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:exception.handler.configuration.compatibility.ExceptionNotHandlerConfigTest.java

@Test
public void notHandlerConfiguration() throws HttpException, IOException {
    HttpClient client = new HttpClient();
    GetMethod method = new GetMethod(deploymentUrl + "/index.jsf");

    int status = client.executeMethod(method);
    assertEquals(HttpStatus.SC_INTERNAL_SERVER_ERROR, status);
}

From source file:com.owncloud.android.operations.RemoteOperationResult.java

private RemoteOperationResult(boolean success, int httpCode) {
    mSuccess = success;/*  ww  w  .  ja v  a2 s.c  o m*/
    mHttpCode = httpCode;

    if (success) {
        mCode = ResultCode.OK;

    } else if (httpCode > 0) {
        switch (httpCode) {
        case HttpStatus.SC_UNAUTHORIZED:
            mCode = ResultCode.UNAUTHORIZED;
            break;
        case HttpStatus.SC_NOT_FOUND:
            mCode = ResultCode.FILE_NOT_FOUND;
            break;
        case HttpStatus.SC_INTERNAL_SERVER_ERROR:
            mCode = ResultCode.INSTANCE_NOT_CONFIGURED;
            break;
        case HttpStatus.SC_CONFLICT:
            mCode = ResultCode.CONFLICT;
            break;
        case HttpStatus.SC_INSUFFICIENT_STORAGE:
            mCode = ResultCode.QUOTA_EXCEEDED;
            break;
        default:
            mCode = ResultCode.UNHANDLED_HTTP_CODE;
            Log_OC.d(TAG, "RemoteOperationResult has processed UNHANDLED_HTTP_CODE: " + httpCode);
        }
    }
}

From source file:com.owncloud.android.oc_framework.operations.RemoteOperationResult.java

private RemoteOperationResult(boolean success, int httpCode) {
    mSuccess = success;/*from ww  w.jav  a 2  s  .  c om*/
    mHttpCode = httpCode;

    if (success) {
        mCode = ResultCode.OK;

    } else if (httpCode > 0) {
        switch (httpCode) {
        case HttpStatus.SC_UNAUTHORIZED:
            mCode = ResultCode.UNAUTHORIZED;
            break;
        case HttpStatus.SC_NOT_FOUND:
            mCode = ResultCode.FILE_NOT_FOUND;
            break;
        case HttpStatus.SC_INTERNAL_SERVER_ERROR:
            mCode = ResultCode.INSTANCE_NOT_CONFIGURED;
            break;
        case HttpStatus.SC_CONFLICT:
            mCode = ResultCode.CONFLICT;
            break;
        case HttpStatus.SC_INSUFFICIENT_STORAGE:
            mCode = ResultCode.QUOTA_EXCEEDED;
            break;
        default:
            mCode = ResultCode.UNHANDLED_HTTP_CODE;
            Log.d(TAG, "RemoteOperationResult has processed UNHANDLED_HTTP_CODE: " + httpCode);
        }
    }
}

From source file:eu.alefzero.owncloud.authenticator.ConnectionCheckerRunnable.java

private boolean tryConnection(Uri uri) {
    WebdavClient wc = new WebdavClient();
    wc.allowSelfsignedCertificates();//from w  ww  .j  a  v a  2 s .c om
    GetMethod get = new GetMethod(uri.toString());
    boolean retval = false;
    try {
        int status = wc.executeMethod(get, TRY_CONNECTION_TIMEOUT);
        switch (status) {
        case HttpStatus.SC_OK: {
            String response = get.getResponseBodyAsString();
            JSONObject json = new JSONObject(response);
            if (!json.getBoolean("installed")) {
                mLatestResult = ResultType.INSTANCE_NOT_CONFIGURED;
                break;
            }
            mOCVersion = new OwnCloudVersion(json.getString("version"));
            if (!mOCVersion.isVersionValid())
                break;
            retval = true;
            break;
        }
        case HttpStatus.SC_NOT_FOUND:
            mLatestResult = ResultType.FILE_NOT_FOUND;
            break;
        case HttpStatus.SC_INTERNAL_SERVER_ERROR:
            mLatestResult = ResultType.INSTANCE_NOT_CONFIGURED;
            break;
        default:
            mLatestResult = ResultType.UNKNOWN_ERROR;
            Log.e(TAG, "Not handled status received from server: " + status);
        }

    } catch (Exception e) {
        if (e instanceof UnknownHostException || e instanceof ConnectException
                || e instanceof SocketTimeoutException) {
            mLatestResult = ResultType.HOST_NOT_AVAILABLE;
        } else if (e instanceof JSONException) {
            mLatestResult = ResultType.INSTANCE_NOT_CONFIGURED;
        } else if (e instanceof SSLHandshakeException) {
            mLatestResult = ResultType.SSL_INIT_ERROR;
        } else {
            mLatestResult = ResultType.UNKNOWN_ERROR;
        }
        e.printStackTrace();
    }

    return retval;
}

From source file:com.eviware.soapui.impl.rest.mock.RestMockDispatcherTest.java

@Test
public void returnsErrorOnrequestScriptException() throws Exception {
    Exception runTimeException = new IllegalStateException("wrong state");
    when(restMockService.runOnRequestScript(any(WsdlMockRunContext.class), any(MockRequest.class)))
            .thenThrow(runTimeException);

    restMockDispatcher.dispatchRequest(request, response);

    verify(response).setStatus(HttpStatus.SC_INTERNAL_SERVER_ERROR);
}

From source file:com.owncloud.android.authenticator.ConnectionCheckerRunnable.java

private boolean tryConnection(String urlSt) {
    boolean retval = false;
    GetMethod get = null;/*from w ww  .  j av  a2  s. c o  m*/
    try {
        WebdavClient wc = OwnCloudClientUtils.createOwnCloudClient(Uri.parse(urlSt));
        get = new GetMethod(urlSt);
        int status = wc.executeMethod(get, TRY_CONNECTION_TIMEOUT, TRY_CONNECTION_TIMEOUT);
        String response = get.getResponseBodyAsString();
        switch (status) {
        case HttpStatus.SC_OK: {
            JSONObject json = new JSONObject(response);
            if (!json.getBoolean("installed")) {
                mLatestResult = ResultType.INSTANCE_NOT_CONFIGURED;
                break;
            }
            mOCVersion = new OwnCloudVersion(json.getString("version"));
            if (!mOCVersion.isVersionValid()) {
                mLatestResult = ResultType.BAD_OC_VERSION;
                break;
            }
            retval = true;
            break;
        }
        case HttpStatus.SC_NOT_FOUND:
            mLatestResult = ResultType.FILE_NOT_FOUND;
            break;
        case HttpStatus.SC_INTERNAL_SERVER_ERROR:
            mLatestResult = ResultType.INSTANCE_NOT_CONFIGURED;
            break;
        default:
            mLatestResult = ResultType.UNKNOWN_ERROR;
            Log.e(TAG, "Not handled status received from server: " + status);
        }

    } catch (JSONException e) {
        mLatestResult = ResultType.INSTANCE_NOT_CONFIGURED;
        Log.e(TAG, "JSON exception while trying connection (instance not configured) ", e);

    } catch (SocketException e) {
        mLatestResult = ResultType.WRONG_CONNECTION;
        Log.e(TAG, "Socket exception while trying connection", e);

    } catch (SocketTimeoutException e) {
        mLatestResult = ResultType.TIMEOUT;
        Log.e(TAG, "Socket timeout exception while trying connection", e);

    } catch (MalformedURLException e) {
        mLatestResult = ResultType.INCORRECT_ADDRESS;
        Log.e(TAG, "Connect exception while trying connection", e);

    } catch (UnknownHostException e) {
        mLatestResult = ResultType.HOST_NOT_AVAILABLE;
        Log.e(TAG, "Unknown host exception while trying connection", e);

    } catch (SSLPeerUnverifiedException e) { // specially meaningful SSLException
        mLatestResult = ResultType.SSL_UNVERIFIED_SERVER;
        Log.e(TAG, "SSL Peer Unverified exception while trying connection", e);

    } catch (SSLException e) {
        mLatestResult = ResultType.SSL_INIT_ERROR;
        Log.e(TAG, "SSL exception while trying connection", e);

    } catch (ConnectTimeoutException e) { // timeout specific exception from org.apache.commons.httpclient
        mLatestResult = ResultType.TIMEOUT;
        Log.e(TAG, "Socket timeout exception while trying connection", e);

    } catch (HttpException e) { // other specific exceptions from org.apache.commons.httpclient
        mLatestResult = ResultType.UNKNOWN_ERROR;
        Log.e(TAG, "HTTP exception while trying connection", e);

    } catch (IOException e) { // UnkownsServiceException, and any other transport exceptions that could occur
        mLatestResult = ResultType.UNKNOWN_ERROR;
        Log.e(TAG, "I/O exception while trying connection", e);

    } catch (Exception e) {
        mLatestResult = ResultType.UNKNOWN_ERROR;
        Log.e(TAG, "Unexpected exception while trying connection", e);

    } finally {
        if (get != null)
            get.releaseConnection();
    }

    return retval;
}

From source file:com.cerema.cloud2.lib.common.operations.RemoteOperationResult.java

private RemoteOperationResult(boolean success, int httpCode) {
    mSuccess = success;/* w w  w  .  j a v  a2 s.  c  om*/
    mHttpCode = httpCode;

    if (success) {
        mCode = ResultCode.OK;

    } else if (httpCode > 0) {
        switch (httpCode) {
        case HttpStatus.SC_UNAUTHORIZED:
            mCode = ResultCode.UNAUTHORIZED;
            break;
        case HttpStatus.SC_NOT_FOUND:
            mCode = ResultCode.FILE_NOT_FOUND;
            break;
        case HttpStatus.SC_INTERNAL_SERVER_ERROR:
            mCode = ResultCode.INSTANCE_NOT_CONFIGURED;
            break;
        case HttpStatus.SC_CONFLICT:
            mCode = ResultCode.CONFLICT;
            break;
        case HttpStatus.SC_INSUFFICIENT_STORAGE:
            mCode = ResultCode.QUOTA_EXCEEDED;
            break;
        case HttpStatus.SC_FORBIDDEN:
            mCode = ResultCode.FORBIDDEN;
            break;
        default:
            mCode = ResultCode.UNHANDLED_HTTP_CODE;
            Log_OC.d(TAG, "RemoteOperationResult has processed UNHANDLED_HTTP_CODE: " + httpCode);
        }
    }
}

From source file:ke.go.moh.oec.adt.Daemon.java

private static boolean sendMessage(String url, String filename) {
    int returnStatus = HttpStatus.SC_CREATED;
    HttpClient httpclient = new HttpClient();
    HttpConnectionManager connectionManager = httpclient.getHttpConnectionManager();
    connectionManager.getParams().setSoTimeout(120000);

    PostMethod httpPost = new PostMethod(url);

    RequestEntity requestEntity;//  w  w w . j ava 2 s  .co m
    try {
        FileInputStream message = new FileInputStream(filename);
        Base64InputStream message64 = new Base64InputStream(message, true, -1, null);
        requestEntity = new InputStreamRequestEntity(message64, "application/octet-stream");
    } catch (FileNotFoundException e) {
        Logger.getLogger(Daemon.class.getName()).log(Level.SEVERE, "File not found.", e);
        return false;
    }
    httpPost.setRequestEntity(requestEntity);
    try {
        httpclient.executeMethod(httpPost);
        returnStatus = httpPost.getStatusCode();
    } catch (SocketTimeoutException e) {
        returnStatus = HttpStatus.SC_REQUEST_TIMEOUT;
        Logger.getLogger(Daemon.class.getName()).log(Level.SEVERE, "Request timed out.  Not retrying.", e);
    } catch (HttpException e) {
        returnStatus = HttpStatus.SC_INTERNAL_SERVER_ERROR;
        Logger.getLogger(Daemon.class.getName()).log(Level.SEVERE, "HTTP exception.  Not retrying.", e);
    } catch (ConnectException e) {
        returnStatus = HttpStatus.SC_SERVICE_UNAVAILABLE;
        Logger.getLogger(Daemon.class.getName()).log(Level.SEVERE, "Service unavailable.  Not retrying.", e);
    } catch (UnknownHostException e) {
        returnStatus = HttpStatus.SC_NOT_FOUND;
        Logger.getLogger(Daemon.class.getName()).log(Level.SEVERE, "Not found.  Not retrying.", e);
    } catch (IOException e) {
        returnStatus = HttpStatus.SC_GATEWAY_TIMEOUT;
        Logger.getLogger(Daemon.class.getName()).log(Level.SEVERE, "IO exception.  Not retrying.", e);
    } finally {
        httpPost.releaseConnection();
    }
    return returnStatus == HttpStatus.SC_OK;
}

From source file:com.thoughtworks.go.server.service.PipelinePauseServiceTest.java

@Test
public void shouldPopulateHttpResult500WhenPipelinePauseResultsInAnError() throws Exception {

    setUpValidPipelineWithAuth();/*from  w w w .  j av a 2 s  .c o  m*/

    HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();

    doThrow(new RuntimeException("Failed to pause")).when(pipelineDao).pause(VALID_PIPELINE, "cause",
            VALID_USER.getUsername().toString());

    pipelinePauseService.pause(VALID_PIPELINE, "cause", VALID_USER, result);

    assertThat(result.isSuccessful(), is(false));
    assertThat(result.httpCode(), is(HttpStatus.SC_INTERNAL_SERVER_ERROR));

    verify(pipelineDao).pause(VALID_PIPELINE, "cause", VALID_USER.getUsername().toString());
}

From source file:com.bigdata.rdf.sail.remoting.GraphRepositoryServlet.java

/**
 * Perform an HTTP GET, which corresponds to the basic CRUD operation "read"
 * according to the generic interaction semantics of HTTP REST.
 * <p>//from   w  ww . ja  va  2s.  com
 * <ul>
 * <li>BODY ignored for READ</li> 
 * <li>no RANGE retrieves the entire graph</li> 
 * <li>RANGE(&lt;query language&gt;[&lt;query&gt;]) performs a query</li>
 * </ul>
 */
protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {

    String range = request.getHeader(HTTP_RANGE);
    boolean includeInferred = Boolean.valueOf(request.getHeader(X_INCLUDE_INFERRED));

    if (log.isInfoEnabled()) {
        log.info("doGet: " + range);
    }

    try {

        // set the content type and the _encoding_
        response.setContentType(RDF_XML);

        // obtain the writer -- it will use the specified encoding.
        PrintWriter out = response.getWriter();
        String query = null;
        QueryLanguage ql = null;
        int status = 0;
        if (range == null || range.length() == 0) {
            // proper semantics are to provide the entire graph, per above
            status = HttpStatus.SC_OK;
        } else {
            // sparql[select ...]
            final int i = range.indexOf('[');
            ql = QueryLanguage.valueOf(range.substring(0, i));
            if (ql == null) {
                throw new RuntimeException("unrecognized query language: " + range);
            }
            query = range.substring(i + 1, range.length() - 1);
            /*
             MetadataRepositoryHelper.doQuery(graph, query, ql,
             includeInferred);
             */
            status = HttpStatus.SC_PARTIAL_CONTENT;
        }

        String results = read(query, ql, includeInferred);
        out.print(results);
        out.flush();
        response.setStatus(status);

    } catch (Exception ex) {
        ex.printStackTrace();
        response.sendError(HttpStatus.SC_INTERNAL_SERVER_ERROR, ex.getMessage());
    }

}