List of usage examples for java.lang Throwable Throwable
public Throwable(Throwable cause)
From source file:io.selendroid.android.impl.AbstractDevice.java
@Override public void startSelendroid(AndroidApp aut, int port) throws AndroidSdkException { this.port = port; String[] args = { "-e", "main_activity", aut.getMainActivity(), "-e", "server_port", Integer.toString(port), "io.selendroid." + aut.getBasePackage() + "/io.selendroid.ServerInstrumentation" }; CommandLine command = adbCommand(/*from w ww. j av a2 s.co m*/ ObjectArrays.concat(new String[] { "shell", "am", "instrument" }, args, String.class)); String result = executeCommand(command, 20000); if (result.contains("FAILED")) { String detailedResult; try { // Try again, waiting for instrumentation to finish. This way we'll get more error output. CommandLine getErrorDetailCommand = adbCommand(ObjectArrays .concat(new String[] { "shell", "am", "instrument", "-w" }, args, String.class)); detailedResult = executeCommand(getErrorDetailCommand, 20000); } catch (Exception e) { detailedResult = ""; } throw new SelendroidException("Error occurred while starting selendroid-server on the device", new Throwable(result + "\nDetails:\n" + detailedResult)); } forwardSelendroidPort(port); startLogging(); }
From source file:edu.ucsd.xmlrpc.xmlrpc.server.XmlRpcStreamServer.java
/** Returns, whether the /** Processes a "connection". The "connection" is an opaque object, which is * being handled by the subclasses./*from w w w . j a va 2 s .c o m*/ * @param pConfig The request configuration. * @param pConnection The "connection" being processed. * @throws XmlRpcException Processing the request failed. */ public void execute(XmlRpcStreamRequestConfig pConfig, ServerStreamConnection pConnection, WebServer wServer) throws XmlRpcException { log.debug("execute: ->"); Object result; Throwable error; try { InputStream istream = null; try { istream = getInputStream(pConfig, pConnection); XmlRpcRequest request = getRequest(pConfig, istream); // Ucsd modified code StoredRequest storedRequest = new StoredRequest((XmlRpcClientRequestImpl) request); if (wServer != null) { wServer.addRequest(storedRequest.getRequest().getJobID(), storedRequest); } result = execute(request); storedRequest.setValid(true); ; storedRequest.setResult(result); //TODO DEMO remove if (result.equals(-9)) { throw new Throwable("Server Disconnected"); } // end istream.close(); istream = null; error = null; log.debug("execute: Request performed successfully"); } catch (Throwable t) { logError(t); result = null; error = t; } finally { if (istream != null) { try { istream.close(); } catch (Throwable ignore) { } } } boolean contentLengthRequired = isContentLengthRequired(pConfig); ByteArrayOutputStream baos; OutputStream ostream; if (contentLengthRequired) { baos = new ByteArrayOutputStream(); ostream = baos; } else { baos = null; ostream = pConnection.newOutputStream(); } ostream = getOutputStream(pConnection, pConfig, ostream); try { if (error == null) { writeResponse(pConfig, ostream, result); } else { writeError(pConfig, ostream, error); } ostream.close(); ostream = null; } finally { if (ostream != null) { try { ostream.close(); } catch (Throwable ignore) { } } } if (baos != null) { OutputStream dest = getOutputStream(pConfig, pConnection, baos.size()); try { baos.writeTo(dest); dest.close(); dest = null; } finally { if (dest != null) { try { dest.close(); } catch (Throwable ignore) { } } } } pConnection.close(); pConnection = null; } catch (IOException e) { throw new XmlRpcException("I/O error while processing request: " + e.getMessage(), e); } finally { if (pConnection != null) { try { pConnection.close(); } catch (Throwable ignore) { } } } log.debug("execute: <-"); }
From source file:com.xwiki.authentication.sts.STSTokenValidator.java
/** * validate - Validate Token. It's taking envelopedToken as a parameter. This token - is a token * which is recived to this method - from VRA. And checks it's trust level using utility * method of this class. It uses some additional methods implemented in this class. * And mothods from other auxiliary classes. * /*from w w w . ja v a 2 s . c o m*/ * @param envelopedToken String * @return List<STSClaim> * @throws ParserConfigurationException, SAXException, IOException, STSException, ConfigurationException, CertificateException, KeyException, SecurityException, ValidationException, UnmarshallingException, URISyntaxException, NoSuchAlgorithmException */ public List<STSClaim> validate(String envelopedToken) throws ParserConfigurationException, SAXException, IOException, STSException, ConfigurationException, CertificateException, KeyException, SecurityException, ValidationException, UnmarshallingException, URISyntaxException, NoSuchAlgorithmException { SignableSAMLObject samlToken; boolean trusted = false; STSException stsException = null; // Check token metadata if (envelopedToken.contains("RequestSecurityTokenResponse")) { samlToken = getSamlTokenFromRstr(envelopedToken); } else { samlToken = getSamlTokenFromSamlResponse(envelopedToken); } log.debug("\n===== envelopedToken ========\n" + samlToken.getDOM().getTextContent() + "\n=========="); String currentContext = getAttrVal(envelopedToken, "t:RequestSecurityTokenResponse", "Context"); if (!context.equals(currentContext)) { errorCollector.addError( new Throwable("Wrong token Context. Suspected: " + context + " got: " + currentContext)); stsException = new STSException( "Wrong token Context. Suspected: " + context + " got: " + currentContext); } if (this.validateExpiration) { Instant created = new Instant(getElementVal(envelopedToken, "wsu:Created")); Instant expires = new Instant(getElementVal(envelopedToken, "wsu:Expires")); if (!checkExpiration(created, expires)) { errorCollector.addError(new Throwable("Token Created or Expires elements have been expired")); stsException = new STSException("Token Created or Expires elements have been expired"); } } else { log.warn("Token time was not validated. To validate, set xwiki.authentication.sts.wct=1"); } if (certificate == null) { log.debug("\n"); log.debug("STSTokenValidator: cert is null, using old method"); if (issuer != null && issuerDN != null && !trustedSubjectDNs.isEmpty()) { if (!issuer.equals(getAttrVal(envelopedToken, "saml:Assertion", "Issuer"))) { errorCollector.addError(new Throwable("Wrong token Issuer")); stsException = new STSException("Wrong token Issuer"); } // Check SAML assertions if (!validateIssuerDN(samlToken, issuerDN)) { errorCollector.addError(new Throwable("Wrong token IssuerDN")); stsException = new STSException("Wrong token IssuerDN"); } for (String subjectDN : this.trustedSubjectDNs) { trusted |= validateSubjectDN(samlToken, subjectDN); } if (!trusted) { errorCollector.addError(new Throwable("Wrong token SubjectDN")); stsException = new STSException("Wrong token SubjectDN"); } } else { log.debug("\n"); log.debug("STSTokenValidator: Nothing to validate against"); errorCollector.addError(new Throwable("Nothing to validate against")); stsException = new STSException("Nothing to validate against"); } } else { log.debug("\n"); log.debug("STSTokenValidator: Using cert equals"); if (!certificate.equals(certFromToken(samlToken))) { errorCollector.addError(new Throwable("Local certificate didn't match the user suplied one")); stsException = new STSException("Local certificate didn't match the user suplied one"); } } String address = null; if (samlToken instanceof org.opensaml.saml1.core.Assertion) { address = getAudienceUri((org.opensaml.saml1.core.Assertion) samlToken); } URI audience = new URI(address); boolean validAudience = false; for (URI audienceUri : audienceUris) { validAudience |= audience.equals(audienceUri); } if (!validAudience) { errorCollector.addError(new Throwable("The token applies to an untrusted audience")); stsException = new STSException( String.format("The token applies to an untrusted audience: %s", new Object[] { audience })); } List<STSClaim> claims = null; if (samlToken instanceof org.opensaml.saml1.core.Assertion) { claims = getClaims((org.opensaml.saml1.core.Assertion) samlToken); } if (this.validateExpiration && samlToken instanceof org.opensaml.saml1.core.Assertion) { Instant notBefore = ((org.opensaml.saml1.core.Assertion) samlToken).getConditions().getNotBefore() .toInstant(); Instant notOnOrAfter = ((org.opensaml.saml1.core.Assertion) samlToken).getConditions().getNotOnOrAfter() .toInstant(); if (!checkExpiration(notBefore, notOnOrAfter)) { errorCollector.addError(new Throwable("Token Created or Expires elements have been expired")); stsException = new STSException("Token Created or Expires elements have been expired"); } } // Check token certificate and signature boolean valid = validateToken(samlToken); if (!valid) { errorCollector.addError(new Throwable("Invalid signature")); stsException = new STSException("Invalid signature"); } if (!(stsException == null)) throw stsException; return claims; }
From source file:gov.nih.nci.integration.caaers.invoker.CaAERSRegistrationServiceInvocationStrategy.java
private void handleErrorResponse(ServiceResponse response, ServiceInvocationResult result) { final List<WsError> wserrors = response.getWsError(); WsError error = null;//from w w w . j a v a 2 s . c o m IntegrationException ie = null; if (wserrors == null || wserrors.isEmpty()) { ie = new IntegrationException(IntegrationError._1053, new Throwable(response.getMessage()), response // NOPMD .getMessage()); } else { error = wserrors.get(0); ie = new IntegrationException(IntegrationError._1053, new Throwable(error.getException()), error // NOPMD .getErrorDesc()); } result.setInvocationException(ie); }
From source file:de.unikiel.inf.comsys.neo4j.inference.SPARQLInferenceTest.java
@Test public void missing() throws QueryEvaluationException, TupleQueryResultHandlerException, IOException, QueryResultParseException, QueryResultHandlerException { QueryResult q = this.runQuery(); Multiset<BindingSet> missing = q.getExpected(); missing.removeAll(q.getActual());// ww w . j a v a 2 s .c o m for (BindingSet b : missing) { collector.addError(new Throwable("Missing " + b + " in result set")); } }
From source file:com.qualogy.qafe.bind.core.application.ApplicationContext.java
public void handleLoadFailure(Throwable loadException, boolean loadAnyway) { // Set the load failure exception if (loadException.getMessage() != null && loadException.getMessage().equals("Premature end of file.")) { this.loadException = new Throwable("QAML file is empty/invalid. " + loadException.getMessage()); } else {/*from w ww. j a va2s .c om*/ this.loadException = loadException; } if (!loadAnyway) { // "Unload" the application-mapping of this context, // the context will remain in the cluster, so when rendering it knows which one is failing setApplicationMapping(null); } }
From source file:gov.nih.nci.integration.invoker.CaTissueSpecimenStrategyTest.java
/** * Tests updateSpecimens using the ServiceInvocationStrategy class for the failure scenario * /*from w w w .java 2 s. com*/ * @throws IntegrationException - IntegrationException * @throws JAXBException - JAXBException */ @SuppressWarnings({ "unchecked", "rawtypes" }) @Test public void updateSpecimensFailure() throws IntegrationException, JAXBException { final Date stTime = new Date(new java.util.Date().getTime()); xsltTransformer.transform(null, null, null); EasyMock.expectLastCall().andAnswer(new IAnswer() { public Object answer() { return getSpecimenXMLStr(); } }).anyTimes(); final ServiceInvocationResult clientResult = new ServiceInvocationResult(); clientResult.setDataChanged(false); clientResult.setOriginalData(getSpecimenXMLStr()); final IntegrationException ie = new IntegrationException(IntegrationError._1085, new Throwable( // NOPMD "Available Quantity cannot be greater than the Initial Quantity"), "Available Quantity cannot be greater than the Initial Quantity"); clientResult.setInvocationException(ie); EasyMock.expect(caTissueSpecimenClient.updateSpecimens((String) EasyMock.anyObject())) .andReturn(clientResult); EasyMock.replay(caTissueSpecimenClient); final ServiceInvocationMessage serviceInvocationMessage = prepareServiceInvocationMessage(REFMSGID, getSpecimenXMLStr(), stTime, caTissueUpdateSpecimenStrategy.getStrategyIdentifier()); final ServiceInvocationResult strategyResult = caTissueUpdateSpecimenStrategy .invoke(serviceInvocationMessage); Assert.assertNotNull(strategyResult); }
From source file:org.echocat.redprecursor.annotations.ParametersPassesExpressionUnitTest.java
@Test public void testThrowMessageForMessageOnViolation() throws Exception { final ParametersPassesExpression annotation = proxyAnnotation(ParametersPassesExpression.class, "value", "myExpression", "messageOnViolation", "My message - ${#expression}"); final MethodCall<ParametersPassesExpressionUnitTest> methodCall = toMethodCall( ParametersPassesExpressionUnitTest.class, this, "test", "a", 1, "b", 2); try {/*from w w w . j a v a 2 s . c om*/ new Evaluator().throwMessageFor(annotation, methodCall, null); fail("Exception missing"); } catch (IllegalArgumentException e) { assertThat(e.getMessage(), is("My message - " + annotation.value())); assertThat(e.getCause(), nullValue()); } final Throwable cause = new Throwable("myCause"); try { new Evaluator().throwMessageFor(annotation, methodCall, cause); fail("Exception missing"); } catch (IllegalArgumentException e) { assertThat(e.getMessage(), is("My message - " + annotation.value())); assertThat(e.getCause(), is(cause)); } }
From source file:de.tudarmstadt.ukp.dkpro.keyphrases.core.evaluator.KeyphraseEvaluator.java
private void computeMaxRecall(List<Keyphrase> keyphrases, Set<String> goldKeyphrases, String title) throws AnalysisEngineProcessException { int tp = 0;/* ww w. j ava2s . c o m*/ int fp = 0; List<String> keyphrasesToConsider = getKeyphrasesToConsider(keyphrases, keyphrases.size()); int nrOfGoldKeyphrases = goldKeyphrases.size(); // get the set of matching goldkeyphrases and equivalent extracted keyphrases Matchings matchings = getMatchings(new HashSet<String>(goldKeyphrases), keyphrasesToConsider); tp = matchings.getNumberOfMatchings(); fp = keyphrasesToConsider.size() - tp; // sanity check if (tp > nrOfGoldKeyphrases) { throw new AnalysisEngineProcessException( new Throwable("More true positives than gold standard keyphrases.")); } maxRecallCounter.setFileTPcount(title, keyphrasesToConsider.size(), tp); maxRecallCounter.setFileFPcount(title, keyphrasesToConsider.size(), fp); maxRecallCounter.setFileFNcount(title, keyphrasesToConsider.size(), nrOfGoldKeyphrases - tp); }
From source file:gov.nih.nci.integration.invoker.CaTissueParticipantStrategyTest.java
/** * Tests updateRegistrationParticipant using the ServiceInvocationStrategy class for the failure scenario * // ww w . j av a2 s.co m * @throws IntegrationException - IntegrationException * @throws JAXBException - JAXBException */ @SuppressWarnings({ "unchecked", "rawtypes" }) @Test public void updateParticipantRegistrationFailure() throws IntegrationException, JAXBException { final Date stTime = new Date(new java.util.Date().getTime()); xsltTransformer.transform(null, null, null); EasyMock.expectLastCall().andAnswer(new IAnswer() { public Object answer() { return getSpecimenXMLStr(); } }).anyTimes(); final ServiceInvocationResult clientResult = new ServiceInvocationResult(); clientResult.setDataChanged(false); clientResult.setOriginalData(getSpecimenXMLStr()); final IntegrationException ie = new IntegrationException(IntegrationError._1034, new Throwable( // NOPMD "Participant does not contain the unique identifier SSN"), "Participant does not contain the unique identifier SSN"); clientResult.setInvocationException(ie); EasyMock.expect(caTissueParticipantClient.updateRegistrationParticipant((String) EasyMock.anyObject())) .andReturn(clientResult); EasyMock.replay(caTissueParticipantClient); final ServiceInvocationMessage serviceInvocationMessage = prepareServiceInvocationMessage(REFMSGID, getSpecimenXMLStr(), stTime, caTissueUpdateRegistrationStrategy.getStrategyIdentifier()); final ServiceInvocationResult strategyResult = caTissueUpdateRegistrationStrategy .invoke(serviceInvocationMessage); Assert.assertNotNull(strategyResult); }