Search in sources :

Example 71 with BasicHttpResponse

use of org.graylog.shaded.elasticsearch7.org.apache.http.message.BasicHttpResponse in project OpenRefine by OpenRefine.

the class AppEngineClientConnection method receiveResponseHeader.

public HttpResponse receiveResponseHeader() {
    URLFetchService ufs = URLFetchServiceFactory.getURLFetchService();
    try {
        _appengine_hresponse = ufs.fetch(_appengine_hrequest);
    } catch (java.io.IOException e) {
        throw new RuntimeException(e);
    }
    org.apache.http.HttpResponse apache_response = new BasicHttpResponse(new ProtocolVersion("HTTP", 1, 0), _appengine_hresponse.getResponseCode(), null);
    for (HTTPHeader h : _appengine_hresponse.getHeaders()) {
        apache_response.addHeader(h.getName(), h.getValue());
    }
    return apache_response;
}
Also used : BasicHttpResponse(org.apache.http.message.BasicHttpResponse) URLFetchService(com.google.appengine.api.urlfetch.URLFetchService) HttpResponse(org.apache.http.HttpResponse) ProtocolVersion(org.apache.http.ProtocolVersion) HTTPHeader(com.google.appengine.api.urlfetch.HTTPHeader)

Example 72 with BasicHttpResponse

use of org.graylog.shaded.elasticsearch7.org.apache.http.message.BasicHttpResponse in project XobotOS by xamarin.

the class DefaultHttpResponseFactory method newHttpResponse.

// non-javadoc, see interface HttpResponseFactory
public HttpResponse newHttpResponse(final ProtocolVersion ver, final int status, HttpContext context) {
    if (ver == null) {
        throw new IllegalArgumentException("HTTP version may not be null");
    }
    final Locale loc = determineLocale(context);
    final String reason = reasonCatalog.getReason(status, loc);
    StatusLine statusline = new BasicStatusLine(ver, status, reason);
    return new BasicHttpResponse(statusline, reasonCatalog, loc);
}
Also used : Locale(java.util.Locale) BasicStatusLine(org.apache.http.message.BasicStatusLine) StatusLine(org.apache.http.StatusLine) BasicHttpResponse(org.apache.http.message.BasicHttpResponse) BasicStatusLine(org.apache.http.message.BasicStatusLine)

Example 73 with BasicHttpResponse

use of org.graylog.shaded.elasticsearch7.org.apache.http.message.BasicHttpResponse in project camel by apache.

the class Olingo2AppImpl method parseResponse.

private Olingo2BatchResponse parseResponse(Edm edm, Map<String, String> contentIdLocationMap, Olingo2BatchRequest request, BatchSingleResponse response) throws EntityProviderException, ODataApplicationException {
    // validate HTTP status
    final int statusCode = Integer.parseInt(response.getStatusCode());
    final String statusInfo = response.getStatusInfo();
    final BasicHttpResponse httpResponse = new BasicHttpResponse(new BasicStatusLine(HttpVersion.HTTP_1_1, statusCode, statusInfo));
    final Map<String, String> headers = response.getHeaders();
    for (Map.Entry<String, String> entry : headers.entrySet()) {
        httpResponse.setHeader(entry.getKey(), entry.getValue());
    }
    ByteArrayInputStream content = null;
    try {
        if (response.getBody() != null) {
            final ContentType partContentType = receiveWithCharsetParameter(ContentType.parse(headers.get(HttpHeaders.CONTENT_TYPE)), Consts.UTF_8);
            final String charset = partContentType.getCharset().toString();
            final String body = response.getBody();
            content = body != null ? new ByteArrayInputStream(body.getBytes(charset)) : null;
            httpResponse.setEntity(new StringEntity(body, charset));
        }
        AbstractFutureCallback.checkStatus(httpResponse);
    } catch (ODataApplicationException e) {
        return new Olingo2BatchResponse(statusCode, statusInfo, response.getContentId(), response.getHeaders(), e);
    } catch (UnsupportedEncodingException e) {
        return new Olingo2BatchResponse(statusCode, statusInfo, response.getContentId(), response.getHeaders(), e);
    }
    // resolve resource path and query params and parse batch part uri
    final String resourcePath = request.getResourcePath();
    final String resolvedResourcePath;
    if (resourcePath.startsWith("$") && !(METADATA.equals(resourcePath) || BATCH.equals(resourcePath))) {
        resolvedResourcePath = findLocation(resourcePath, contentIdLocationMap);
    } else {
        final String resourceLocation = response.getHeader(HttpHeaders.LOCATION);
        resolvedResourcePath = resourceLocation != null ? resourceLocation.substring(serviceUri.length()) : resourcePath;
    }
    final Map<String, String> resolvedQueryParams = request instanceof Olingo2BatchQueryRequest ? ((Olingo2BatchQueryRequest) request).getQueryParams() : null;
    final UriInfoWithType uriInfo = parseUri(edm, resolvedResourcePath, resolvedQueryParams);
    // resolve response content
    final Object resolvedContent = content != null ? readContent(uriInfo, content) : null;
    return new Olingo2BatchResponse(statusCode, statusInfo, response.getContentId(), response.getHeaders(), resolvedContent);
}
Also used : ContentType(org.apache.http.entity.ContentType) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ODataApplicationException(org.apache.olingo.odata2.api.exception.ODataApplicationException) BasicStatusLine(org.apache.http.message.BasicStatusLine) Olingo2BatchQueryRequest(org.apache.camel.component.olingo2.api.batch.Olingo2BatchQueryRequest) StringEntity(org.apache.http.entity.StringEntity) BasicHttpResponse(org.apache.http.message.BasicHttpResponse) Olingo2BatchResponse(org.apache.camel.component.olingo2.api.batch.Olingo2BatchResponse) ByteArrayInputStream(java.io.ByteArrayInputStream) Map(java.util.Map) HashMap(java.util.HashMap)

Example 74 with BasicHttpResponse

use of org.graylog.shaded.elasticsearch7.org.apache.http.message.BasicHttpResponse in project ddf by codice.

the class SolrHttpWrapper method execute.

@Override
public ResponseWrapper execute(URI uri) {
    HttpResponse httpResponse;
    HttpGet get = new HttpGet(uri);
    try {
        LOGGER.debug("Executing uri: {}", uri.toString());
        httpResponse = solrClient.execute(get);
        return new ResponseWrapper(httpResponse);
    } catch (IOException e) {
        LOGGER.debug("Error during request. Returning null response.");
    }
    BasicHttpResponse response = new BasicHttpResponse(null, HttpStatus.SC_INTERNAL_SERVER_ERROR, "Error during request.");
    return new ResponseWrapper(response);
}
Also used : BasicHttpResponse(org.apache.http.message.BasicHttpResponse) HttpGet(org.apache.http.client.methods.HttpGet) BasicHttpResponse(org.apache.http.message.BasicHttpResponse) HttpResponse(org.apache.http.HttpResponse) IOException(java.io.IOException)

Example 75 with BasicHttpResponse

use of org.graylog.shaded.elasticsearch7.org.apache.http.message.BasicHttpResponse in project ddf by codice.

the class BackupCommandTest method prepareResponse.

private HttpResponse prepareResponse(int statusCode, String responseBody) {
    HttpResponse httpResponse = new BasicHttpResponse(new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), statusCode, ""));
    httpResponse.setStatusCode(statusCode);
    try {
        httpResponse.setEntity(new StringEntity(responseBody));
    } catch (UnsupportedEncodingException e) {
        throw new IllegalArgumentException(e);
    }
    return httpResponse;
}
Also used : StringEntity(org.apache.http.entity.StringEntity) BasicHttpResponse(org.apache.http.message.BasicHttpResponse) BasicHttpResponse(org.apache.http.message.BasicHttpResponse) HttpResponse(org.apache.http.HttpResponse) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ProtocolVersion(org.apache.http.ProtocolVersion) BasicStatusLine(org.apache.http.message.BasicStatusLine)

Aggregations

BasicHttpResponse (org.apache.http.message.BasicHttpResponse)107 BasicStatusLine (org.apache.http.message.BasicStatusLine)64 ProtocolVersion (org.apache.http.ProtocolVersion)58 HttpResponse (org.apache.http.HttpResponse)51 StatusLine (org.apache.http.StatusLine)39 Test (org.junit.Test)39 StringEntity (org.apache.http.entity.StringEntity)34 IOException (java.io.IOException)33 List (java.util.List)24 Header (org.apache.http.Header)22 HttpHost (org.apache.http.HttpHost)19 HashMap (java.util.HashMap)18 URL (java.net.URL)17 BasicHeader (org.apache.http.message.BasicHeader)17 HttpURLConnection (java.net.HttpURLConnection)16 HttpEntity (org.apache.http.HttpEntity)14 MainResponse (org.elasticsearch.action.main.MainResponse)14 Before (org.junit.Before)13 BasicHttpEntity (org.apache.http.entity.BasicHttpEntity)12 ElasticsearchException (org.elasticsearch.ElasticsearchException)12