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:com.alibaba.ims.web.valve.ExceptionValve.java

@Override
public void invoke(PipelineContext pipelineContext) throws Exception {
    try {/*from  w  w  w  . j a  v  a2s.c o m*/
        pipelineContext.invokeNext();
    } catch (Exception e) {
        response.setStatus(HttpStatus.SC_INTERNAL_SERVER_ERROR);
        logger.error(e.getMessage(), e);
        try {
            Throwable cause = e.getCause().getCause().getCause();
            if (cause instanceof WebException) {
                response.getWriter().write(((WebException) cause).getMessage());
            } else {
                response.getWriter().write(ExceptionCode.Common.INNER_ERROR);
            }
        } catch (NullPointerException ne) {
            response.getWriter().write(ExceptionCode.Common.INNER_ERROR);
        }
    }
}

From source file:es.carebear.rightmanagement.client.group.AddUserToGroup.java

public void AddUser(String executing, String target, String group)
        throws BadRequestException, InternalServerErrorException, IOException, UnknownResponseException {
    PostMethod postMethod = new PostMethod(baseUri + "/client/groups/add/" + target + "/" + group);
    postMethod.addParameter("authName", executing);
    int responseCode = httpClient.executeMethod(postMethod);

    switch (responseCode) {
    case HttpStatus.SC_OK:
        break;// ww w .j a v a2 s.c o m
    case HttpStatus.SC_BAD_REQUEST:
        throw new BadRequestException();
    case HttpStatus.SC_INTERNAL_SERVER_ERROR:
        throw new InternalServerErrorException();
    case HttpStatus.SC_FORBIDDEN:
        throw new ForbiddenException();
    default:
        throw new UnknownResponseException((new Integer(responseCode)).toString());
    }
}

From source file:es.carebear.rightmanagement.client.user.RegisterUser.java

public User register(String username, String password) throws BadRequestException, InternalServerErrorException,
        IOException, UnauthorizedException, UnknownResponseException {
    PostMethod postMethod = new PostMethod(baseUri + "/client/users/register/" + username);
    postMethod.addParameter("password", password);
    int responseCode = httpClient.executeMethod(postMethod);

    switch (responseCode) {
    case HttpStatus.SC_CREATED:
        String response = postMethod.getResponseBodyAsString();
        return XMLHelper.fromXML(response, User.class);
    case HttpStatus.SC_BAD_REQUEST:
        throw new BadRequestException();
    case HttpStatus.SC_INTERNAL_SERVER_ERROR:
        throw new InternalServerErrorException();
    default://from  w w  w .  ja  va  2  s  .c  o  m
        throw new UnknownResponseException((new Integer(responseCode)).toString());
    }
}

From source file:costumetrade.common.http.HttpWorker.java

@Override
public void onReceive(Object msg) throws Exception {

    HttpMessage message = (HttpMessage) msg;
    try {/*from  w  w w  .j a v  a2s .  c o  m*/
        HttpResponse httpResponse = this.sendRequest(message);
        returnMessage(httpResponse);
    } catch (NoHttpResponseException | ConnectTimeoutException | SocketTimeoutException e) {
        if (message.needRetry()) {
            logger.info(",????,url:{}", message.getUrl());
            returnMessage(
                    new HttpResponse(HttpStatus.SC_INTERNAL_SERVER_ERROR, null, message.getCallbackData()));
            return;
        }
        message.retry();
        scheduler.scheduleOnce(Duration.create(message.getInterval(), TimeUnit.SECONDS), getSelf(), message,
                dispatcher, getSender());
    } catch (Exception e) {
        logger.error("", e);
        returnMessage(new HttpResponse(HttpStatus.SC_INTERNAL_SERVER_ERROR, null, message.getCallbackData()));
    }
}

From source file:es.carebear.rightmanagement.client.user.AddAllowedUserId.java

public void AddUser(String authName, String target, String rightMask) throws BadRequestException,
        InternalServerErrorException, IOException, UnknownResponseException, UnauthorizedException {
    PostMethod postMethod = new PostMethod(baseUri + "/client/users/change/allowed");
    postMethod.addParameter("authName", authName);
    postMethod.addParameter("target", target);
    postMethod.addParameter("rightMask", rightMask);
    int responseCode = httpClient.executeMethod(postMethod);

    switch (responseCode) {
    case HttpStatus.SC_OK:
        break;/*from  w ww. jav a  2  s. c  om*/
    case HttpStatus.SC_BAD_REQUEST:
        throw new BadRequestException();
    case HttpStatus.SC_INTERNAL_SERVER_ERROR:
        throw new InternalServerErrorException();
    case HttpStatus.SC_UNAUTHORIZED:
        throw new UnauthorizedException();
    case HttpStatus.SC_FORBIDDEN:
        throw new ForbiddenException();
    default:
        throw new UnknownResponseException((new Integer(responseCode)).toString());
    }
}

From source file:com.temenos.interaction.media.odata.xml.error.RuntimeExceptionHandler.java

@Override
public Response toResponse(RuntimeException exception) {
    int code = HttpStatus.SC_INTERNAL_SERVER_ERROR;
    String stackTrace = generateLogMessage(exception, code);
    EntityResource<?> er = CommandHelper
            .createEntityResource(new GenericError(Integer.toString(code), stackTrace), GenericError.class);
    return Response.serverError().entity(er.getGenericEntity()).build();
}

From source file:es.carebear.rightmanagement.client.user.ChangeAttributeUser.java

public void ChangeAttribute(String userName, String authName, String[] attribute, String[] value)
        throws BadRequestException, InternalServerErrorException, IOException, UnknownResponseException {
    Gson gson = new Gson();
    String attr = gson.toJson(attribute, attribute.getClass());
    String val = gson.toJson(value, value.getClass());

    PostMethod postMethod = new PostMethod(baseUri + "/client/users/change/" + userName);
    postMethod.addParameter("authName", authName);
    postMethod.addParameter("attribute", attr);
    postMethod.addParameter("value", val);

    int responseCode = httpClient.executeMethod(postMethod);

    switch (responseCode) {
    case HttpStatus.SC_OK:
        break;/*ww  w.j  a v a2 s. c  o m*/
    case HttpStatus.SC_BAD_REQUEST:
        throw new BadRequestException();
    case HttpStatus.SC_INTERNAL_SERVER_ERROR:
        throw new InternalServerErrorException();
    case HttpStatus.SC_FORBIDDEN:
        throw new ForbiddenException();
    default:
        throw new UnknownResponseException((new Integer(responseCode)).toString());
    }
}

From source file:atg.taglib.json.Helper.java

/**
 * Get a response from the server for a test
 *
 * @param pTestUrl The test url, relative to the tests context root
 * @return the <code>ResponseData</code> object for this test
 * @throws IOException /*from  w  w  w .  jav a 2s.c  o m*/
 * @throws HttpException 
 * @throws JSONException 
 */
public static ResponseData getData(String pType, int pTestNum)
        throws HttpException, IOException, JSONException {
    // Setup HTTP client
    HttpClient client = new HttpClient();
    HttpMethod method = new GetMethod(getTestUrl(pType, pTestNum));

    // Execute the GET request, capturing response status
    int statusCode = client.executeMethod(method);
    String responseBody = method.getResponseBodyAsString();
    method.releaseConnection();

    // Create response data object
    ResponseData data = new ResponseData();
    data.body = responseBody.trim();
    data.statusCode = statusCode;
    if (statusCode == HttpStatus.SC_OK) {
        // Parse the JSON response
        data.json = parseJsonTextToObject(responseBody);
    }

    // Get the expected result
    method = new GetMethod(getStatus200ResultUrl(pType, pTestNum));
    data.expectedStatusCode = HttpStatus.SC_OK;

    // Execute the GET request, capturing response status
    statusCode = client.executeMethod(method);

    if (statusCode == HttpStatus.SC_NOT_FOUND) {
        // Test result wasn't found - we must be expecting an error for this test
        method.releaseConnection();
        method = new GetMethod(getStatus500ResultUrl(pType, pTestNum));
        statusCode = client.executeMethod(method);
        data.expectedStatusCode = HttpStatus.SC_INTERNAL_SERVER_ERROR;
    }

    responseBody = method.getResponseBodyAsString().trim();
    method.releaseConnection();

    // Parse the expected data   
    if (data.expectedStatusCode == HttpStatus.SC_OK) {
        // Parse body into JSON object
        data.expectedJson = parseJsonTextToObject(responseBody);
    } else {
        // Exception is expected, set the expected key
        data.expectedMsgKey = responseBody.trim();
    }

    return data;
}

From source file:edu.unc.lib.dl.cdr.sword.server.servlets.ContainerServlet.java

@RequestMapping(value = { "/{pid}", "/{pid}/*" }, method = RequestMethod.DELETE)
public void deleteContainer(HttpServletRequest req, HttpServletResponse resp) {
    try {/*  w  ww  . j  av a 2  s .co m*/
        this.api.delete(req, resp);
    } catch (Exception e) {
        log.error("Failed to delete container " + req.getQueryString(), e);
        resp.setStatus(HttpStatus.SC_INTERNAL_SERVER_ERROR);
    }
}

From source file:com.sappenin.eaut.consumer.mappingservice.MappingServiceClientImpl.java

/**
 * This function communicates with an EAUT Mapping service via an HTTP get,
 * provides the service an email address, and return the resulting URL, if
 * found.//ww  w .j  a v a 2  s.  c  o m
 * 
 * @param pae
 * @return The URL that the specified Mapping Service indicates is the URL
 *         of the specified email address.
 * @throws EAUTException
 */
@Override
public String queryMappingService(ParsedEmailAddress pae, String getUrl) throws EAUTException {
    HttpClient client = new HttpClient();
    GetMethod get = new GetMethod(getUrl);
    get.setFollowRedirects(true);

    if (log.isDebugEnabled())
        log.debug("Performing HTTP GET on: " + getUrl + " ...");

    int statusCode;
    try {
        statusCode = client.executeMethod(get);
        if (statusCode != HttpStatus.SC_OK) {
            if (statusCode == HttpStatus.SC_BAD_REQUEST)
                throw new EAUTException("The Email Identifier supplied by '" + getUrl
                        + "' is not properly formatted per the EAUT spec and/or RFC2822 (Http Error 400)");
            else if (statusCode == HttpStatus.SC_INTERNAL_SERVER_ERROR)
                throw new EAUTException(
                        "The EAUT Mapping Service was unable to complete a mapping request for URL: '" + getUrl
                                + "'.  Please try this request again at a later time.  (Http Error 500)");
            else
                throw new EAUTException("GET failed on " + getUrl + "(Http Error " + statusCode + ")");
        } else {
            String redirectLocation = get.getURI().toString();
            if (redirectLocation != null) {
                return redirectLocation;
            } else {
                // The response is invalid and did not provide the new
                // location
                // for the resource. Report an error or possibly handle the
                // response like a 404 Not Found error.
                throw new EAUTException("GET failed on " + getUrl + "(Http Error " + statusCode + ")");
            }

        }
    } catch (EAUTException ee) {
        throw ee;
    } catch (HttpException he) {
        throw new EAUTException(he);
    } catch (IOException ioe) {
        throw new EAUTException(ioe);
    }
}