Search in sources :

Example 91 with UniformInterfaceException

use of com.sun.jersey.api.client.UniformInterfaceException in project ANNIS by korpling.

the class DocBrowserTable method generateInfoButtonCell.

public Button generateInfoButtonCell(final String docName) {
    Button btn = new Button();
    btn.setStyleName(ChameleonTheme.BUTTON_BORDERLESS);
    btn.setIcon(INFO_ICON);
    btn.addClickListener(new Button.ClickListener() {

        @Override
        public void buttonClick(Button.ClickEvent event) {
            try {
                List<Annotation> annos = getDocMetaData(docName);
                /**
                 * Transforms to a list of key value pairs. The values concates the
                 * namespace and ordinary value. Namespaces "NULL" are ignored.
                 */
                // create datasource and bind it to a table
                BeanItemContainer<Annotation> metaContainer = new BeanItemContainer<>(Annotation.class);
                metaContainer.addAll(annos);
                metaContainer.sort(new Object[] { "namespace", "name" }, new boolean[] { true, true });
                Table metaTable = new Table();
                metaTable.setContainerDataSource(metaContainer);
                metaTable.addGeneratedColumn("genname", new MetaDataPanel.MetaTableNameGenerator(metaContainer));
                metaTable.addGeneratedColumn("genvalue", new MetaDataPanel.MetaTableValueGenerator(metaContainer));
                metaTable.setVisibleColumns("genname", "genvalue");
                metaTable.setColumnHeaders(new String[] { "Name", "Value" });
                metaTable.setSizeFull();
                metaTable.setColumnWidth("genname", -1);
                metaTable.setColumnExpandRatio("genvalue", 1.0f);
                metaTable.addStyleName(ChameleonTheme.TABLE_STRIPED);
                // create and style the extra window for the metadata table
                Window metaWin = new Window();
                metaWin.setContent(metaTable);
                metaWin.setCaption("metadata doc " + docName);
                metaWin.center();
                metaWin.setWidth(400, Unit.PIXELS);
                metaWin.setHeight(400, Unit.PIXELS);
                // paint the window
                docBrowserPanel.getUI().addWindow(metaWin);
            } catch (UniformInterfaceException ex) {
                log.error("can not retrieve metadata for document " + docName, ex);
            }
        }
    });
    return btn;
}
Also used : Window(com.vaadin.ui.Window) Table(com.vaadin.ui.Table) BeanItemContainer(com.vaadin.data.util.BeanItemContainer) Annotation(annis.model.Annotation) UniformInterfaceException(com.sun.jersey.api.client.UniformInterfaceException) Button(com.vaadin.ui.Button) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List)

Example 92 with UniformInterfaceException

use of com.sun.jersey.api.client.UniformInterfaceException in project ANNIS by korpling.

the class CorpusManagement method fetchFromService.

public void fetchFromService() throws CriticalServiceQueryException, ServiceQueryException {
    if (webResourceProvider != null) {
        corpora.clear();
        try {
            WebResource rootRes = webResourceProvider.getWebResource();
            List<AnnisCorpus> corporaList = rootRes.path("query").path("corpora").get(new GenericType<List<AnnisCorpus>>() {
            });
            for (AnnisCorpus c : corporaList) {
                corpora.put(c.getName(), c);
            }
        } catch (ClientHandlerException ex) {
            log.error(null, ex);
            throw new ServiceQueryException("Service not available: " + ex.getLocalizedMessage());
        } catch (UniformInterfaceException ex) {
            if (ex.getResponse().getStatus() == Response.Status.UNAUTHORIZED.getStatusCode()) {
                throw new CriticalServiceQueryException("You are not authorized to get the corpus list.");
            } else {
                log.error(null, ex);
                throw new ServiceQueryException("Remote exception: " + ex.getLocalizedMessage());
            }
        }
    }
}
Also used : ClientHandlerException(com.sun.jersey.api.client.ClientHandlerException) UniformInterfaceException(com.sun.jersey.api.client.UniformInterfaceException) AnnisCorpus(annis.service.objects.AnnisCorpus) CriticalServiceQueryException(annis.gui.CriticalServiceQueryException) ServiceQueryException(annis.gui.ServiceQueryException) WebResource(com.sun.jersey.api.client.WebResource) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) CriticalServiceQueryException(annis.gui.CriticalServiceQueryException)

Example 93 with UniformInterfaceException

use of com.sun.jersey.api.client.UniformInterfaceException in project ANNIS by korpling.

the class CorpusManagement method delete.

public void delete(String corpusName) throws CriticalServiceQueryException, ServiceQueryException {
    if (webResourceProvider != null) {
        try {
            WebResource rootRes = webResourceProvider.getWebResource();
            rootRes.path("admin").path("corpora").path(corpusName).delete();
            corpora.remove(corpusName);
        } catch (ClientHandlerException ex) {
            log.error(null, ex);
            throw new ServiceQueryException("Service not available: " + ex.getLocalizedMessage());
        } catch (UniformInterfaceException ex) {
            if (ex.getResponse().getStatus() == Response.Status.UNAUTHORIZED.getStatusCode()) {
                throw new CriticalServiceQueryException("You are not authorized to delete a corpus");
            } else if (ex.getResponse().getStatus() == Response.Status.NOT_FOUND.getStatusCode()) {
                throw new ServiceQueryException("Corpus with name " + corpusName + " not found");
            } else {
                log.error(null, ex);
                throw new ServiceQueryException("Remote exception: " + ex.getLocalizedMessage());
            }
        }
    }
}
Also used : ClientHandlerException(com.sun.jersey.api.client.ClientHandlerException) UniformInterfaceException(com.sun.jersey.api.client.UniformInterfaceException) CriticalServiceQueryException(annis.gui.CriticalServiceQueryException) ServiceQueryException(annis.gui.ServiceQueryException) WebResource(com.sun.jersey.api.client.WebResource) CriticalServiceQueryException(annis.gui.CriticalServiceQueryException)

Example 94 with UniformInterfaceException

use of com.sun.jersey.api.client.UniformInterfaceException in project ANNIS by korpling.

the class AnnisBaseUI method handleCommonError.

/**
 * Handle common errors like database/service connection problems and display a unified
 * error message.
 *
 * This will not log the exception, only display information to the user.
 *
 * @param ex
 * @return True if error was handled, false otherwise.
 */
public static boolean handleCommonError(Throwable ex, String action) {
    if (ex != null) {
        Throwable rootCause = ex;
        while (rootCause.getCause() != null) {
            rootCause = rootCause.getCause();
        }
        if (rootCause instanceof UniformInterfaceException) {
            UniformInterfaceException uniEx = (UniformInterfaceException) rootCause;
            if (uniEx.getResponse() != null) {
                if (uniEx.getResponse().getStatus() == 503) {
                    // database connection error
                    Notification n = new Notification("Can't execute " + (action == null ? "" : "\"" + action + "\"") + " action because database server is not responding.<br/>" + "There might be too many users using this service right now.", Notification.Type.WARNING_MESSAGE);
                    n.setDescription("<p><strong>Please try again later.</strong> If the error persists inform the administrator of this server.</p>" + "<p>Click on this message to close it.</p>" + "<p style=\"font-size:9pt;color:gray;\">Pinguin picture by Polar Cruises [CC BY 2.0 (http://creativecommons.org/licenses/by/2.0)], via Wikimedia Commons</p>");
                    n.setIcon(PINGUIN_IMAGE);
                    n.setHtmlContentAllowed(true);
                    n.setDelayMsec(15000);
                    n.show(Page.getCurrent());
                    return true;
                }
            }
        }
    }
    return false;
}
Also used : UniformInterfaceException(com.sun.jersey.api.client.UniformInterfaceException) Notification(com.vaadin.ui.Notification)

Example 95 with UniformInterfaceException

use of com.sun.jersey.api.client.UniformInterfaceException in project ANNIS by korpling.

the class ResultFetchJob method run.

@Override
public void run() {
    WebResource subgraphRes = Helper.getAnnisWebResource().path("query/search/subgraph");
    // holds the ids of the matches.
    MatchGroup result;
    try {
        if (Thread.interrupted()) {
            return;
        }
        // set the the progress bar, for given the user some information about the loading process
        ui.accessSynchronously(new Runnable() {

            @Override
            public void run() {
                resultPanel.showMatchSearchInProgress(query);
            }
        });
        // get the matches
        result = futureMatches.get();
        // get the subgraph for each match, when the result is not empty
        if (result.getMatches().isEmpty()) {
            // check if thread was interrupted
            if (Thread.interrupted()) {
                return;
            }
            // nothing found, so inform the user about this.
            ui.access(new Runnable() {

                @Override
                public void run() {
                    resultPanel.showNoResult();
                }
            });
        } else {
            if (Thread.interrupted()) {
                return;
            }
            // since annis found something, inform the user that subgraphs are created
            ui.access(new Runnable() {

                @Override
                public void run() {
                    resultPanel.showSubgraphSearchInProgress(query, 0.0f);
                }
            });
            // prepare fetching subgraphs
            final BlockingQueue<SaltProject> queue = new ArrayBlockingQueue<>(result.getMatches().size());
            int current = 0;
            final ArrayList<Match> matchList = new ArrayList<>(result.getMatches());
            for (Match m : matchList) {
                if (Thread.interrupted()) {
                    return;
                }
                List<Match> subList = new LinkedList<>();
                subList.add(m);
                final SaltProject p = executeQuery(subgraphRes, new MatchGroup(subList), query.getLeftContext(), query.getRightContext(), query.getSegmentation(), SubgraphFilter.all);
                queue.put(p);
                log.debug("added match {} to queue", current + 1);
                if (current == 0) {
                    ui.access(new Runnable() {

                        @Override
                        public void run() {
                            resultPanel.setQueryResultQueue(queue, query, matchList);
                        }
                    });
                }
                if (Thread.interrupted()) {
                    return;
                }
                current++;
            }
        }
    // end if no results
    } catch (InterruptedException ex) {
    // just return
    } catch (final ExecutionException root) {
        ui.accessSynchronously(new Runnable() {

            @Override
            public void run() {
                if (resultPanel != null && resultPanel.getPaging() != null) {
                    PagingComponent paging = resultPanel.getPaging();
                    Throwable cause = root.getCause();
                    if (cause instanceof UniformInterfaceException) {
                        UniformInterfaceException ex = (UniformInterfaceException) cause;
                        if (ex.getResponse().getStatus() == 400) {
                            List<AqlParseError> errors = ex.getResponse().getEntity(new GenericType<List<AqlParseError>>() {
                            });
                            String errMsg = Joiner.on(" | ").join(errors);
                            paging.setInfo("parsing error: " + errMsg);
                        } else if (ex.getResponse().getStatus() == 504) {
                            paging.setInfo("Timeout: query execution took too long");
                        } else if (ex.getResponse().getStatus() == 403) {
                            paging.setInfo("Not authorized to query this corpus.");
                        } else {
                            paging.setInfo("unknown error: " + ex);
                        }
                    } else {
                        log.error("Unexcepted ExecutionException cause", root);
                    }
                    resultPanel.showFinishedSubgraphSearch();
                }
            }
        });
    }
// end catch
}
Also used : ArrayList(java.util.ArrayList) AqlParseError(annis.model.AqlParseError) AsyncWebResource(com.sun.jersey.api.client.AsyncWebResource) WebResource(com.sun.jersey.api.client.WebResource) SaltProject(org.corpus_tools.salt.common.SaltProject) LinkedList(java.util.LinkedList) Match(annis.service.objects.Match) PagingComponent(annis.gui.paging.PagingComponent) UniformInterfaceException(com.sun.jersey.api.client.UniformInterfaceException) ArrayBlockingQueue(java.util.concurrent.ArrayBlockingQueue) MatchGroup(annis.service.objects.MatchGroup) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List) ExecutionException(java.util.concurrent.ExecutionException)

Aggregations

UniformInterfaceException (com.sun.jersey.api.client.UniformInterfaceException)172 WebResource (com.sun.jersey.api.client.WebResource)128 ClientResponse (com.sun.jersey.api.client.ClientResponse)74 Test (org.junit.Test)65 JSONObject (org.codehaus.jettison.json.JSONObject)45 ClientHandlerException (com.sun.jersey.api.client.ClientHandlerException)34 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)20 SOSFailure (com.emc.storageos.vasa.fault.SOSFailure)18 ArrayList (java.util.ArrayList)17 LinkedList (java.util.LinkedList)16 JobId (org.apache.hadoop.mapreduce.v2.api.records.JobId)14 Job (org.apache.hadoop.mapreduce.v2.app.job.Job)14 IOException (java.io.IOException)12 Client (com.sun.jersey.api.client.Client)10 List (java.util.List)10 AnnisAttribute (annis.service.objects.AnnisAttribute)9 GenericType (com.sun.jersey.api.client.GenericType)8 Application (org.apache.hadoop.yarn.server.nodemanager.containermanager.application.Application)7 MockNM (org.apache.hadoop.yarn.server.resourcemanager.MockNM)7 JerseyTest (com.sun.jersey.test.framework.JerseyTest)6