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;
}
}
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);
}
Aggregations