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;
}
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());
}
}
}
}
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());
}
}
}
}
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;
}
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
}
Aggregations