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:org.apache.axis2.mtom.EchoRawMTOMFaultReportTest.java

public void testEchoFaultSync() throws Exception {
    HttpClient client = new HttpClient();

    PostMethod httppost = new PostMethod(
            "http://127.0.0.1:" + (UtilServer.TESTING_PORT) + "/axis2/services/EchoService/mtomSample");

    HttpMethodRetryHandler myretryhandler = new HttpMethodRetryHandler() {
        public boolean retryMethod(final HttpMethod method, final IOException exception, int executionCount) {
            if (executionCount >= 10) {
                return false;
            }/* w w w.  j a v  a 2 s .c  o  m*/
            if (exception instanceof NoHttpResponseException) {
                return true;
            }
            if (!method.isRequestSent()) {
                return true;
            }
            // otherwise do not retry
            return false;
        }
    };
    httppost.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, myretryhandler);
    httppost.setRequestEntity(new InputStreamRequestEntity(
            new FileInputStream(TestingUtils.prefixBaseDirectory("test-resources/mtom/wmtom.bin"))));

    httppost.setRequestHeader("Content-Type",
            "multipart/related; boundary=--MIMEBoundary258DE2D105298B756D; type=\"application/xop+xml\"; start=\"<0.15B50EF49317518B01@apache.org>\"; start-info=\"application/soap+xml\"");
    try {
        client.executeMethod(httppost);

        if (httppost.getStatusCode() == HttpStatus.SC_INTERNAL_SERVER_ERROR) {

            // TODO: There is a missing wsa:Action header in the SOAP message.  Fix or look for correct fault text!

            //                assertEquals("HTTP/1.1 500 Internal server error",
            //                             httppost.getStatusLine().toString());
        }
    } catch (NoHttpResponseException e) {
    } finally {
        httppost.releaseConnection();
    }
}

From source file:org.apache.axis2.transport.http.HTTPSender.java

/**
 * Used to handle the HTTP Response/*from  w  w  w  . j  a  v a  2s .c om*/
 *
 * @param msgContext - The MessageContext of the message
 * @param method     - The HTTP method used
 * @throws IOException - Thrown in case an exception occurs
 */
private void handleResponse(MessageContext msgContext, HttpMethodBase method) throws IOException {
    int statusCode = method.getStatusCode();
    HTTPStatusCodeFamily family = getHTTPStatusCodeFamily(statusCode);
    log.trace("Handling response - " + statusCode);
    Set<Integer> nonErrorCodes = (Set<Integer>) msgContext
            .getProperty(HTTPConstants.NON_ERROR_HTTP_STATUS_CODES);
    Set<Integer> errorCodes = new HashSet<Integer>();
    String strRetryErrorCodes = (String) msgContext.getProperty(HTTPConstants.ERROR_HTTP_STATUS_CODES); // Fixing
    // ESBJAVA-3178
    if (strRetryErrorCodes != null && !strRetryErrorCodes.trim().equals("")) {
        for (String strRetryErrorCode : strRetryErrorCodes.split(",")) {
            try {
                errorCodes.add(Integer.valueOf(strRetryErrorCode));
            } catch (NumberFormatException e) {
                log.warn(strRetryErrorCode + " is not a valid status code");
            }
        }
    }
    if (statusCode == HttpStatus.SC_ACCEPTED) {
        /* When an HTTP 202 Accepted code has been received, this will be the case of an execution 
         * of an in-only operation. In such a scenario, the HTTP response headers should be returned,
         * i.e. session cookies. */
        obtainHTTPHeaderInformation(method, msgContext);
        // Since we don't expect any content with a 202 response, we must release the connection
        method.releaseConnection();
    } else if (HTTPStatusCodeFamily.SUCCESSFUL.equals(family)) {
        // Save the HttpMethod so that we can release the connection when cleaning up
        msgContext.setProperty(HTTPConstants.HTTP_METHOD, method);
        processResponse(method, msgContext);
    } else if (!errorCodes.contains(statusCode) && (statusCode == HttpStatus.SC_INTERNAL_SERVER_ERROR
            || statusCode == HttpStatus.SC_BAD_REQUEST || statusCode == HttpStatus.SC_CONFLICT)) {
        // Save the HttpMethod so that we can release the connection when cleaning up
        msgContext.setProperty(HTTPConstants.HTTP_METHOD, method);
        Header contenttypeHeader = method.getResponseHeader(HTTPConstants.HEADER_CONTENT_TYPE);
        String value = null;
        if (contenttypeHeader != null) {
            value = contenttypeHeader.getValue();
        }
        OperationContext opContext = msgContext.getOperationContext();
        if (opContext != null) {
            MessageContext inMessageContext = opContext.getMessageContext(WSDLConstants.MESSAGE_LABEL_IN_VALUE);
            if (inMessageContext != null) {
                inMessageContext.setProcessingFault(true);
            }
        }
        if (value != null) {

            processResponse(method, msgContext);
        }

        if (org.apache.axis2.util.Utils.isClientThreadNonBlockingPropertySet(msgContext)) {
            throw new AxisFault(
                    Messages.getMessage("transportError", String.valueOf(statusCode), method.getStatusText()));
        }
    } else if (nonErrorCodes != null && nonErrorCodes.contains(statusCode)) {
        msgContext.setProperty(HTTPConstants.HTTP_METHOD, method);
        processResponse(method, msgContext);
        return;
    } else {
        // Since we don't process the response, we must release the connection immediately
        method.releaseConnection();
        throw new AxisFault(
                Messages.getMessage("transportError", String.valueOf(statusCode), method.getStatusText()));
    }
}

From source file:org.apache.axis2.transport.http.impl.httpclient3.HTTPSenderImpl.java

/**
 * Used to handle the HTTP Response/*from w w w.j a v a2  s. c om*/
 * 
 * @param msgContext
 *            - The MessageContext of the message
 * @param method
 *            - The HTTP method used
 * @throws IOException
 *             - Thrown in case an exception occurs
 */
protected void handleResponse(MessageContext msgContext, Object httpMethodBase) throws IOException {
    HttpMethodBase method;
    if (httpMethodBase instanceof HttpMethodBase) {
        method = (HttpMethodBase) httpMethodBase;
    } else {
        log.trace("HttpMethodBase expected, but found - " + httpMethodBase);
        return;
    }
    int statusCode = method.getStatusCode();
    HTTPStatusCodeFamily family = getHTTPStatusCodeFamily(statusCode);
    log.trace("Handling response - " + statusCode);
    if (statusCode == HttpStatus.SC_ACCEPTED) {
        /* When an HTTP 202 Accepted code has been received, this will be the case of an execution 
         * of an in-only operation. In such a scenario, the HTTP response headers should be returned,
         * i.e. session cookies. */
        obtainHTTPHeaderInformation(method, msgContext);
        // Since we don't expect any content with a 202 response, we must release the connection
        method.releaseConnection();
    } else if (HTTPStatusCodeFamily.SUCCESSFUL.equals(family)) {
        // Save the HttpMethod so that we can release the connection when cleaning up
        msgContext.setProperty(HTTPConstants.HTTP_METHOD, method);
        processResponse(method, msgContext);
    } else if (statusCode == HttpStatus.SC_INTERNAL_SERVER_ERROR || statusCode == HttpStatus.SC_BAD_REQUEST) {
        // Save the HttpMethod so that we can release the connection when
        // cleaning up
        msgContext.setProperty(HTTPConstants.HTTP_METHOD, method);
        Header contenttypeHeader = method.getResponseHeader(HTTPConstants.HEADER_CONTENT_TYPE);
        String value = null;
        if (contenttypeHeader != null) {
            value = contenttypeHeader.getValue();
        }
        OperationContext opContext = msgContext.getOperationContext();
        if (opContext != null) {
            MessageContext inMessageContext = opContext.getMessageContext(WSDLConstants.MESSAGE_LABEL_IN_VALUE);
            if (inMessageContext != null) {
                inMessageContext.setProcessingFault(true);
            }
        }
        if (value != null) {

            processResponse(method, msgContext);
        }

        if (org.apache.axis2.util.Utils.isClientThreadNonBlockingPropertySet(msgContext)) {
            throw new AxisFault(
                    Messages.getMessage("transportError", String.valueOf(statusCode), method.getStatusText()));
        }
    } else {
        // Since we don't process the response, we must release the
        // connection immediately
        method.releaseConnection();
        throw new AxisFault(
                Messages.getMessage("transportError", String.valueOf(statusCode), method.getStatusText()));
    }
}

From source file:org.apache.falcon.regression.lineage.LineageApiTest.java

/**
 * Negative test - get a vertex without specifying id, we should not get internal server error.
 * @throws Exception//w w w . j a v a 2  s  . c o  m
 */
@Test
public void testVertexNoId() throws Exception {
    HttpResponse response = lineageHelper.runGetRequest(lineageHelper.getUrl(LineageHelper.URL.VERTICES, ""));
    String responseString = lineageHelper.getResponseString(response);
    LOGGER.info("response: " + response);
    LOGGER.info("responseString: " + responseString);
    Assert.assertNotEquals(response.getStatusLine().getStatusCode(), HttpStatus.SC_INTERNAL_SERVER_ERROR,
            "We should not get internal server error");
}

From source file:org.apache.synapse.mediators.json.SynapseJsonSender.java

public InvocationResponse invoke(MessageContext msgContext) throws AxisFault {
    //Fix Me For Sending Only
    // Trasnport URL can be different from the WSA-To. So processing
    // that now./* w  w  w .ja va2s  .  com*/
    EndpointReference epr = null;
    String transportURL = (String) msgContext.getProperty(Constants.Configuration.TRANSPORT_URL);

    if (transportURL != null) {
        epr = new EndpointReference(transportURL);
    } else if ((msgContext.getTo() != null)
            && !AddressingConstants.Submission.WSA_ANONYMOUS_URL.equals(msgContext.getTo().getAddress())
            && !AddressingConstants.Final.WSA_ANONYMOUS_URL.equals(msgContext.getTo().getAddress())) {
        epr = msgContext.getTo();
    }

    if (epr == null) {
        throw new AxisFault("EndpointReference is not available");
    }

    // Get the JSONObject
    JSONObject jsonObject = (JSONObject) msgContext.getProperty("JSONObject");
    if (jsonObject == null) {
        throw new AxisFault("Couldn't Find JSONObject");

    }
    HttpClient agent = new HttpClient();
    PostMethod postMethod = new PostMethod(epr.getAddress());
    try {
        postMethod.setRequestEntity(new ByteArrayRequestEntity(XML.toString(jsonObject).getBytes()));
        agent.executeMethod(postMethod);

        if (postMethod.getStatusCode() == HttpStatus.SC_OK) {
            processResponse(postMethod, msgContext);
        } else if (postMethod.getStatusCode() == HttpStatus.SC_ACCEPTED) {
        } else if (postMethod.getStatusCode() == HttpStatus.SC_INTERNAL_SERVER_ERROR) {
            Header contenttypeHheader = postMethod.getResponseHeader(HTTPConstants.HEADER_CONTENT_TYPE);
            String value = contenttypeHheader.getValue();

            if (value != null) {
                if ((value.indexOf(SOAP11Constants.SOAP_11_CONTENT_TYPE) >= 0)
                        || (value.indexOf(SOAP12Constants.SOAP_12_CONTENT_TYPE) >= 0)) {
                    processResponse(postMethod, msgContext);
                }
            }
        } else {
            throw new AxisFault(Messages.getMessage("transportError",
                    String.valueOf(postMethod.getStatusCode()), postMethod.getResponseBodyAsString()));
        }
    } catch (JSONException e) {
        log.error(e);
        throw new AxisFault(e);
    } catch (IOException e) {
        log.error(e);
        throw new AxisFault(e);
    }

    return InvocationResponse.CONTINUE;
}

From source file:org.apromore.common.converters.xpdl.servlet.XPDLImportServlet.java

@Override
protected void doPost(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
    String data = req.getParameter("data");

    try {/*from  ww w .  j  a  v  a  2s .  c  o  m*/
        XPDLToJSONConverter converter = new XPDLToJSONConverter();
        XPDLPackage xpdlModel = converter.getXPDLModel(data);

        res.setStatus(HttpStatus.SC_OK);
        res.setContentType("application/json");
        res.getWriter().print(converter.getXPDL(xpdlModel));
        res.getWriter().flush();
        res.getWriter().close();
    } catch (Exception e) {
        res.setStatus(HttpStatus.SC_INTERNAL_SERVER_ERROR);
        res.setContentType("application/json");
        res.getWriter().write("{success: false, data: \"" + e.getMessage() + "\"}");
    }
}

From source file:org.artifactory.request.ResponseStatusCodesMapper.java

public int getStatusCode(Throwable e) {
    if (e instanceof BadPomException) {
        return HttpStatus.SC_CONFLICT;
    } else if (e instanceof DoesNotExistException) {
        return HttpStatus.SC_NOT_FOUND;
    } else if (e instanceof ItemNotFoundRuntimeException) {
        return HttpStatus.SC_BAD_REQUEST;
    } else if (e instanceof RepoRejectException) {
        return ((RepoRejectException) e).getErrorCode();
    } else if (e instanceof IllegalArgumentException) {
        return HttpStatus.SC_BAD_REQUEST;
    }//from  www  . j a  va  2  s.co m

    return HttpStatus.SC_INTERNAL_SERVER_ERROR;
}

From source file:org.artifactory.request.ResponseWithStatusHolderMapper.java

@Override
public int getStatusCode(Throwable e) {
    int statusCode = statusHolder.getStatusCode();
    if (statusCode != HttpStatus.SC_INTERNAL_SERVER_ERROR) {
        return statusCode;
    }/*from  ww  w .ja  v  a2s  .  co  m*/

    return super.getStatusCode(e);
}

From source file:org.artifactory.rest.resource.system.ExportResource.java

@POST
@Path(ImportRestConstants.SYSTEM_PATH)
@Consumes({ SystemRestConstants.MT_EXPORT_SETTINGS, MediaType.APPLICATION_JSON })
public Response activateExport(ExportSettingsConfigurationImpl settings) {
    StreamStatusHolder holder = new StreamStatusHolder(httpResponse);
    ExportSettingsImpl exportSettings = new ExportSettingsImpl(new File(settings.getExportPath()), holder);
    exportSettings.setIncludeMetadata(settings.isIncludeMetadata());
    exportSettings.setCreateArchive(settings.isCreateArchive());
    exportSettings.setIgnoreRepositoryFilteringRulesOn(settings.isBypassFiltering());
    exportSettings.setVerbose(settings.isVerbose());
    exportSettings.setFailFast(settings.isFailOnError());
    exportSettings.setFailIfEmpty(settings.isFailIfEmpty());
    exportSettings.setM2Compatible(settings.isM2());
    exportSettings.setIncremental(settings.isIncremental());
    exportSettings.setExcludeContent(settings.isExcludeContent());

    if (settings.isIncludeMetadata() || !settings.isExcludeContent()) {
        exportSettings.setRepositories(getAllLocalRepoKeys());
    }//  ww w.j a  v a2s  .  c o  m
    log.debug("Activating export {}", settings);
    try {
        ContextHelper.get().exportTo(exportSettings);
        if (!httpResponse.isCommitted() && holder.isError()) {
            return Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR)
                    .entity("Export finished with errors. Check " + "Artifactory logs for more details.")
                    .build();
        }
    } catch (Exception e) {
        if (!httpResponse.isCommitted()) {
            return Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR).entity(e.getMessage()).build();
        }
    }
    return Response.ok().build();
}

From source file:org.artifactory.rest.resource.system.PingResource.java

/**
 * @return The artifactory state "OK" or "Failure"
 *///  www  .j  av  a  2 s  .c o m
@GET
@Produces({ MediaType.TEXT_PLAIN })
public Response pingArtifactory() {
    try {
        log.debug("Received ping call");
        // Check that addons are OK if needed
        if (addonsManager.lockdown()) {
            log.error("Ping failed due to unloaded addons");
            return Response.status(HttpStatus.SC_FORBIDDEN).entity("Addons unloaded").build();
        }
        ArtifactoryHome artifactoryHome = ArtifactoryHome.get();
        if (!artifactoryHome.getDataDir().canWrite() || !artifactoryHome.getLogDir().canWrite()) {
            log.error("Ping failed due to file system access to data or log dir failed");
            return Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR).entity("File system access failed")
                    .build();
        }
        ContextHelper.get().beanForType(StorageService.class).ping();
    } catch (Exception e) {
        log.error("Error during ping test", e);
        return Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR).entity(e.getMessage()).build();
    }
    log.debug("Ping successful");
    return Response.ok().entity("OK").build();
}