Search in sources :

Example 6 with MethodNotSupportedException

use of org.apache.http.MethodNotSupportedException in project openhab1-addons by openhab.

the class StreamClientImpl method sendRequest.

@Override
public StreamResponseMessage sendRequest(StreamRequestMessage requestMessage) {
    final UpnpRequest requestOperation = requestMessage.getOperation();
    log.fine("Preparing HTTP request message with method '" + requestOperation.getHttpMethodName() + "': " + requestMessage);
    try {
        // Create the right HTTP request
        HttpUriRequest httpRequest = createHttpRequest(requestMessage, requestOperation);
        // Set all the headers on the request
        httpRequest.setParams(getRequestParams(requestMessage));
        HeaderUtil.add(httpRequest, requestMessage.getHeaders());
        log.fine("Sending HTTP request: " + httpRequest.getURI());
        return httpClient.execute(httpRequest, createResponseHandler());
    } catch (MethodNotSupportedException ex) {
        log.warning("Request aborted: " + ex.toString());
        return null;
    } catch (ClientProtocolException ex) {
        log.warning("HTTP protocol exception executing request: " + requestMessage);
        log.warning("Cause: " + Exceptions.unwrap(ex));
        return null;
    } catch (IOException ex) {
        // Don't log stacktrace
        log.fine("Client connection was aborted: " + ex.getMessage());
        return null;
    }
}
Also used : HttpUriRequest(org.apache.http.client.methods.HttpUriRequest) UpnpRequest(org.teleal.cling.model.message.UpnpRequest) MethodNotSupportedException(org.apache.http.MethodNotSupportedException) IOException(java.io.IOException) ClientProtocolException(org.apache.http.client.ClientProtocolException)

Example 7 with MethodNotSupportedException

use of org.apache.http.MethodNotSupportedException in project platform_external_apache-http by android.

the class HttpService method handleException.

protected void handleException(final HttpException ex, final HttpResponse response) {
    if (ex instanceof MethodNotSupportedException) {
        response.setStatusCode(HttpStatus.SC_NOT_IMPLEMENTED);
    } else if (ex instanceof UnsupportedHttpVersionException) {
        response.setStatusCode(HttpStatus.SC_HTTP_VERSION_NOT_SUPPORTED);
    } else if (ex instanceof ProtocolException) {
        response.setStatusCode(HttpStatus.SC_BAD_REQUEST);
    } else {
        response.setStatusCode(HttpStatus.SC_INTERNAL_SERVER_ERROR);
    }
    byte[] msg = EncodingUtils.getAsciiBytes(ex.getMessage());
    ByteArrayEntity entity = new ByteArrayEntity(msg);
    entity.setContentType("text/plain; charset=US-ASCII");
    response.setEntity(entity);
}
Also used : ProtocolException(org.apache.http.ProtocolException) ByteArrayEntity(org.apache.http.entity.ByteArrayEntity) MethodNotSupportedException(org.apache.http.MethodNotSupportedException) UnsupportedHttpVersionException(org.apache.http.UnsupportedHttpVersionException)

Aggregations

MethodNotSupportedException (org.apache.http.MethodNotSupportedException)7 ByteArrayEntity (org.apache.http.entity.ByteArrayEntity)4 IOException (java.io.IOException)3 ProtocolException (org.apache.http.ProtocolException)3 UnsupportedHttpVersionException (org.apache.http.UnsupportedHttpVersionException)3 SenderException (nl.nn.adapterframework.core.SenderException)2 TimeOutException (nl.nn.adapterframework.core.TimeOutException)2 ClientProtocolException (org.apache.http.client.ClientProtocolException)2 HttpGet (org.apache.http.client.methods.HttpGet)2 HttpPost (org.apache.http.client.methods.HttpPost)2 HttpRequestBase (org.apache.http.client.methods.HttpRequestBase)2 HttpUriRequest (org.apache.http.client.methods.HttpUriRequest)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 SocketTimeoutException (java.net.SocketTimeoutException)1 URISyntaxException (java.net.URISyntaxException)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 StringTokenizer (java.util.StringTokenizer)1 GZIPOutputStream (java.util.zip.GZIPOutputStream)1