private IOException asIOException(HttpRequestBase request, HttpResponse response) throws IOException { return new IOException(request.getMethod() + " failed, error code " + response.getStatusLine().getStatusCode() + " and response: " + EntityUtils.toString(response.getEntity())); }
/** * Set the request body. This value may be of any type supported by * the associated {@link EncoderRegistry request encoder}. That is, * the value of <code>body</code> will be interpreted by the encoder * associated with the current {@link #getRequestContentType() request * content-type}. * * @param body data or closure interpreted as the request body * @see #send(Object, Object) */ public void setBody(Object requestContentType, Object body) { if (!(request instanceof HttpEntityEnclosingRequest)) throw new IllegalArgumentException( "Cannot set a request body for a " + request.getMethod() + " method"); Closure encoder = encoders.getAt(requestContentType); HttpEntity entity = (HttpEntity) encoder.call(requestContentType, body); ((HttpEntityEnclosingRequest) this.request).setEntity(entity); }
public RequestLine getRequestLine() { String method = getMethod(); ProtocolVersion ver = getProtocolVersion(); URI uri = getURI(); String uritext = null; if (uri != null) { uritext = uri.toASCIIString(); } if (uritext == null || uritext.length() == 0) { uritext = "/"; } return new BasicRequestLine(method, uritext, ver); }
@Override public String getHttpVerbName() { return myRequest.getMethod(); }
/** * Set the request body. This value may be of any type supported by * the associated {@link EncoderRegistry request encoder}. That is, * the value of <code>body</code> will be interpreted by the encoder * associated with the current {@link #getRequestContentType() request * content-type}. * @see #send(Object, Object) * @param body data or closure interpreted as the request body */ public void setBody( Object requestContentType, Object body ) { if ( ! (request instanceof HttpEntityEnclosingRequest ) ) throw new IllegalArgumentException( "Cannot set a request body for a " + request.getMethod() + " method" ); Closure encoder = encoders.getAt( requestContentType ); HttpEntity entity = (HttpEntity)encoder.call( requestContentType, body ); ((HttpEntityEnclosingRequest)this.request).setEntity( entity ); }
private static HttpRequestBase addRequestBody(HttpRequestBase httpRequest, HttpEntity entity) { if (entity != null) { if (httpRequest instanceof HttpEntityEnclosingRequestBase) { ((HttpEntityEnclosingRequestBase)httpRequest).setEntity(entity); } else { throw new UnsupportedOperationException(httpRequest.getMethod() + " with body is not supported"); } } return httpRequest; }
private static HttpRequestBase addRequestBody(HttpRequestBase httpRequest, HttpEntity entity) { if (entity != null) { if (httpRequest instanceof HttpEntityEnclosingRequestBase) { ((HttpEntityEnclosingRequestBase)httpRequest).setEntity(entity); } else { throw new UnsupportedOperationException(httpRequest.getMethod() + " with body is not supported"); } } return httpRequest; }
/** * Returns the HTTP Method as a String * @return */ public String getHttpMethodAsString() { try { return this.getRequestType().newInstance().getMethod().toUpperCase(); } catch (Exception e) { throw new IllegalArgumentException(e); } }
/** * Returns HTTP method associated with this request * @return The name of HTTP method associated with this request */ public String getMethod() { return getCoreRequest().getMethod(); }
/** * Returns HTTP method associated with this request * @return The name of HTTP method associated with this request */ public String getMethod() { return getCoreRequest().getMethod(); }
CloseableHttpResponse execute(HttpRequestBase req, HttpClientContext context) throws ClientProtocolException, IOException { return !SettingsManager.settings().cache() || nonCachedMethods.contains(req.getMethod()) ? client.execute(req, context) : cachingClient.execute(req, context); }
@Override protected void log(HttpRequestBase request) { try { URI uri = request.getURI(); LOG.info("performing " + request.getMethod() + " on uri " + decode(uri.toString(), DEFAULT_ENCODING)); LOG.debug("encoded uri is " + uri.toString()); logBody(request); logHeaders(request); } catch (IOException e) { throw new UncheckedIOException(e); } }
private HttpException requestFailed(HttpRequestBase request, CloseableHttpResponse httpResponse, StatusLine statusLine) throws IOException { int statusCode = statusLine.getStatusCode(); HttpEntity entity = httpResponse.getEntity(); String body = toString(entity); String method = request.getMethod(); URI uri = request.getURI(); String reasonPhrase = statusLine.getReasonPhrase(); return new HttpException(statusCode, String.format("%n%s %s%n==> %d %s%n%s", method, uri, statusCode, reasonPhrase, body)); }
/** * Performs the request constructed in this builder and returns the response * * @return the repository response * @throws FcrepoOperationFailedException when the underlying HTTP request results in an error */ public FcrepoResponse perform() throws FcrepoOperationFailedException { LOGGER.debug("Fcrepo {} request to {} with headers: {}", request.getMethod(), targetUri, request.getAllHeaders()); return client.executeRequest(targetUri, request); }
private HttpResponse execute(HttpRequestBase httpRequestBase) { logger.info(String.format("%s---%s", httpRequestBase.getURI().toString(), httpRequestBase.getMethod())); CouchRequest couchRequest = couchHttpRequestFactory.create(httpRequestBase); return couchRequest.execute(databases); }
public static RepositoryException generate(DavException davExc, HttpRequestBase request) { String name = (request == null) ? "_undefined_" : request.getMethod(); int code = DavMethods.getMethodCode(name); return generate(davExc, code, name); }
public RequestLine getRequestLine() { String method = getMethod(); ProtocolVersion ver = getProtocolVersion(); URI uri = getURI(); String uritext = null; if (uri != null) { uritext = uri.toASCIIString(); } if (uritext == null || uritext.length() == 0) { uritext = "/"; } return new BasicRequestLine(method, uritext, ver); }
public static RepositoryException generate(DavException davExc, HttpRequestBase request) { String name = (request == null) ? "_undefined_" : request.getMethod(); int code = DavMethods.getMethodCode(name); return generate(davExc, code, name); }
private String sendRequest(HttpRequestBase request) throws IOException { try (CloseableHttpClient httpClient = createHttpClient()) { return getReply(httpClient, request); } catch (UnknownHostException | ConnectException e) { throw new WebClientException(e, "Unable to execute %s request to %s", request.getMethod(), request.getURI()); } }
@Override public T coerce(final HttpRequestBase request, final HttpResponse response) { final HttpEntity entity = response.getEntity(); this.requestMethod = request.getMethod(); this.requestContentType = null == entity ? null : ContentType.get(entity).getMimeType(); this.requestAcceptHeader = request.getFirstHeader("Accept").getValue(); return null; }