@Override /* BasicHttpEntity */ public InputStream getContent() { if (outputBytes == null) { try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) { writeTo(baos); outputBytes = baos.toByteArray(); } catch (IOException e) { throw new RuntimeException(e); } } return new ByteArrayInputStream(outputBytes); } }
/** * Perform a <code>POST</code> request with a content type of <code>application/x-www-form-urlencoded</code> * against the specified URL. * * @param url * The URL of the remote REST resource. * Can be any of the following: {@link String}, {@link URI}, {@link URL}. * @param o * The object to serialize and transmit to the URL as the body of the request, serialized as a form post * using the {@link UrlEncodingSerializer#DEFAULT} serializer. * @return * A {@link RestCall} object that can be further tailored before executing the request and getting the response * as a parsed object. * @throws RestCallException If any authentication errors occurred. */ public RestCall doFormPost(Object url, Object o) throws RestCallException { return doCall("POST", url, true) .body(o instanceof HttpEntity ? o : new RestRequestEntity(o, urlEncodingSerializer, null)); }
/** * Constructor. * * @param input The POJO to serialize. Can also be a {@link Reader} or {@link InputStream}. * @param serializer The serializer to use to serialize this response. * @param schema The optional schema information about the serialized part. */ public RestRequestEntity(Object input, Serializer serializer, HttpPartSchema schema) { this.output = input; this.serializer = serializer; this.schema = schema; if (serializer != null && serializer.getResponseContentType() != null) setContentType(new BasicHeader("Content-Type", serializer.getResponseContentType().toString())); }
/** * Perform a <code>POST</code> request with a content type of <code>application/x-www-form-urlencoded</code> * against the specified URL. * * @param url * The URL of the remote REST resource. * Can be any of the following: {@link String}, {@link URI}, {@link URL}. * @param o * The object to serialize and transmit to the URL as the body of the request, serialized as a form post * using the {@link UrlEncodingSerializer#DEFAULT} serializer. * @return * A {@link RestCall} object that can be further tailored before executing the request and getting the response * as a parsed object. * @throws RestCallException If any authentication errors occurred. */ public RestCall doFormPost(Object url, Object o) throws RestCallException { return doCall("POST", url, true) .body(o instanceof HttpEntity ? o : new RestRequestEntity(o, urlEncodingSerializer, null)); }
/** * Constructor. * * @param input The POJO to serialize. Can also be a {@link Reader} or {@link InputStream}. * @param serializer The serializer to use to serialize this response. * @param schema The optional schema information about the serialized part. */ public RestRequestEntity(Object input, Serializer serializer, HttpPartSchema schema) { this.output = input; this.serializer = serializer; this.schema = schema; if (serializer != null && serializer.getResponseContentType() != null) setContentType(new BasicHeader("Content-Type", serializer.getResponseContentType().toString())); }
/** * Perform a <code>POST</code> request with a content type of <code>application/x-www-form-urlencoded</code> * against the specified URL. * * @param url * The URL of the remote REST resource. * Can be any of the following: {@link String}, {@link URI}, {@link URL}. * @param o * The object to serialize and transmit to the URL as the body of the request, serialized as a form post * using the {@link UrlEncodingSerializer#DEFAULT} serializer. * @return * A {@link RestCall} object that can be further tailored before executing the request and getting the response * as a parsed object. * @throws RestCallException If any authentication errors occurred. */ public RestCall doFormPost(Object url, Object o) throws RestCallException { return doCall("POST", url, true) .body(o instanceof HttpEntity ? o : new RestRequestEntity(o, urlEncodingSerializer, null)); }
@Override /* BasicHttpEntity */ public InputStream getContent() { if (outputBytes == null) { try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) { writeTo(baos); outputBytes = baos.toByteArray(); } catch (IOException e) { throw new RuntimeException(e); } } return new ByteArrayInputStream(outputBytes); } }
/** * Constructor. * * @param input The POJO to serialize. Can also be a {@link Reader} or {@link InputStream}. * @param serializer The serializer to use to serialize this response. * @param schema The optional schema information about the serialized part. */ public RestRequestEntity(Object input, Serializer serializer, HttpPartSchema schema) { this.output = input; this.serializer = serializer; this.schema = schema; if (serializer != null && serializer.getResponseContentType() != null) setContentType(new BasicHeader("Content-Type", serializer.getResponseContentType().toString())); }
entity = new InputStreamEntity((InputStream)input, getRequestContentType(ContentType.APPLICATION_OCTET_STREAM)); else if (serializer != null) entity = new RestRequestEntity(input, serializer, requestBodySchema); else if (partSerializer != null) entity = new StringEntity(partSerializer.serialize((HttpPartSchema)null, input), getRequestContentType(TEXT_PLAIN));
@Override /* BasicHttpEntity */ public InputStream getContent() { if (outputBytes == null) { try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) { writeTo(baos); outputBytes = baos.toByteArray(); } catch (IOException e) { throw new RuntimeException(e); } } return new ByteArrayInputStream(outputBytes); } }
entity = new InputStreamEntity((InputStream)input, getRequestContentType(ContentType.APPLICATION_OCTET_STREAM)); else if (serializer != null) entity = new RestRequestEntity(input, serializer, requestBodySchema); else if (partSerializer != null) entity = new StringEntity(partSerializer.serialize((HttpPartSchema)null, input), getRequestContentType(TEXT_PLAIN));
entity = new InputStreamEntity((InputStream)input, getRequestContentType(ContentType.APPLICATION_OCTET_STREAM)); else if (serializer != null) entity = new RestRequestEntity(input, serializer, requestBodySchema); else if (partSerializer != null) entity = new StringEntity(partSerializer.serialize((HttpPartSchema)null, input), getRequestContentType(TEXT_PLAIN));