List of usage examples for java.lang Throwable getCause
public synchronized Throwable getCause()
From source file:fedora.server.security.servletfilters.pubcookie.ConnectPubcookie.java
public final void connect(String urlString, Map requestParameters, Cookie[] requestCookies, String truststoreLocation, String truststorePassword) { log.debug(this.getClass().getName() + ".connect() " + " url==" + urlString + " requestParameters==" + requestParameters + " requestCookies==" + requestCookies); responseCookies2 = null;/*www .j av a 2 s. c o m*/ URL url = null; try { url = new URL(urlString); } catch (MalformedURLException mue) { log.error(this.getClass().getName() + ".connect() " + "bad configured url==" + urlString); } if (urlString.startsWith("https:") && null != truststoreLocation && !"".equals(truststoreLocation) && null != truststorePassword && !"".equals(truststorePassword)) { log.debug("setting " + FilterPubcookie.TRUSTSTORE_LOCATION_KEY + " to " + truststoreLocation); System.setProperty(FilterPubcookie.TRUSTSTORE_LOCATION_KEY, truststoreLocation); log.debug("setting " + FilterPubcookie.TRUSTSTORE_PASSWORD_KEY + " to " + truststorePassword); System.setProperty(FilterPubcookie.TRUSTSTORE_PASSWORD_KEY, truststorePassword); log.debug("setting " + FilterPubcookie.KEYSTORE_LOCATION_KEY + " to " + truststoreLocation); System.setProperty(FilterPubcookie.KEYSTORE_LOCATION_KEY, truststoreLocation); log.debug("setting " + FilterPubcookie.KEYSTORE_PASSWORD_KEY + " to " + truststorePassword); System.setProperty(FilterPubcookie.KEYSTORE_PASSWORD_KEY, truststorePassword); System.setProperty("javax.net.debug", "ssl,handshake,data,trustmanager"); } else { log.debug("DIAGNOSTIC urlString==" + urlString); log.debug("didn't set " + FilterPubcookie.TRUSTSTORE_LOCATION_KEY + " to " + truststoreLocation); log.debug("didn't set " + FilterPubcookie.TRUSTSTORE_PASSWORD_KEY + " to " + truststorePassword); } /* * log.debug("\n-a-"); Protocol easyhttps = null; try { easyhttps = new * Protocol("https", (ProtocolSocketFactory) new * EasySSLProtocolSocketFactory(), 443); } catch (Throwable t) { * log.debug(t); log.debug(t.getMessage()); if (t.getCause() != null) * log.debug(t.getCause().getMessage()); } log.debug("\n-b-"); * Protocol.registerProtocol("https", easyhttps); log.debug("\n-c-"); */ HttpClient client = new HttpClient(); log.debug(this.getClass().getName() + ".connect() " + " b4 calling setup"); log.debug(this.getClass().getName() + ".connect() requestCookies==" + requestCookies); HttpMethodBase method = setup(client, url, requestParameters, requestCookies); log.debug(this.getClass().getName() + ".connect() " + " after calling setup"); int statusCode = 0; try { log.debug(this.getClass().getName() + ".connect() " + " b4 calling executeMethod"); client.executeMethod(method); log.debug(this.getClass().getName() + ".connect() " + " after calling executeMethod"); statusCode = method.getStatusCode(); log.debug( this.getClass().getName() + ".connect() " + "(with configured url) statusCode==" + statusCode); } catch (Exception e) { log.error(this.getClass().getName() + ".connect() " + "failed original connect, url==" + urlString); log.error(e); log.error(e.getMessage()); if (e.getCause() != null) { log.error(e.getCause().getMessage()); } e.printStackTrace(); } log.debug(this.getClass().getName() + ".connect() " + " status code==" + statusCode); if (302 == statusCode) { Header redirectHeader = method.getResponseHeader("Location"); if (redirectHeader != null) { String redirectString = redirectHeader.getValue(); if (redirectString != null) { URL redirectURL = null; try { redirectURL = new URL(redirectString); method = setup(client, redirectURL, requestParameters, requestCookies); } catch (MalformedURLException mue) { log.error(this.getClass().getName() + ".connect() " + "bad redirect, url==" + urlString); } statusCode = 0; try { client.executeMethod(method); statusCode = method.getStatusCode(); log.debug(this.getClass().getName() + ".connect() " + "(on redirect) statusCode==" + statusCode); } catch (Exception e) { log.error(this.getClass().getName() + ".connect() " + "failed redirect connect"); } } } } if (statusCode == 200) { // this is either the original, non-302, status code or the status code after redirect log.debug(this.getClass().getName() + ".connect() " + "status code 200"); String content = null; try { log.debug(this.getClass().getName() + ".connect() " + "b4 gRBAS()"); content = method.getResponseBodyAsString(); log.debug(this.getClass().getName() + ".connect() " + "after gRBAS() content==" + content); } catch (IOException e) { log.error(this.getClass().getName() + ".connect() " + "couldn't get content"); return; } if (content == null) { log.error(this.getClass().getName() + ".connect() content==null"); return; } else { log.debug(this.getClass().getName() + ".connect() content != null, about to new Tidy"); Tidy tidy = null; try { tidy = new Tidy(); } catch (Throwable t) { log.debug("new Tidy didn't"); log.debug(t); log.debug(t.getMessage()); if (t != null) { log.debug(t.getCause().getMessage()); } } log.debug(this.getClass().getName() + ".connect() after newing Tidy, tidy==" + tidy); byte[] inputBytes = content.getBytes(); log.debug(this.getClass().getName() + ".connect() A1"); ByteArrayInputStream inputStream = new ByteArrayInputStream(inputBytes); log.debug(this.getClass().getName() + ".connect() A2"); responseDocument = tidy.parseDOM(inputStream, null); //use returned root node as only output log.debug(this.getClass().getName() + ".connect() A3"); } log.debug(this.getClass().getName() + ".connect() " + "b4 getState()"); HttpState state = client.getState(); log.debug(this.getClass().getName() + ".connect() state==" + state); try { responseCookies2 = method.getRequestHeaders(); log.debug(this.getClass().getName() + ".connect() just got headers"); for (Header element : responseCookies2) { log.debug(this.getClass().getName() + ".connect() header==" + element); } responseCookies = state.getCookies(); log.debug(this.getClass().getName() + ".connect() responseCookies==" + responseCookies); } catch (Throwable t) { log.error(this.getClass().getName() + ".connect() exception==" + t.getMessage()); if (t.getCause() != null) { log.error(this.getClass().getName() + ".connect() cause==" + t.getCause().getMessage()); } } completedFully = true; log.debug(this.getClass().getName() + ".connect() completedFully==" + completedFully); } }
From source file:net.nan21.dnet.core.web.controller.AbstractDnetController.java
/** * Generic exception handler/*from ww w. j a va 2s . c o m*/ * * @param e * @param response * @return * @throws IOException */ @ExceptionHandler(value = Exception.class) @ResponseBody protected String handleException(Exception e, HttpServletResponse response) throws IOException { e.printStackTrace(); if (e instanceof NotAuthorizedRequestException) { return this.handleException((NotAuthorizedRequestException) e, response); } else if (e instanceof InvocationTargetException) { StringBuffer sb = new StringBuffer(); if (e.getMessage() != null) { sb.append(e.getMessage() + "\n"); } Throwable exc = ((InvocationTargetException) e).getTargetException(); if (exc.getMessage() != null) { sb.append(exc.getMessage() + "\n"); } if (exc.getCause() != null) { if (sb.length() > 0) { sb.append(" Reason: "); } sb.append(exc.getCause().getLocalizedMessage()); } exc.printStackTrace(); response.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value()); response.getOutputStream().print(sb.toString()); return null; } StringBuffer sb = new StringBuffer(); if (e.getLocalizedMessage() != null) { sb.append(e.getLocalizedMessage()); } else if (e.getCause() != null) { if (sb.length() > 0) { sb.append(" Reason: "); } sb.append(e.getCause().getLocalizedMessage()); } if (sb.length() == 0) { if (e.getStackTrace() != null) { response.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value()); e.printStackTrace(response.getWriter()); return null; } } response.setStatus(HttpStatus.EXPECTATION_FAILED.value()); response.getOutputStream().print(sb.toString()); response.getOutputStream().flush(); return null; }
From source file:controllers.DeveloperController.java
@RequestMapping(value = "/create", method = RequestMethod.POST, params = "save") public ModelAndView saveCreate(@Valid final CreateDeveloperForm createDeveloperForm, final BindingResult binding) { ModelAndView result;/*from w w w. j a v a 2 s . c om*/ Developer developer; if (binding.hasErrors()) result = this.createEditModelAndView(createDeveloperForm); else try { developer = this.developerService.reconstructProfile(createDeveloperForm, "create"); this.developerService.save(developer); result = new ModelAndView("redirect:/welcome/index.do"); } catch (final Throwable oops) { if (!createDeveloperForm.getPassword().equals(createDeveloperForm.getConfirmPassword())) result = this.createEditModelAndView(createDeveloperForm, "developer.commit.error.password"); else if (createDeveloperForm.getIsAgree().equals(false)) result = this.createEditModelAndView(createDeveloperForm, "developer.commit.error.isAgree"); else if ((oops.getCause().getCause().getMessage() != null) && (oops.getCause().getCause().getMessage().contains("Duplicate"))) result = this.createEditModelAndView(createDeveloperForm, "developer.commit.error.duplicate"); else result = this.createEditModelAndView(createDeveloperForm, "developer.commit.error"); } return result; }
From source file:de.tudarmstadt.lt.ltbot.postprocessor.DecesiveValuePrioritizer.java
@Override protected void innerProcess(CrawlURI uri) throws InterruptedException { // CrawlURI is a candidate Uri which has to be scheduled according our priority synchronized (_lck) { double value = 0d; try {/*from w ww . java 2 s. co m*/ value = getValueFromViaURI(uri); double oldvalue = getValueFromCurrentURI(uri); if (oldvalue <= value) // URI was already processed and value was equal to or lower than the current via url return; } catch (Throwable t) { for (int i = 1; t != null && i < 10; i++) { LOG.log(Level.WARNING, String.format("Failed to get decisive value from extra info: (%d-%s:%s).", i, t.getClass().getName(), t.getMessage()), t); t = t.getCause(); } return; } int schedulingConstants_priority = getPriorityAsSchedulingDirective(value); if (uri.getFullVia().isSeed() && uri.getLastHop().equals(Hop.REFER.getHopString())) schedulingConstants_priority = SchedulingConstants.HIGHEST; if (schedulingConstants_priority < 0) { _count_reject++; uri.setFetchStatus(S_OUT_OF_SCOPE); // this will not consider the url for further processing // TODO: there must be a better solution, maybe extend org.archive.crawler.prefetch.FrontierPreparer or org.archive.crawler.prefetch.CandidateScoper } uri.setSchedulingDirective(schedulingConstants_priority); if (schedulingConstants_priority >= 0) _assignment_counts[schedulingConstants_priority]++; LOG.finest(String.format("Assigned scheduling directive %d to %s.", schedulingConstants_priority, uri.toString())); // lower values have higher precedence, i.e. higher priority int cost = 255; if (schedulingConstants_priority == 0) cost = 1; else if (schedulingConstants_priority > 0) cost = getPrecedenceCost(value); uri.setHolderCost(cost); uri.setPrecedence(cost); LOG.finest(String.format("Assigned precedence cost %d to %s.", cost, uri.toString())); try { uri.getExtraInfo().put(SharedConstants.EXTRA_INFO_ASSIGNED_SCHEDULING_DIRECTIVE, schedulingConstants_priority); uri.getExtraInfo().put(SharedConstants.EXTRA_INFO_ASSIGNED_COST_PRECEDENCE, cost); uri.getExtraInfo().put(SharedConstants.EXTRA_INFO_PERPLEXITY_VIA, String.format("%012g", value)); } catch (Throwable t) { for (int i = 1; t != null && i < 10; i++) { LOG.log(Level.WARNING, String.format("Failed to add extra information to uri %s: (%d-%s:%s).", uri.toString(), i, t.getClass().getName(), t.getMessage()), t); t = t.getCause(); } } } }
From source file:com.nokia.dempsy.TestDempsy.java
@Test public void testAdaptorThrowsRuntimeOnSetDispatcher() throws Throwable { TestAdaptor.throwExceptionOnSetDispatcher = true; ClassPathXmlApplicationContext actx = null; boolean gotException = false; try {// w w w .ja va 2 s .com actx = new ClassPathXmlApplicationContext("testDempsy/Dempsy.xml", "testDempsy/Transport-PassthroughActx.xml", "testDempsy/ClusterManager-LocalVmActx.xml", "testDempsy/SimpleMultistageApplicationActx.xml"); actx.registerShutdownHook(); } catch (Throwable th) { assertEquals("Forced RuntimeException", th.getCause().getLocalizedMessage()); gotException = true; } finally { TestAdaptor.throwExceptionOnSetDispatcher = false; if (actx != null) { actx.stop(); actx.destroy(); } } assertTrue(gotException); }
From source file:com.cerema.cloud2.lib.common.operations.RemoteOperationResult.java
private CertificateCombinedException getCertificateCombinedException(Exception e) { CertificateCombinedException result = null; if (e instanceof CertificateCombinedException) { return (CertificateCombinedException) e; }/*from w w w . ja v a 2 s.co m*/ Throwable cause = mException.getCause(); Throwable previousCause = null; while (cause != null && cause != previousCause && !(cause instanceof CertificateCombinedException)) { previousCause = cause; cause = cause.getCause(); } if (cause != null && cause instanceof CertificateCombinedException) { result = (CertificateCombinedException) cause; } return result; }
From source file:de.axelfaust.alfresco.nashorn.repo.web.scripts.console.ExecutePost.java
protected void collectCallstackLines(final Throwable exception, final List<String> callstackLines) { if (exception.getCause() != null) { this.collectCallstackLines(exception.getCause(), callstackLines); callstackLines.add("Wrapped in " + exception.toString()); callstackLines.add(CALLSTACK_AT_PREFIX + exception.getStackTrace()[0].toString()); } else {/*from w ww . ja va2 s . c o m*/ callstackLines.add(exception.toString()); for (final StackTraceElement element : exception.getStackTrace()) { callstackLines.add(CALLSTACK_AT_PREFIX + element.toString()); } } }
From source file:maspack.fileutil.FileManager.java
private static Throwable getRootThrowable(Throwable t) { Throwable root = t; while (root.getCause() != null && root.getCause() != root) { root = root.getCause();/* w ww . j a v a 2s. c o m*/ } return root; }
From source file:com.blackducksoftware.integration.jira.config.HubConfigController.java
@Path("/testConnection") @PUT//from w ww . j a v a 2 s. c om @Consumes(MediaType.APPLICATION_JSON) public Response testConnection(final HubServerConfigSerializable config, @Context final HttpServletRequest request) { try { final PluginSettings settings = pluginSettingsFactory.createGlobalSettings(); final Response response = checkUserPermissions(request, settings); if (response != null) { return response; } transactionTemplate.execute(new TransactionCallback() { @Override public Object doInTransaction() { final HubServerConfigBuilder serverConfigBuilder = setConfigBuilderFromSerializableConfig( config, settings); setConfigFromResult(config, serverConfigBuilder.createValidator()); if (config.hasErrors()) { return config; } else { final HubServerConfig serverConfig = serverConfigBuilder.build(); try { final CredentialsRestConnection restConnection = new CredentialsRestConnection(logger, serverConfig.getHubUrl(), serverConfig.getGlobalCredentials().getUsername(), serverConfig.getGlobalCredentials().getDecryptedPassword(), serverConfig.getTimeout()); restConnection.connect(); } catch (final IntegrationException e) { if (e.getMessage().toLowerCase().contains("unauthorized")) { config.setUsernameError( "Username and Password are invalid for : " + serverConfig.getHubUrl()); } else { config.setTestConnectionError(e.toString()); } } return config; } } }); if (config.hasErrors()) { return Response.ok(config).status(Status.BAD_REQUEST).build(); } return Response.noContent().build(); } catch (final Throwable t) { final StringBuilder sb = new StringBuilder(); sb.append("Unexpected exception caught in testConnection(): "); sb.append(t.getMessage()); if (t.getCause() != null) { sb.append("; Caused by: "); sb.append(t.getCause().getMessage()); } config.setHubUrlError(sb.toString()); return Response.ok(config).status(Status.BAD_REQUEST).build(); } }
From source file:com.tesora.dve.dbc.ServerDBConnection.java
private void executeInContext(final MysqlTextResultCollector resultConsumer, final byte[] sql) throws PEException, Throwable { Throwable t = ssCon.executeInContext(new Callable<Throwable>() { public Throwable call() { try { ExecuteRequestExecutor.execute(ssCon, resultConsumer, sql); } catch (Throwable e) { return e; }/* w w w.ja v a 2s. c o m*/ return null; } }); if (t instanceof SchemaException) throw (SchemaException) t; if (t != null && t.getCause() != null) { throw new PEException(t); } }