List of usage examples for org.apache.commons.lang3.exception ExceptionUtils getRootCauseMessage
public static String getRootCauseMessage(final Throwable th)
From source file:org.xwiki.rest.internal.exceptions.XWikiRestExceptionMapper.java
@Override public Response toResponse(XWikiRestException exception) { Throwable cause = exception.getCause(); if (cause instanceof XWikiException) { XWikiException xwikiException = (XWikiException) cause; if (xwikiException.getCode() == XWikiException.ERROR_XWIKI_ACCESS_DENIED) { return Response.status(Status.UNAUTHORIZED).entity(exception.getMessage()) .type(MediaType.TEXT_PLAIN).build(); }/*w w w.j a va2 s.co m*/ } else if (cause instanceof QueryException) { QueryException queryException = (QueryException) cause; return Response.serverError().entity(String.format("%s\n%s\n", exception.getMessage(), ExceptionUtils.getRootCauseMessage(queryException))).type(MediaType.TEXT_PLAIN).build(); } return Response.serverError().entity(exception.getMessage()).type(MediaType.TEXT_PLAIN).build(); }
From source file:org.xwiki.rest.internal.resources.classes.GroupsClassPropertyValuesProvider.java
@Override protected String getIcon(DocumentReference groupReference) { XWikiContext xcontext = this.xcontextProvider.get(); try {/* w ww . j av a 2 s .c om*/ XWikiDocument groupProfileDocument = xcontext.getWiki().getDocument(groupReference, xcontext); XWikiAttachment avatarAttachment = getFirstImageAttachment(groupProfileDocument, xcontext); if (avatarAttachment != null) { return xcontext.getWiki().getURL(avatarAttachment.getReference(), "download", "width=30&height=30&keepAspectRatio=true", null, xcontext); } } catch (XWikiException e) { this.logger.warn( "Failed to read the avatar of group [{}]. Root cause is [{}]. Using the default avatar instead.", groupReference.getName(), ExceptionUtils.getRootCauseMessage(e)); } return xcontext.getWiki().getSkinFile("icons/xwiki/noavatargroup.png", true, xcontext); }
From source file:org.xwiki.rest.internal.resources.classes.GroupsClassPropertyValuesProvider.java
@Override protected String getLabel(DocumentReference groupReference, Object currentLabel) { try {//w w w. j ava2 s.co m XWikiContext xcontext = this.xcontextProvider.get(); return xcontext.getWiki().getDocument(groupReference, xcontext).getRenderedTitle(Syntax.PLAIN_1_0, xcontext); } catch (XWikiException e) { this.logger.warn("Failed to get the title of group [{}]. Root cause is [{}].", this.entityReferenceSerializer.serialize(groupReference), ExceptionUtils.getRootCauseMessage(e)); return super.getLabel(groupReference, currentLabel); } }
From source file:org.xwiki.rest.internal.resources.classes.UsersClassPropertyValuesProvider.java
@Override protected String getIcon(DocumentReference userReference) { XWikiContext xcontext = this.xcontextProvider.get(); try {//w w w.ja v a2s. c o m XWikiDocument userProfileDocument = xcontext.getWiki().getDocument(userReference, xcontext); String avatar = userProfileDocument.getStringValue("avatar"); XWikiAttachment avatarAttachment = userProfileDocument.getAttachment(avatar); if (avatarAttachment != null && avatarAttachment.isImage(xcontext)) { return xcontext.getWiki().getURL(avatarAttachment.getReference(), "download", "width=30&height=30&keepAspectRatio=true", null, xcontext); } } catch (XWikiException e) { this.logger.warn( "Failed to read the avatar of user [{}]. Root cause is [{}]. Using the default avatar instead.", userReference.getName(), ExceptionUtils.getRootCauseMessage(e)); } return xcontext.getWiki().getSkinFile("icons/xwiki/noavatar.png", true, xcontext); }
From source file:org.xwiki.rest.internal.resources.job.JobsResourceImpl.java
@Override public JobStatus executeJob(String jobType, boolean async, JobRequest restJobRequest) throws XWikiRestException { // Restrict generic Job starting to programming right for now // TODO: provide extension point to decide of the access depending on the job if (!this.authorization.hasAccess(Right.PROGRAM, null)) { throw new WebApplicationException(Status.UNAUTHORIZED); }/*from w ww . j a v a2s . c o m*/ // Parse JobRequest DefaultRequest request = this.factory.toJobRequest(restJobRequest); if (request == null) { request = new DefaultRequest(); } // Start job Job job; try { // Give a few context related values to the job if (request.getProperty(JobRequestContext.KEY) == null) { JobRequestContext.set(request, this.xcontextProvider.get()); } job = this.jobExecutor.execute(jobType, request); } catch (JobException e) { throw new XWikiRestException("Failed to start job", e); } // Wait for the job end if asked if (!async) { try { job.join(); } catch (InterruptedException e) { throw new XWikiRestException("The job as been interrupted", e); } // Fail the HTTP request if the job failed if (job.getStatus().getError() != null) { throw new XWikiRestException( "The job failed (" + ExceptionUtils.getRootCauseMessage(job.getStatus().getError()) + ")", job.getStatus().getError()); } } // Get job status org.xwiki.job.event.status.JobStatus status = job.getStatus(); // Convert Job status return this.factory.toRestJobStatus(status, null, true, false, false, null); }
From source file:org.xwiki.search.solr.internal.SolrIndexEventListener.java
/** * Helper method to index all the translations of a document. We don't rely on the {@code recurse} parameter of the * {@link SolrIndexer#index(org.xwiki.model.reference.EntityReference, boolean)} because we want to update only the * {@code type=DOCUMENT} rows from the Solr index. The attachment and object rows are updated separately when the * corresponding events are fired./*from w w w. j av a2s . c om*/ * * @param document the document whose translations need to be indexed * @param xcontext the XWiki context */ private void indexTranslations(XWikiDocument document, XWikiContext xcontext) { SolrIndexer indexer = this.solrIndexer.get(); // Index the default translation. DocumentReference documentReferenceWithoutLocale = document.getDocumentReference(); indexer.index(documentReferenceWithoutLocale, false); try { // Index the rest of the available translations. document.getTranslationLocales(xcontext).stream().forEach( locale -> indexer.index(new DocumentReference(documentReferenceWithoutLocale, locale), false)); } catch (XWikiException e) { this.logger.warn("Failed to index the translations of [{}]. Root cause is [{}].", documentReferenceWithoutLocale, ExceptionUtils.getRootCauseMessage(e)); } }
From source file:org.xwiki.security.authorization.cache.internal.DefaultSecurityCacheLoaderTest.java
@Test public void loadWithConflictingInsertionException() throws Exception { DocumentReference userReference = new DocumentReference("wiki", "Users", "mflorea"); UserSecurityReference user = securityReferenceFactory.newUserReference(userReference); DocumentReference documentReference = new DocumentReference("wiki", "Space", "Document"); SecurityReference entity = securityReferenceFactory.newEntityReference(documentReference); SecurityRuleEntry documentEntry = mock(SecurityRuleEntry.class, "document"); when(documentEntry.getReference()).thenReturn(entity); when(documentEntry.isEmpty()).thenReturn(true); SecurityRuleEntry spaceEntry = mock(SecurityRuleEntry.class, "space"); when(spaceEntry.getReference()).thenReturn(entity.getParentSecurityReference()); when(spaceEntry.isEmpty()).thenReturn(true); SecurityRuleEntry wikiEntry = mock(SecurityRuleEntry.class, "wiki"); when(wikiEntry.getReference()).thenReturn(entity.getParentSecurityReference().getParentSecurityReference()); when(wikiEntry.isEmpty()).thenReturn(true); SecurityCache securityCache = mocker.getInstance(SecurityCache.class); when(securityCache.get(entity)).thenReturn(documentEntry); when(securityCache.get(entity.getParentSecurityReference())).thenReturn(spaceEntry); when(securityCache.get(entity.getParentSecurityReference().getParentSecurityReference())) .thenReturn(wikiEntry);//ww w . j a v a 2s .c o m when(securityCache.getGroupsFor(user, null)).thenReturn(null); UserBridge userBridge = mocker.getInstance(UserBridge.class); DocumentReference groupReference = new DocumentReference("wiki", "Groups", "AllGroup"); Set<GroupSecurityReference> groups = Collections .singleton(securityReferenceFactory.newGroupReference(groupReference)); when(userBridge.getAllGroupsFor(user, userReference.getWikiReference())).thenReturn(groups); SecurityAccessEntry securityAccessEntry = mock(SecurityAccessEntry.class); AuthorizationSettler authorizationSettler = mocker.getInstance(AuthorizationSettler.class); Deque<SecurityRuleEntry> securityRuleEntries = new LinkedList<SecurityRuleEntry>( Arrays.asList(documentEntry, spaceEntry, wikiEntry)); when(authorizationSettler.settle(user, groups, securityRuleEntries)).thenReturn(securityAccessEntry); doThrow(ConflictingInsertionException.class).when(securityCache).add(securityAccessEntry); doThrow(ConflictingInsertionException.class).when(securityCache).add(securityAccessEntry, null); try { securityCacheLoader.load(user, entity); fail(); } catch (AuthorizationException e) { assertEquals("Failed to load the cache in 5 attempts. Giving up. when checking " + "access to [wiki:Space.Document] for user [wiki:Users.mflorea]", e.getMessage()); assertTrue(ExceptionUtils.getRootCauseMessage(e).contains("ConflictingInsertionException")); } // Assert that we've also emitted a log assertEquals(1, this.logRule.size()); assertEquals("Failed to load the cache in 5 attempts. Giving up.", this.logRule.getMessage(0)); }
From source file:org.xwiki.tree.script.TreeScriptService.java
/** * @param roleHint the {@link Tree} role hint * @return the {@link Tree} component implementation with the specified hint *///w w w. j av a2s. co m public Tree get(String roleHint) { ComponentManager contextComponentManager = this.contextComponentManagerProvider.get(); if (contextComponentManager.hasComponent(Tree.class, roleHint)) { try { return contextComponentManager.getInstance(Tree.class, roleHint); } catch (ComponentLookupException e) { this.logger.warn("Failed to load the specified tree component. Root cause is [{}]", ExceptionUtils.getRootCauseMessage(e)); } } return null; }
From source file:org.xwiki.webjars.script.WebJarsScriptService.java
/** * Creates an URL that can be used to load a resource (JavaScript, CSS, etc.) from a WebJar in the passed namespace. * * @param webjarId the id of the WebJar that contains the resource; the format of the WebJar id is * {@code groupId:artifactId} (e.g. {@code org.xwiki.platform:xwiki-platform-job-webjar}), where the * {@code groupId} can be omitted if it is {@link #DEFAULT_WEBJAR_GROUP_ID} (i.e. {@code angular} * translates to {@code org.webjars:angular}) * @param namespace the namespace in which the webjars resources will be loaded from (e.g. for a wiki namespace you * should use the format {@code wiki:<wikiId>}). If null then defaults to the current wiki * namespace. And if the passed namespace doesn't exist, falls back to the main wiki namespace * @param path the path within the WebJar, starting from the version folder (e.g. you should pass just * {@code angular.js} if the actual path is {@code META-INF/resources/webjars/angular/2.1.11/angular.js}) * @param params additional query string parameters to add to the returned URL; there are two known (reserved) * parameters: {@code version} (the WebJar version) and {@code evaluate} (a boolean parameter that * specifies if the requested resource has Velocity code that needs to be evaluated); besides these you * can pass whatever parameters you like (they will be taken into account or not depending on the * resource)/*from w w w .j ava 2 s. co m*/ * @return the URL to load the WebJar resource (relative to the context path of the web application) * @since 8.1M2 */ public String url(String webjarId, String namespace, String path, Map<String, ?> params) { if (StringUtils.isEmpty(webjarId)) { return null; } String groupId = DEFAULT_WEBJAR_GROUP_ID; String artifactId = webjarId; int groupSeparatorPosition = webjarId.indexOf(':'); if (groupSeparatorPosition >= 0) { // A different group id. groupId = webjarId.substring(0, groupSeparatorPosition); artifactId = webjarId.substring(groupSeparatorPosition + 1); } Map<String, Object> urlParams = new LinkedHashMap<>(); if (params != null) { urlParams.putAll(params); } // For backward-compatibility reasons we still support passing the target wiki in parameters. However we need // to remove it from the params if that's the case since we don't want to output a URL with the wiki id in the // query string (since the namespace is now part of the URL). urlParams.remove(WIKI); Object version = urlParams.remove(VERSION); if (version == null) { // Try to determine the version based on the extensions that are currently installed or provided by default. version = getVersion(String.format("%s:%s", groupId, artifactId), namespace); } // Construct a WebJarsResourceReference so that we can serialize it! WebJarsResourceReference resourceReference = getResourceReference(artifactId, version, namespace, path, urlParams); ExtendedURL extendedURL; try { extendedURL = this.defaultResourceReferenceSerializer.serialize(resourceReference); } catch (SerializeResourceReferenceException | UnsupportedResourceReferenceException e) { this.logger.warn("Error while serializing WebJar URL for id [{}], path = [{}]. Root cause = [{}]", webjarId, path, ExceptionUtils.getRootCauseMessage(e)); return null; } return extendedURL.serialize(); }
From source file:org.xwiki.wikistream.xar.internal.input.WikiReader.java
public void read(InputStream stream, Object filter, XARInputFilter proxyFilter) throws XMLStreamException, IOException, WikiStreamException { ZipArchiveInputStream zis = new ZipArchiveInputStream(stream, "UTF-8", false); for (ZipArchiveEntry entry = zis.getNextZipEntry(); entry != null; entry = zis.getNextZipEntry()) { if (entry.isDirectory() || entry.getName().startsWith("META-INF")) { // The entry is either a directory or is something inside of the META-INF dir. // (we use that directory to put meta data such as LICENSE/NOTICE files.) continue; } else if (entry.getName().equals(XarModel.PATH_PACKAGE)) { // The entry is the manifest (package.xml). Read this differently. try { this.xarPackage.readDescriptor(zis); } catch (Exception e) { if (this.properties.isVerbose()) { this.logger.warn(LOG_DESCRIPTOR_FAILREAD, "Failed to read XAR descriptor from entry [{}]: {}", entry.getName(), ExceptionUtils.getRootCauseMessage(e)); }//from w w w . jav a 2 s . co m } } else { try { this.documentReader.read(zis, filter, proxyFilter); } catch (SkipEntityException skip) { if (this.properties.isVerbose()) { this.logger.info(LOG_DOCUMENT_SKIPPED, "Skipped document [{}]", skip.getEntityReference()); } } catch (Exception e) { if (this.properties.isVerbose()) { this.logger.warn(LOG_DOCUMENT_FAILREAD, "Failed to read XAR XML document from entry [{}]: {}", entry.getName(), ExceptionUtils.getRootCauseMessage(e)); } } } } }