Example usage for org.apache.commons.httpclient HttpStatus SC_INTERNAL_SERVER_ERROR

List of usage examples for org.apache.commons.httpclient HttpStatus SC_INTERNAL_SERVER_ERROR

Introduction

In this page you can find the example usage for org.apache.commons.httpclient HttpStatus SC_INTERNAL_SERVER_ERROR.

Prototype

int SC_INTERNAL_SERVER_ERROR

To view the source code for org.apache.commons.httpclient HttpStatus SC_INTERNAL_SERVER_ERROR.

Click Source Link

Document

<tt>500 Server Error</tt> (HTTP/1.0 - RFC 1945)

Usage

From source file:ai.grakn.engine.controller.TasksController.java

private Json addTaskToManager(TaskStateWithConfiguration taskState) {
    Json singleTaskReturnJson = Json.object().set("index", taskState.getIndex());
    try {//from w  ww .java2s. c om
        manager.addTask(taskState.getTaskState(), TaskConfiguration.of(taskState.getConfiguration()));
        singleTaskReturnJson.set("id", taskState.getTaskState().getId().getValue());
        singleTaskReturnJson.set("code", HttpStatus.SC_OK);
    } catch (Exception e) {
        LOG.error("Server error while adding the task", e);
        singleTaskReturnJson.set("code", HttpStatus.SC_INTERNAL_SERVER_ERROR);
    }
    return singleTaskReturnJson;
}

From source file:de.lemo.apps.restws.client.InitialisationImpl.java

@Override
public JSONObject taskResult(String taskId) {

    JSONObject json = new JSONObject();
    Response taskResult = null;/*from   w w w .  ja v a 2 s .c  o  m*/
    try {
        taskResult = taskManager.taskResult(taskId);
    } catch (RuntimeException e) {
        if (!e.getCause().getClass().equals(ConnectionPoolTimeoutException.class)) {
            // ignore ConnectionPoolTimeoutException, rethrow anything else
            //throw e;
        }
    }

    int status = (taskResult == null) ? HttpStatus.SC_GATEWAY_TIMEOUT : taskResult.getStatus();

    if (status == HttpStatus.SC_INTERNAL_SERVER_ERROR) {
        // DMS error (maybe a processing timeout)
        json.put("status", HttpStatus.SC_BAD_GATEWAY);
    } else {
        json.put("status", status);
    }

    if (status == HttpStatus.SC_OK) {
        @SuppressWarnings("unchecked")
        ClientResponse<String> clientResponse = (ClientResponse<String>) taskResult;
        String analysisResult = clientResponse.getEntity(String.class);
        json.put("bideResult", new JSONObject(analysisResult));
    }
    return json;
}

From source file:com.amazonaws.elasticmapreduce.AmazonElasticMapReduceClient.java

/**
 * Invokes request using parameters from parameters map.
 * Returns response of the T type passed to this method
 *///from w  w  w.j  av a  2 s.c  om
private <T> T invoke(Class<T> clazz, Map<String, String> parameters) throws AmazonElasticMapReduceException {

    String actionName = parameters.get("Action");
    T response = null;
    String responseBodyString = null;
    PostMethod method = new PostMethod(config.getServiceURL());
    int status = -1;

    log.debug("Invoking" + actionName + " request. Current parameters: " + parameters);

    try {

        /* Set content type and encoding */
        log.debug("Setting content-type to application/x-www-form-urlencoded; charset="
                + DEFAULT_ENCODING.toLowerCase());
        method.addRequestHeader("Content-Type",
                "application/x-www-form-urlencoded; charset=" + DEFAULT_ENCODING.toLowerCase());

        /* Add required request parameters and set request body */
        log.debug("Adding required parameters...");
        addRequiredParametersToRequest(method, parameters);
        log.debug("Done adding additional required parameteres. Parameters now: " + parameters);

        boolean shouldRetry = true;
        int retries = 0;
        do {
            log.debug("Sending Request to host:  " + config.getServiceURL());

            try {

                /* Submit request */
                status = httpClient.executeMethod(method);

                /* Consume response stream */
                responseBodyString = getResponsBodyAsString(method.getResponseBodyAsStream());

                /* Successful response. Attempting to unmarshal into the <Action>Response type */
                if (status == HttpStatus.SC_OK) {
                    shouldRetry = false;
                    log.debug("Received Response. Status: " + status + ". " + "Response Body: "
                            + responseBodyString);
                    if (responseBodyString != null
                            && responseBodyString.trim().endsWith(actionName + "Response>")) {
                        log.debug("Attempting to transform " + actionName + "Response type...");
                        responseBodyString = ResponseTransformer.transform(responseBodyString);
                        log.debug("Transformed response to: " + responseBodyString);
                    }
                    log.debug("Attempting to unmarshal into the " + actionName + "Response type...");
                    response = clazz.cast(getUnmarshaller()
                            .unmarshal(new StreamSource(new StringReader(responseBodyString))));

                    log.debug("Unmarshalled response into " + actionName + "Response type.");

                } else { /* Unsucessful response. Attempting to unmarshall into ErrorResponse  type */

                    log.debug("Received Response. Status: " + status + ". " + "Response Body: "
                            + responseBodyString);

                    if ((status == HttpStatus.SC_INTERNAL_SERVER_ERROR
                            || status == HttpStatus.SC_SERVICE_UNAVAILABLE) && pauseIfRetryNeeded(++retries)) {
                        shouldRetry = true;
                    } else {
                        log.debug("Attempting to unmarshal into the ErrorResponse type...");
                        ErrorResponse errorResponse = (ErrorResponse) getUnmarshaller()
                                .unmarshal(new StreamSource(new StringReader(responseBodyString)));

                        log.debug("Unmarshalled response into the ErrorResponse type.");

                        com.amazonaws.elasticmapreduce.model.Error error = errorResponse.getError().get(0);

                        throw new AmazonElasticMapReduceException(error.getMessage(), status, error.getCode(),
                                error.getType(), errorResponse.getRequestId(), errorResponse.toXML());
                    }
                }
            } catch (JAXBException je) {
                /* Response cannot be unmarshalled neither as <Action>Response or ErrorResponse types.
                Checking for other possible errors. */

                log.debug("Caught JAXBException", je);
                log.debug("Response cannot be unmarshalled neither as " + actionName
                        + "Response or ErrorResponse types." + "Checking for other possible errors.");

                AmazonElasticMapReduceException awse = processErrors(responseBodyString, status);

                throw awse;

            } catch (IOException ioe) {
                log.debug("Caught IOException exception", ioe);
                throw new AmazonElasticMapReduceException("Internal Error", ioe);
            } catch (Exception e) {
                log.debug("Caught Exception", e);
                throw new AmazonElasticMapReduceException(e);
            } finally {
                method.releaseConnection();
            }
        } while (shouldRetry);

    } catch (AmazonElasticMapReduceException se) {
        log.debug("Caught AmazonElasticMapReduceException", se);
        throw se;

    } catch (Throwable t) {
        log.debug("Caught Exception", t);
        throw new AmazonElasticMapReduceException(t);
    }
    return response;
}

From source file:ac.elements.io.Signature.java

/**
 * Gets the XML response as a string./*from  w  w  w  .jav  a 2  s .  c  o  m*/
 * 
 * @param keyValues
 *            the keyValues pairs
 * @param id
 *            the id
 * @param key
 *            the key
 * 
 * @return the XML response as a string
 */
public static String getXMLResponse(final Map<String, String> keyValues, String id, String key) {

    Map<String, String> parameters;
    try {
        parameters = Signature.getParameters(keyValues, id, key);
    } catch (SignatureException se) {
        se.printStackTrace();
        throw new RuntimeException("CredentialsNotFound: Please make sure " + "that the file "
                + "'aws.properties' is located in the classpath " + "(usually "
                + "$TOMCAT_HOME/webapps/mysimpledb/WEB-INF/classes" + ") of the java virtual machine. "
                + "This file should " + "define your AWSAccessKeyId and SecretAccessKey.");
    }
    int status = -1;
    String response = null;

    PostMethod method = new PostMethod(SERVICE_URL);

    for (Entry<String, String> entry : parameters.entrySet()) {
        method.addParameter(entry.getKey(), entry.getValue());
    }

    String en = null;
    try {

        /* Set content type and encoding */
        method.addRequestHeader("Content-Type",
                "application/x-www-form-urlencoded; charset=" + DEFAULT_ENCODING.toLowerCase());
        boolean shouldRetry = true;
        int retries = 0;
        do {
            // log.debug("Sending Request to host: " + SERVICE_URL);

            try {

                /* Submit request */
                status = Signature.httpClient.executeMethod(method);

                /* Consume response stream */
                response = getResponsBodyAsString(method.getResponseBodyAsStream());

                if (status == HttpStatus.SC_OK) {
                    shouldRetry = false;
                    // log.debug("Received Response. Status: " + status + ".
                    // " +
                    // "Response Body: " + responseBodyString);

                } else {
                    // log.debug("Received Response. Status: " + status + ".
                    // " +
                    // "Response Body: " + responseBodyString);

                    if ((status == HttpStatus.SC_INTERNAL_SERVER_ERROR
                            || status == HttpStatus.SC_SERVICE_UNAVAILABLE) && pauseIfRetryNeeded(++retries)) {
                        shouldRetry = true;
                    } else {
                        shouldRetry = false;
                    }
                }
            } catch (ConnectException ce) {
                shouldRetry = false;
                en =

                        "ConnectException: This webapp is not able to " + "connect, a likely cause is your "
                                + "firewall settings, please double check.";

            } catch (UnknownHostException uhe) {
                shouldRetry = false;
                en =

                        "UnknownHostException: This webapp is not able to " + "connect, to sdb.amazonaws.com "
                                + "please check connection and your " + "firewall settings.";

            } catch (IOException ioe) {

                ++retries;
                log.error("Caught IOException: ", ioe);
                ioe.printStackTrace();

            } catch (Exception e) {
                ++retries;
                log.error("Caught Exception: ", e);
                e.printStackTrace();
            } finally {
                method.releaseConnection();
            }
            // if (shouldRetry && retries == 1) {
            // concurrentRetries++;
            // log.warn("concurrentRetries: " + concurrentRetries);
            // }
            // if (concurrentRetries >= 1) {
            // StatementAsync.throttleDown();
            // } else {
            // StatementAsync.throttleUp();
            // }
        } while (shouldRetry);
        // if (retries > 0 && concurrentRetries > 0)
        // concurrentRetries--;
    } catch (Exception e) {
        log.error("Caught Exception: ", e);
        e.printStackTrace();
    }
    if (en != null) {
        throw new RuntimeException(en);
    }
    if (response.indexOf("<Code>InvalidClientTokenId</Code>") != -1) {

        throw new RuntimeException("InvalidClientTokenId: The AWS Access Key Id you provided "
                + "does not exist in Amazons records. The file " + "aws.properties should define your "
                + "AWSAccessKeyId and SecretAccessKey.");

    } else if (response.indexOf("<Code>SignatureDoesNotMatch</Code>") != -1) {

        throw new RuntimeException("SignatureDoesNotMatch: The request signature we "
                + "calculated does not match the signature you " + "provided. Check your Secret Access Key "
                + "and signing method. Consult the service " + "documentation for details.");
    } else if (response.indexOf("<Code>AuthFailure</Code>") != -1) {

        throw new RuntimeException("AuthFailure: AWS was not able to validate the provided "
                + "access credentials. This usually means you do " + "not have a simple db account. "
                + "Go to <a href=\"" + "http://aws.amazon.com/simpledb/\">Amazon's "
                + "Simple DB</a> page and create an account, if " + "you do not have one at this moment.");
    } else if (response.indexOf("<Errors>") != -1) {

        log.error("Found keyword error in response:\n" + response);
        log.error("Key value pairs sent:\n" + keyValues);

    }
    return response;

}

From source file:com.eviware.soapui.impl.wsdl.mock.WsdlMockResponse.java

private void handleFault(String responseContent) {
    try {/*from w  w w  . ja  va  2 s . co  m*/
        if (SoapUtils.isSoapFault(responseContent)) {
            setResponseHttpStatus(HttpStatus.SC_INTERNAL_SERVER_ERROR);
        }
    } catch (XmlException e) {
        SoapUI.logError(e);
    }
}

From source file:com.mirth.connect.connectors.http.HttpReceiver.java

private void sendResponse(Request baseRequest, HttpServletResponse servletResponse,
        DispatchResult dispatchResult) throws Exception {
    ContentType contentType = ContentType
            .parse(replaceValues(connectorProperties.getResponseContentType(), dispatchResult));
    if (!connectorProperties.isResponseDataTypeBinary() && contentType.getCharset() == null) {
        /*//w w w .j av  a2 s.c  o m
         * If text mode is used and a specific charset isn't already defined, use the one from
         * the connector properties. We can't use ContentType.withCharset here because it
         * doesn't preserve other parameters, like boundary definitions
         */
        contentType = ContentType.parse(contentType.toString() + "; charset="
                + CharsetUtils.getEncoding(connectorProperties.getCharset()));
    }
    servletResponse.setContentType(contentType.toString());

    // set the response headers
    for (Entry<String, List<String>> entry : connectorProperties.getResponseHeaders().entrySet()) {
        for (String headerValue : entry.getValue()) {
            servletResponse.addHeader(entry.getKey(), replaceValues(headerValue, dispatchResult));
        }
    }

    // set the status code
    int statusCode = NumberUtils
            .toInt(replaceValues(connectorProperties.getResponseStatusCode(), dispatchResult), -1);

    /*
     * set the response body and status code (if we choose a response from the drop-down)
     */
    if (dispatchResult != null && dispatchResult.getSelectedResponse() != null) {
        dispatchResult.setAttemptedResponse(true);

        Response selectedResponse = dispatchResult.getSelectedResponse();
        Status newMessageStatus = selectedResponse.getStatus();

        /*
         * If the status code is custom, use the entered/replaced string If is is not a
         * variable, use the status of the destination's response (success = 200, failure = 500)
         * Otherwise, return 200
         */
        if (statusCode != -1) {
            servletResponse.setStatus(statusCode);
        } else if (newMessageStatus != null && newMessageStatus.equals(Status.ERROR)) {
            servletResponse.setStatus(HttpStatus.SC_INTERNAL_SERVER_ERROR);
        } else {
            servletResponse.setStatus(HttpStatus.SC_OK);
        }

        String message = selectedResponse.getMessage();

        if (message != null) {
            OutputStream responseOutputStream = servletResponse.getOutputStream();
            byte[] responseBytes;
            if (connectorProperties.isResponseDataTypeBinary()) {
                responseBytes = Base64Util.decodeBase64(message.getBytes("US-ASCII"));
            } else {
                responseBytes = message.getBytes(CharsetUtils.getEncoding(connectorProperties.getCharset()));
            }

            // If the client accepts GZIP compression, compress the content
            boolean gzipResponse = false;
            for (Enumeration<String> en = baseRequest.getHeaders("Accept-Encoding"); en.hasMoreElements();) {
                String acceptEncoding = en.nextElement();

                if (acceptEncoding != null && acceptEncoding.contains("gzip")) {
                    gzipResponse = true;
                    break;
                }
            }

            if (gzipResponse) {
                servletResponse.setHeader(HTTP.CONTENT_ENCODING, "gzip");
                GZIPOutputStream gzipOutputStream = new GZIPOutputStream(responseOutputStream);
                gzipOutputStream.write(responseBytes);
                gzipOutputStream.finish();
            } else {
                responseOutputStream.write(responseBytes);
            }

            // TODO include full HTTP payload in sentResponse
        }
    } else {
        /*
         * If the status code is custom, use the entered/replaced string Otherwise, return 200
         */
        if (statusCode != -1) {
            servletResponse.setStatus(statusCode);
        } else {
            servletResponse.setStatus(HttpStatus.SC_OK);
        }
    }
}

From source file:edu.psu.iam.cpr.core.util.Utility.java

/**
 * This method is used to convert an CPR status code to an analogous HTTP status code.
 *
 * @param statusCode contains the CPR status code.
 * @return will return the HTTP status code.
 *//*from  w w w.  ja  va2s  .  co m*/
public static int convertCprReturnToHttpStatus(final int statusCode) {

    final ReturnType returnType = ReturnType.get(statusCode);
    int httpStatus = HttpStatus.SC_INTERNAL_SERVER_ERROR;

    switch (returnType) {
    case SUCCESS:
        httpStatus = HttpStatus.SC_OK;
        break;
    case ADD_FAILED_EXCEPTION:
        httpStatus = HttpStatus.SC_INTERNAL_SERVER_ERROR;
        break;
    case ALREADY_DELETED_EXCEPTION:
        httpStatus = HttpStatus.SC_BAD_REQUEST;
        break;
    case RECORD_NOT_FOUND_EXCEPTION:
        httpStatus = HttpStatus.SC_NOT_FOUND;
        break;
    case ARCHIVE_FAILED_EXCEPTION:
        httpStatus = HttpStatus.SC_INTERNAL_SERVER_ERROR;
        break;
    case NOT_SPECIFIED_EXCEPTION:
        httpStatus = HttpStatus.SC_BAD_REQUEST;
        break;
    case TYPE_NOT_FOUND_EXCEPTION:
        httpStatus = HttpStatus.SC_BAD_REQUEST;
        break;
    case INVALID_PARAMETERS_EXCEPTION:
        httpStatus = HttpStatus.SC_BAD_REQUEST;
        break;
    case YN_PARAMETERS_EXCEPTION:
        httpStatus = HttpStatus.SC_BAD_REQUEST;
        break;
    case GENERAL_EXCEPTION:
        httpStatus = HttpStatus.SC_BAD_REQUEST;
        break;
    case PARAMETER_LENGTH_EXCEPTION:
        httpStatus = HttpStatus.SC_BAD_REQUEST;
        break;
    case MESSAGE_CREATION_EXCEPTION:
        httpStatus = HttpStatus.SC_INTERNAL_SERVER_ERROR;
        break;
    case MESSAGE_INITIALIZATION_EXCEPTION:
        httpStatus = HttpStatus.SC_INTERNAL_SERVER_ERROR;
        break;
    case MESSAGE_SEND_EXCEPTION:
        httpStatus = HttpStatus.SC_INTERNAL_SERVER_ERROR;
        break;
    case NOT_AUTHORIZED_EXCEPTION:
        httpStatus = HttpStatus.SC_UNAUTHORIZED;
        break;
    case PERSON_NOT_ACTIVE_EXCEPTION:
        httpStatus = HttpStatus.SC_BAD_REQUEST;
        break;
    case PERSON_NOT_FOUND_EXCEPTION:
        httpStatus = HttpStatus.SC_NOT_FOUND;
        break;
    case PSUID_NOT_FOUND_EXCEPTION:
        httpStatus = HttpStatus.SC_NOT_FOUND;
        break;
    case SERVICE_AUTHENTICATION_EXCEPTION:
        httpStatus = HttpStatus.SC_UNAUTHORIZED;
        break;
    case SET_PRIMARY_FAILED_EXCEPTION:
        httpStatus = HttpStatus.SC_INTERNAL_SERVER_ERROR;
        break;
    case UPDATE_FAILED_EXCEPTION:
        httpStatus = HttpStatus.SC_INTERNAL_SERVER_ERROR;
        break;
    case WEB_SERVICE_NOT_FOUND_EXCEPTION:
        httpStatus = HttpStatus.SC_INTERNAL_SERVER_ERROR;
        break;
    case GI_FAILURE:
        httpStatus = HttpStatus.SC_INTERNAL_SERVER_ERROR;
        break;
    case DB_CONNECTION_FAILURE:
        httpStatus = HttpStatus.SC_INTERNAL_SERVER_ERROR;
        break;
    case GENERAL_DATABASE_EXCEPTION:
        httpStatus = HttpStatus.SC_INTERNAL_SERVER_ERROR;
        break;
    case UNARCHIVE_FAILED_EXCEPTION:
        httpStatus = HttpStatus.SC_INTERNAL_SERVER_ERROR;
        break;
    case DATA_CHANGE_EXCEPTION:
        httpStatus = HttpStatus.SC_UNAUTHORIZED;
        break;
    case SECURITY_OPERATION_EXCEPTION:
        httpStatus = HttpStatus.SC_UNAUTHORIZED;
        break;
    case AFFILIATION_USE_EXCEPTION:
        httpStatus = HttpStatus.SC_INTERNAL_SERVER_ERROR;
        break;
    case IAP_USE_EXCEPTION:
        httpStatus = HttpStatus.SC_INTERNAL_SERVER_ERROR;
        break;
    case RECORD_ALREADY_EXISTS:
        httpStatus = HttpStatus.SC_INTERNAL_SERVER_ERROR;
        break;
    case EXACT_MATCH_EXCEPTION:
        httpStatus = HttpStatus.SC_MULTIPLE_CHOICES;
        break;
    case NEAR_MATCH_EXCEPTION:
        httpStatus = HttpStatus.SC_MULTIPLE_CHOICES;
        break;
    case MESSAGE_RECEIVE_EXCEPTION:
        httpStatus = HttpStatus.SC_INTERNAL_SERVER_ERROR;
        break;
    case DIRECTORY_EXCEPTION:
        httpStatus = HttpStatus.SC_INTERNAL_SERVER_ERROR;
        break;
    case JSON_EXCEPTION:
        httpStatus = HttpStatus.SC_INTERNAL_SERVER_ERROR;
        break;
    case JMS_EXCEPTION:
        httpStatus = HttpStatus.SC_INTERNAL_SERVER_ERROR;
        break;
    case NOT_IMPLEMENTED_EXCEPTION:
        httpStatus = HttpStatus.SC_INTERNAL_SERVER_ERROR;
        break;
    default:
        break;
    }
    return httpStatus;
}

From source file:com.amazonaws.fps.AmazonFPSClient.java

/**
 * Invokes request using parameters from parameters map. Returns response of
 * the T type passed to this method/*from  w w  w.  ja va2 s .co  m*/
 */
private <T> T invoke(Class<T> clazz, Map<String, String> parameters) throws AmazonFPSException {

    String actionName = parameters.get("Action");
    T response = null;
    String responseBodyString = null;
    PostMethod method = new PostMethod(config.getServiceURL());
    int status = -1;

    log.debug("Invoking" + actionName + " request. Current parameters: " + parameters);

    try {

        /* Set content type and encoding */
        log.debug("Setting content-type to application/x-www-form-urlencoded; charset="
                + DEFAULT_ENCODING.toLowerCase());
        method.addRequestHeader("Content-Type",
                "application/x-www-form-urlencoded; charset=" + DEFAULT_ENCODING.toLowerCase());

        /* Add required request parameters and set request body */
        log.debug("Adding required parameters...");
        addRequiredParametersToRequest(method, parameters);
        System.out.println(parameters);
        log.debug("Done adding additional required parameteres. Parameters now: " + parameters);

        boolean shouldRetry = true;
        int retries = 0;
        do {
            log.debug("Sending Request to host:  " + config.getServiceURL());

            try {

                /* Submit request */
                status = httpClient.executeMethod(method);

                /* Consume response stream */
                responseBodyString = getResponsBodyAsString(method.getResponseBodyAsStream());

                /*
                 * Successful response. Attempting to unmarshal into the
                 * <Action>Response type
                 */
                if (status == HttpStatus.SC_OK) {
                    shouldRetry = false;
                    log.debug("Received Response. Status: " + status + ". " + "Response Body: "
                            + responseBodyString);
                    log.debug("Attempting to unmarshal into the " + actionName + "Response type...");
                    response = clazz.cast(getUnmarshaller()
                            .unmarshal(new StreamSource(new StringReader(responseBodyString))));

                    log.debug("Unmarshalled response into " + actionName + "Response type.");

                } else { /*
                          * Unsucessful response. Attempting to unmarshall
                          * into ErrorResponse type
                          */

                    log.debug("Received Response. Status: " + status + ". " + "Response Body: "
                            + responseBodyString);

                    if ((status == HttpStatus.SC_INTERNAL_SERVER_ERROR
                            || status == HttpStatus.SC_SERVICE_UNAVAILABLE) && pauseIfRetryNeeded(++retries)) {
                        shouldRetry = true;
                    } else {
                        log.debug("Attempting to unmarshal into the ErrorResponse type...");
                        ErrorResponse errorResponse = (ErrorResponse) getUnmarshaller()
                                .unmarshal(new StreamSource(new StringReader(responseBodyString)));

                        log.debug("Unmarshalled response into the ErrorResponse type.");

                        com.amazonaws.fps.model.Error error = errorResponse.getError().get(0);

                        throw new AmazonFPSException(error.getMessage(), status, error.getCode(),
                                error.getType(), errorResponse.getRequestId(), errorResponse.toXML());
                    }
                }
            } catch (JAXBException je) {
                /*
                 * Response cannot be unmarshalled neither as
                 * <Action>Response or ErrorResponse types. Checking for
                 * other possible errors.
                 */

                log.debug("Caught JAXBException", je);
                log.debug("Response cannot be unmarshalled neither as " + actionName
                        + "Response or ErrorResponse types." + "Checking for other possible errors.");

                AmazonFPSException awse = processErrors(responseBodyString, status);

                throw awse;

            } catch (IOException ioe) {
                log.debug("Caught IOException exception", ioe);
                throw new AmazonFPSException("Internal Error", ioe);
            } catch (Exception e) {
                log.debug("Caught Exception", e);
                throw new AmazonFPSException(e);
            } finally {
                method.releaseConnection();
            }
        } while (shouldRetry);

    } catch (AmazonFPSException se) {
        log.debug("Caught AmazonFPSException", se);
        throw se;

    } catch (Throwable t) {
        log.debug("Caught Exception", t);
        throw new AmazonFPSException(t);
    }
    return response;
}

From source file:com.mirth.connect.connectors.http.HttpReceiver.java

private void sendErrorResponse(HttpServletResponse servletResponse, DispatchResult dispatchResult, Throwable t)
        throws IOException {
    String responseError = ExceptionUtils.getStackTrace(t);
    logger.error("Error receiving message (" + connectorProperties.getName() + " \"Source\" on channel "
            + getChannelId() + ").", t);
    eventController.dispatchEvent(new ErrorEvent(getChannelId(), getMetaDataId(), dispatchResult.getMessageId(),
            ErrorEventType.SOURCE_CONNECTOR, getSourceName(), connectorProperties.getName(),
            "Error receiving message", t));

    if (dispatchResult != null) {
        // TODO decide if we still want to send back the exception content or something else?
        dispatchResult.setAttemptedResponse(true);
        dispatchResult.setResponseError(responseError);
        // TODO get full HTTP payload with error message
        if (dispatchResult.getSelectedResponse() != null) {
            dispatchResult.getSelectedResponse().setMessage(responseError);
        }//from  w ww  .  j av a 2  s  .  c o  m
    }

    servletResponse.setContentType("text/plain");
    servletResponse.setStatus(HttpStatus.SC_INTERNAL_SERVER_ERROR);
    servletResponse.getOutputStream().write(responseError.getBytes());
}

From source file:davmail.http.DavGatewayHttpClientFacade.java

/**
 * Build Http Exception from methode status
 *
 * @param method Http Method//w  w  w  .  j a  v  a  2s . c om
 * @return Http Exception
 */
public static HttpException buildHttpException(HttpMethod method) {
    int status = method.getStatusCode();
    StringBuilder message = new StringBuilder();
    message.append(status).append(' ').append(method.getStatusText());
    try {
        message.append(" at ").append(method.getURI().getURI());
        if (method instanceof CopyMethod || method instanceof MoveMethod) {
            message.append(" to ").append(method.getRequestHeader("Destination"));
        }
    } catch (URIException e) {
        message.append(method.getPath());
    }
    // 440 means forbidden on Exchange
    if (status == 440) {
        return new LoginTimeoutException(message.toString());
    } else if (status == HttpStatus.SC_FORBIDDEN) {
        return new HttpForbiddenException(message.toString());
    } else if (status == HttpStatus.SC_NOT_FOUND) {
        return new HttpNotFoundException(message.toString());
    } else if (status == HttpStatus.SC_PRECONDITION_FAILED) {
        return new HttpPreconditionFailedException(message.toString());
    } else if (status == HttpStatus.SC_INTERNAL_SERVER_ERROR) {
        return new HttpServerErrorException(message.toString());
    } else {
        return new HttpException(message.toString());
    }
}