Example usage for java.lang Exception getCause

List of usage examples for java.lang Exception getCause

Introduction

In this page you can find the example usage for java.lang Exception getCause.

Prototype

public synchronized Throwable getCause() 

Source Link

Document

Returns the cause of this throwable or null if the cause is nonexistent or unknown.

Usage

From source file:com.swordlord.jalapeno.DBConnection.java

public Connection getRawConnection() {
    DataContext context = DataContext.createDataContext(DATA_DOMAIN_REPOSITORY);

    DataMap dataMap = context.getEntityResolver().getDataMap(DATA_MAP_REPOSITORY);

    DataNode dataNode = context.getParentDataDomain().lookupDataNode(dataMap);

    Connection connection = null;

    try {// w  w w .  j  a  v a2s.  co m
        connection = dataNode.getDataSource().getConnection();
    } catch (Exception e) {
        LOG.error(e.getCause());
    }

    return connection;

}

From source file:se.inera.axel.shs.broker.rs.internal.ReceiveServiceRouteBuilderTest.java

@DirtiesContext
@Test(enabled = false)/*from w  ww .  j a  v  a 2  s.  c o  m*/
public void sendingSynchRequestWithUnknownReceiverInVmShouldThrow() throws Exception {
    synchronEndpoint.expectedMessageCount(1);

    try {
        ShsMessage testMessage = make(createSynchMessageWithUnknownReceiver());
        camel.requestBody("direct:in-vm", testMessage, String.class);

        Assert.fail("request should throw exception");
    } catch (Exception e) {
        Throwable cause = e.getCause();
        Assert.assertNotNull(cause);
        Assert.assertTrue(cause instanceof UnknownReceiverException,
                "exception should be 'UnknownReceiverException'");
    }

}

From source file:at.ac.tuwien.dsg.rSybl.cloudInteractionUnit.enforcementPlugins.governance.GovOpsPlugin.java

public boolean setProto(Node entity, String protocol, GovernanceScope governanceScope, String uncertainty) {
    System.err.println("Called method setProto with parameters protocol=" + protocol + " , uncertainty="
            + uncertainty + " governanceScope=" + governanceScope);
    String strategyUncertainty = uncertainty.replace("=", ":").replace("AND", ",");
    String governanceUncertainty = governanceScope.getConsideringUncertainty().replace("=", ":").replace("AND",
            ",");
    String response = "";
    String response1 = "";
    try {//w w w . j  ava  2 s . co m
        response = callPOSTMethod("/governanceScope/setProcessProps/setProto", "application/json",
                governanceUncertainty);
        response1 = callPOSTMethod(
                "/governanceScope/invokeScope/setProto" + "/" + governanceScope.getQuery() + "/"
                        + "cChangeProto" + "/change?proto=" + protocol,
                "application/json", strategyUncertainty);
    } catch (Exception e) {
        RuntimeLogger.logger.error(e.getCause());
        return false;
    }
    System.out.println(response);
    System.out.println(response1);
    return true;
}

From source file:com.google.code.jerseyclients.asynchttpclient.AsyncHttpClientJerseyClientHandler.java

/**
 * @see com.sun.jersey.api.client.ClientHandler#handle(com.sun.jersey.api.client.ClientRequest)
 *//*from ww w .j  av  a  2  s .  c o  m*/
public ClientResponse handle(final ClientRequest clientRequest) throws ClientHandlerException {

    final BoundRequestBuilder boundRequestBuilder = getBoundRequestBuilder(clientRequest);

    PerRequestConfig perRequestConfig = new PerRequestConfig();
    perRequestConfig.setRequestTimeoutInMs(this.jerseyHttpClientConfig.getReadTimeOut());

    if (this.jerseyHttpClientConfig.getProxyInformation() != null) {
        ProxyServer proxyServer = new ProxyServer(jerseyHttpClientConfig.getProxyInformation().getProxyHost(),
                jerseyHttpClientConfig.getProxyInformation().getProxyPort());
        perRequestConfig = new PerRequestConfig(proxyServer, this.jerseyHttpClientConfig.getReadTimeOut());
    }

    boundRequestBuilder.setPerRequestConfig(perRequestConfig);

    if (this.jerseyHttpClientConfig.getApplicationCode() != null) {
        boundRequestBuilder.addHeader(this.jerseyHttpClientConfig.getApplicationCodeHeader(),
                this.jerseyHttpClientConfig.getApplicationCode());
    }
    if (this.jerseyHttpClientConfig.getOptionnalHeaders() != null) {
        for (Entry<String, String> entry : this.jerseyHttpClientConfig.getOptionnalHeaders().entrySet()) {
            boundRequestBuilder.addHeader(entry.getKey(), entry.getValue());
        }
    }

    if (StringUtils.equalsIgnoreCase("POST", clientRequest.getMethod())) {

        if (clientRequest.getEntity() != null) {
            final RequestEntityWriter re = getRequestEntityWriter(clientRequest);

            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            try {
                re.writeRequestEntity(new CommittingOutputStream(baos) {
                    @Override
                    protected void commit() throws IOException {
                        writeOutBoundHeaders(clientRequest.getHeaders(), boundRequestBuilder);
                    }
                });
            } catch (IOException ex) {
                throw new ClientHandlerException(ex);
            }

            boundRequestBuilder.setBody(new ByteArrayInputStream(baos.toByteArray()));

        }
    } else {
        writeOutBoundHeaders(clientRequest.getHeaders(), boundRequestBuilder);
    }
    try {
        StopWatch stopWatch = new StopWatch();
        stopWatch.reset();
        stopWatch.start();
        Future<Response> futureResponse = boundRequestBuilder.execute();
        Response response = futureResponse.get();
        int httpReturnCode = response.getStatusCode();
        stopWatch.stop();
        log.info("time to call rest url " + clientRequest.getURI() + ", " + stopWatch.getTime() + " ms");
        // in case of empty content returned we returned an empty stream
        // to return a null object
        if (httpReturnCode == Status.NO_CONTENT.getStatusCode()) {
            new ClientResponse(httpReturnCode, getInBoundHeaders(response), IOUtils.toInputStream(""),
                    getMessageBodyWorkers());
        }
        return new ClientResponse(httpReturnCode, getInBoundHeaders(response),
                response.getResponseBodyAsStream() == null ? IOUtils.toInputStream("")
                        : response.getResponseBodyAsStream(),
                getMessageBodyWorkers());
    } catch (Exception e) {
        if (e.getCause() != null && (e.getCause() instanceof TimeoutException)) {
            throw new ClientHandlerException(new SocketTimeoutException());
        }
        throw new ClientHandlerException(e);
    }
}

From source file:at.ac.tuwien.dsg.rSybl.cloudInteractionUnit.enforcementPlugins.governance.GovOpsPlugin.java

public boolean updatePollRate(Node entity, String pollRate, GovernanceScope governanceScope,
        String uncertainty) {//w w w . j  a  v  a2 s . c o m
    System.err.println("Called method update poll rate with parameters pollRate=" + pollRate + " , uncertainty="
            + uncertainty + " governanceScope=" + governanceScope);
    String strategyUncertainty = uncertainty.replace("=", ":").replace("AND", ",");
    String governanceUncertainty = governanceScope.getConsideringUncertainty().replace("=", ":").replace("AND",
            ",");
    String response = "";
    String response1 = "";
    try {
        response = callPOSTMethod("/governanceScope/setProcessProps/setSensorRate", "application/json",
                governanceUncertainty);
        response1 = callPOSTMethod(
                "/governanceScope/invokeScope/setSensorRate" + "/" + governanceScope.getQuery() + "/"
                        + "cChangeSensorRate" + "/update?interval=" + pollRate,
                "application/json", strategyUncertainty);
    } catch (Exception e) {
        RuntimeLogger.logger.error(e.getCause());
        return false;
    }
    System.out.println(response);
    System.out.println(response1);
    return true;
}

From source file:com.aliyun.odps.ship.download.DownloadTableTest.java

@Test
public void testDownloadNonExistentPar_Sequential() throws Exception {
    ExecutionContext context = ExecutionContext.init();
    String s = "tunnel d %s %s -cp=false";
    DShipCommand cmd;/*from w w  w. j  ava2 s .  co m*/
    try {
        cmd = DShipCommand.parse(String.format(s, TABLE + "/non_exsistent_par='a'", PATH), context);
        assertNotNull(cmd);
        cmd.run();
        Assert.fail("download a non-existent partition");
    } catch (Exception e) {
        assertTrue("error message",
                e.getCause().getMessage().indexOf("can not specify partition for an unpartitioned table") >= 0);
    }
}

From source file:io.uengine.web.registe.RegisteController.java

@RequestMapping(value = "/remail", method = RequestMethod.POST)
@ResponseStatus(HttpStatus.OK)/*from  w w w . j a va2 s .c o m*/
@ResponseBody
public Response remail(@RequestBody Map params) {
    Response response = new Response();
    try {
        String email = params.get("email").toString();
        registeService.sendRegisteMail(email);
        response.setSuccess(true);
    } catch (Exception ex) {
        response.setSuccess(false);
        response.getError().setMessage(ex.getMessage());
        if (ex.getCause() != null)
            response.getError().setCause(ex.getCause().getMessage());
        response.getError().setException(ExceptionUtils.getFullStackTrace(ex));
    }
    return response;
}

From source file:nz.co.senanque.vaadinsupport.viewmanager.LoginLayout.java

public void afterPropertiesSet() throws Exception {
    setSizeFull();//  www. j a v  a2  s  . c o m
    Panel loginPanel = new Panel();
    AbstractLayout panelLayout = (AbstractLayout) loginPanel.getContent();
    panelLayout.setMargin(false);
    loginPanel.setWidth("460px");
    final MessageSourceAccessor messageSourceAccessor = new MessageSourceAccessor(m_messageSource);
    final LoginForm loginForm = new LoginFormI18n(messageSourceAccessor.getMessage("username"),
            messageSourceAccessor.getMessage("password"), messageSourceAccessor.getMessage("login.button"),
            messageSourceAccessor.getMessage("welcome"));
    loginForm.setHeight("300px");
    loginForm.addListener(new LoginListener() {

        private static final long serialVersionUID = 5201900702970450254L;

        public void onLogin(LoginEvent event) {
            if (getLoginListener() != null) {
                try {
                    getLoginListener().onLogin(event);
                } catch (Exception e) {
                    Throwable cause = e.getCause();
                    if (cause == null || !(cause instanceof LoginException)) {
                        logger.error(e.getMessage(), e);
                    }
                    String message = messageSourceAccessor.getMessage("Bad.Login", "Bad Login");
                    getViewManager().getMainWindow().showNotification(message, Notification.TYPE_ERROR_MESSAGE);
                    return;
                }
            }
            getViewManager().loadApplication();
        }
    });
    loginPanel.addComponent(loginForm);
    addComponent(loginPanel);
    setComponentAlignment(loginPanel, Alignment.MIDDLE_CENTER);
}

From source file:se.skltp.cooperation.web.rest.v1.controller.ServiceConsumerControllerTest.java

@Test
public void get_shouldThrowNotFoundException() throws Exception {

    when(serviceConsumerServiceMock.find(anyLong())).thenReturn(null);

    try {//from   w ww.  j  av  a  2 s .c om
        mockMvc.perform(get("/api/v1/serviceConsumers/{id}", Long.MAX_VALUE)).andExpect(status().isNotFound());
        fail("Should have thrown a exception");
    } catch (Exception e) {
        assertEquals(e.getCause().getClass(), ResourceNotFoundException.class);
    }

}

From source file:ch.ralscha.extdirectspring.controller.SSEHandler.java

public void handle(String beanName, String method, HttpServletRequest request, HttpServletResponse response,
        Locale locale) throws Exception {

    MethodInfo methodInfo = MethodInfoCache.INSTANCE.get(beanName, method);

    SSEvent result = null;/*from  ww w  .  j  ava  2s. co  m*/
    SSEWriter sseWriter = new SSEWriter(response);

    if (methodInfo != null) {

        try {

            Object[] parameters = configurationService.getParametersResolver().prepareParameters(request,
                    response, locale, methodInfo, sseWriter);
            Object methodReturnValue = null;

            if (configurationService.getConfiguration().isSynchronizeOnSession()
                    || methodInfo.isSynchronizeOnSession()) {
                HttpSession session = request.getSession(false);
                if (session != null) {
                    Object mutex = WebUtils.getSessionMutex(session);
                    synchronized (mutex) {
                        methodReturnValue = ExtDirectSpringUtil.invoke(
                                configurationService.getApplicationContext(), beanName, methodInfo, parameters);
                    }
                } else {
                    methodReturnValue = ExtDirectSpringUtil.invoke(configurationService.getApplicationContext(),
                            beanName, methodInfo, parameters);
                }
            } else {
                methodReturnValue = ExtDirectSpringUtil.invoke(configurationService.getApplicationContext(),
                        beanName, methodInfo, parameters);
            }

            if (methodReturnValue instanceof SSEvent) {
                result = (SSEvent) methodReturnValue;
            } else if (methodReturnValue != null) {
                result = new SSEvent();
                result.setData(methodReturnValue.toString());
            }

        } catch (Exception e) {
            log.error("Error polling method '" + beanName + "." + method + "'",
                    e.getCause() != null ? e.getCause() : e);

            Throwable cause;
            if (e.getCause() != null) {
                cause = e.getCause();
            } else {
                cause = e;
            }

            result = new SSEvent();
            result.setEvent("error");
            result.setData(configurationService.getConfiguration().getMessage(cause));

            if (configurationService.getConfiguration().isSendStacktrace()) {
                result.setComment(ExtDirectSpringUtil.getStackTrace(cause));
            }
        }
    } else {
        log.error("Error invoking method '" + beanName + "." + method + "'. Method or Bean not found");

        result = new SSEvent();
        result.setEvent("error");
        result.setData(configurationService.getConfiguration().getDefaultExceptionMessage());

        if (configurationService.getConfiguration().isSendStacktrace()) {
            result.setComment("Bean or Method '" + beanName + "." + method + "' not found");
        }
    }

    if (result != null) {
        sseWriter.write(result);
    }
}