/** * Standard encoder for binary types. Accepts ByteArrayInputStream, InputStream, and byte[] types. * * @param config Fully configured chained request * @param ts Formatted http body is passed to the ToServer argument */ public static void binary(final ChainedHttpConfig config, final ToServer ts) { final ChainedHttpConfig.ChainedRequest request = config.getChainedRequest(); final Object body = checkNull(request.actualBody()); if (handleRawUpload(config, ts)) { return; } checkTypes(body, BINARY_TYPES); if (body instanceof byte[]) { ts.toServer(new ByteArrayInputStream((byte[]) body)); } else { throw new UnsupportedOperationException(); } }
/** * Standard encoder for binary types. Accepts ByteArrayInputStream, InputStream, and byte[] types. * * @param config Fully configured chained request * @param ts Formatted http body is passed to the ToServer argument */ public static void binary(final ChainedHttpConfig config, final ToServer ts) { final ChainedHttpConfig.ChainedRequest request = config.getChainedRequest(); final Object body = checkNull(request.actualBody()); if (handleRawUpload(config, ts)) { return; } checkTypes(body, BINARY_TYPES); if (body instanceof byte[]) { ts.toServer(new ByteArrayInputStream((byte[]) body)); } else { throw new UnsupportedOperationException(); } }
/** * Standard encoder for binary types. Accepts ByteArrayInputStream, InputStream, and byte[] types. * * @param config Fully configured chained request * @param ts Formatted http body is passed to the ToServer argument */ public static void binary(final ChainedHttpConfig config, final ToServer ts) { final ChainedHttpConfig.ChainedRequest request = config.getChainedRequest(); final Object body = checkNull(request.actualBody()); if (handleRawUpload(config, ts)) { return; } checkTypes(body, BINARY_TYPES); if (body instanceof byte[]) { ts.toServer(new ByteArrayInputStream((byte[]) body)); } else { throw new UnsupportedOperationException(); } }
/** * Used to encode the request content using the Jackson JSON encoder. * * @param config the configuration * @param ts the server request content accessor */ @SuppressWarnings("WeakerAccess") public static void encode(final ChainedHttpConfig config, final ToServer ts) { try { if (handleRawUpload(config, ts)) { return; } final ChainedHttpConfig.ChainedRequest request = config.getChainedRequest(); final ObjectMapper mapper = (ObjectMapper) config.actualContext(request.actualContentType(), OBJECT_MAPPER_ID); final StringWriter writer = new StringWriter(); mapper.writeValue(writer, request.actualBody()); ts.toServer(new CharSequenceInputStream(writer.toString(), request.actualCharset())); } catch (IOException e) { throw new RuntimeException(e); } }
/** * Used to encode the request content using the Jackson JSON encoder. * * @param config the configuration * @param ts the server request content accessor */ @SuppressWarnings("WeakerAccess") public static void encode(final ChainedHttpConfig config, final ToServer ts) { try { if (handleRawUpload(config, ts)) { return; } final ChainedHttpConfig.ChainedRequest request = config.getChainedRequest(); final ObjectMapper mapper = (ObjectMapper) config.actualContext(request.actualContentType(), OBJECT_MAPPER_ID); final StringWriter writer = new StringWriter(); mapper.writeValue(writer, request.actualBody()); ts.toServer(new CharSequenceInputStream(writer.toString(), request.actualCharset())); } catch (IOException e) { throw new TransportingException(e); } }
public static void encode(final ChainedHttpConfig config, final ToServer ts) { if(handleRawUpload(config, ts)) { return; } final ChainedHttpConfig.ChainedRequest request = config.getChainedRequest(); final Csv.Context ctx = (Csv.Context) config.actualContext(request.actualContentType(), Csv.Context.ID); final Object body = checkNull(request.actualBody()); checkTypes(body, new Class[] { Iterable.class }); final StringWriter writer = new StringWriter(); final CSVWriter csvWriter = ctx.makeWriter(new StringWriter()); Iterable<?> iterable = (Iterable<?>) body; for(Object o : iterable) { csvWriter.writeNext((String[]) o); } ts.toServer(stringToStream(writer.toString(), request.actualCharset())); }
/** * Used to encode the request content using the Jackson JSON encoder. * * @param config the configuration * @param ts the server request content accessor */ @SuppressWarnings("WeakerAccess") public static void encode(final ChainedHttpConfig config, final ToServer ts) { try { if (handleRawUpload(config, ts)) { return; } final ChainedHttpConfig.ChainedRequest request = config.getChainedRequest(); final ObjectMapper mapper = (ObjectMapper) config.actualContext(request.actualContentType(), OBJECT_MAPPER_ID); final StringWriter writer = new StringWriter(); mapper.writeValue(writer, request.actualBody()); ts.toServer(new CharSequenceInputStream(writer.toString(), request.actualCharset())); } catch (IOException e) { throw new TransportingException(e); } }
/** * Standard encoder for text types. Accepts String and Reader types * * @param config Fully configured chained request * @param ts Formatted http body is passed to the ToServer argument */ public static void text(final ChainedHttpConfig config, final ToServer ts) throws IOException { final ChainedHttpConfig.ChainedRequest request = config.getChainedRequest(); if (handleRawUpload(config, ts)) { return; } final Object body = checkNull(request.actualBody()); checkTypes(body, TEXT_TYPES); ts.toServer(stringToStream(body.toString(), request.actualCharset())); }
/** * Standard encoder for requests with an xml body. * <p> * Accepts String and {@link Closure} types. If the body is a String type the method passes the body * to the ToServer parameter as is. If the body is a {@link Closure} then the closure is converted * to xml using Groovy's {@link StreamingMarkupBuilder}. * * @param config Fully configured chained request * @param ts Formatted http body is passed to the ToServer argument */ public static void xml(final ChainedHttpConfig config, final ToServer ts) { final ChainedHttpConfig.ChainedRequest request = config.getChainedRequest(); if (handleRawUpload(config, ts)) { return; } final Object body = checkNull(request.actualBody()); checkTypes(body, XML_TYPES); if (body instanceof String) { ts.toServer(stringToStream((String) body, request.actualCharset())); } else if (body instanceof Closure) { final StreamingMarkupBuilder smb = new StreamingMarkupBuilder(); ts.toServer(stringToStream(smb.bind(body).toString(), request.actualCharset())); } else { throw new UnsupportedOperationException(); } }
/** * Standard encoder for text types. Accepts String and Reader types * * @param config Fully configured chained request * @param ts Formatted http body is passed to the ToServer argument */ public static void text(final ChainedHttpConfig config, final ToServer ts) throws IOException { final ChainedHttpConfig.ChainedRequest request = config.getChainedRequest(); if (handleRawUpload(config, ts)) { return; } final Object body = checkNull(request.actualBody()); checkTypes(body, TEXT_TYPES); ts.toServer(stringToStream(body.toString(), request.actualCharset())); }
/** * Standard encoder for text types. Accepts String and Reader types * * @param config Fully configured chained request * @param ts Formatted http body is passed to the ToServer argument */ public static void text(final ChainedHttpConfig config, final ToServer ts) throws IOException { final ChainedHttpConfig.ChainedRequest request = config.getChainedRequest(); if (handleRawUpload(config, ts)) { return; } final Object body = checkNull(request.actualBody()); checkTypes(body, TEXT_TYPES); ts.toServer(stringToStream(body.toString(), request.actualCharset())); }
public static void jsoupEncode(final ChainedHttpConfig config, final ToServer ts) { final ChainedHttpConfig.ChainedRequest request = config.getChainedRequest(); if (handleRawUpload(config, ts)) { return; } final Document document = (Document) request.actualBody(); ts.toServer(stringToStream(document.text(), request.actualCharset())); } }
public static void jsoupEncode(final ChainedHttpConfig config, final ToServer ts) { final ChainedHttpConfig.ChainedRequest request = config.getChainedRequest(); if (handleRawUpload(config, ts)) { return; } final Document document = (Document) request.actualBody(); ts.toServer(stringToStream(document.text(), request.actualCharset())); } }
public static void jsoupEncode(final ChainedHttpConfig config, final ToServer ts) { final ChainedHttpConfig.ChainedRequest request = config.getChainedRequest(); if (handleRawUpload(config, ts)) { return; } final Document document = (Document) request.actualBody(); ts.toServer(stringToStream(document.text(), request.actualCharset())); } }
/** * Used to encode the request content using the OpenCsv writer. * * @param config the configuration * @param ts the server request content accessor */ public static void encode(final ChainedHttpConfig config, final ToServer ts) { if (handleRawUpload(config, ts)) { return; } final ChainedHttpConfig.ChainedRequest request = config.getChainedRequest(); final Csv.Context ctx = (Csv.Context) config.actualContext(request.actualContentType(), Csv.Context.ID); final Object body = checkNull(request.actualBody()); checkTypes(body, new Class[]{Iterable.class}); final StringWriter writer = new StringWriter(); final CSVWriter csvWriter = ctx.makeWriter(new StringWriter()); Iterable<?> iterable = (Iterable<?>) body; for (Object o : iterable) { csvWriter.writeNext((String[]) o); } ts.toServer(stringToStream(writer.toString(), request.actualCharset())); }
/** * Used to encode the request content using the OpenCsv writer. * * @param config the configuration * @param ts the server request content accessor */ public static void encode(final ChainedHttpConfig config, final ToServer ts) { if (handleRawUpload(config, ts)) { return; } final ChainedHttpConfig.ChainedRequest request = config.getChainedRequest(); final Csv.Context ctx = (Csv.Context) config.actualContext(request.actualContentType(), Csv.Context.ID); final Object body = checkNull(request.actualBody()); checkTypes(body, new Class[]{Iterable.class}); final StringWriter writer = new StringWriter(); final CSVWriter csvWriter = ctx.makeWriter(new StringWriter()); Iterable<?> iterable = (Iterable<?>) body; for (Object o : iterable) { csvWriter.writeNext((String[]) o); } ts.toServer(stringToStream(writer.toString(), request.actualCharset())); }
@Override public void accept(final ChainedHttpConfig config, final ToServer ts) { final ChainedHttpConfig.ChainedRequest request = config.getChainedRequest(); final Object body = request.actualBody(); NativeHandlers.Encoders.checkTypes(body, MULTIPART_TYPES); MultipartContent mp = (MultipartContent) request.actualBody(); request.setContentType("multipart/form-data; boundary=" + mp.boundary()); ts.toServer(stream(config, mp)); }
/** * Standard encoder for requests with a json body. * <p> * Accepts String, {@link GString} and {@link Closure} types. If the body is a String type the method passes the body * to the ToServer parameter as is. If the body is a {@link Closure} then the closure is converted * to json using Groovy's {@link JsonBuilder}. * * @param config Fully configured chained request * @param ts Formatted http body is passed to the ToServer argument */ public static void json(final ChainedHttpConfig config, final ToServer ts) { final ChainedHttpConfig.ChainedRequest request = config.getChainedRequest(); if (handleRawUpload(config, ts)) { return; } final Object body = checkNull(request.actualBody()); final String json = ((body instanceof String || body instanceof GString) ? body.toString() : new JsonBuilder(body).toString()); ts.toServer(stringToStream(json, request.actualCharset())); } }
/** * Standard encoder for requests with a json body. * <p> * Accepts String, {@link GString} and {@link Closure} types. If the body is a String type the method passes the body * to the ToServer parameter as is. If the body is a {@link Closure} then the closure is converted * to json using Groovy's {@link JsonBuilder}. * * @param config Fully configured chained request * @param ts Formatted http body is passed to the ToServer argument */ public static void json(final ChainedHttpConfig config, final ToServer ts) { final ChainedHttpConfig.ChainedRequest request = config.getChainedRequest(); if (handleRawUpload(config, ts)) { return; } final Object body = checkNull(request.actualBody()); final String json = ((body instanceof String || body instanceof GString) ? body.toString() : new JsonBuilder(body).toString()); ts.toServer(stringToStream(json, request.actualCharset())); } }
/** * Standard encoder for requests with a json body. * <p> * Accepts String, {@link GString} and {@link Closure} types. If the body is a String type the method passes the body * to the ToServer parameter as is. If the body is a {@link Closure} then the closure is converted * to json using Groovy's {@link JsonBuilder}. * * @param config Fully configured chained request * @param ts Formatted http body is passed to the ToServer argument */ public static void json(final ChainedHttpConfig config, final ToServer ts) { final ChainedHttpConfig.ChainedRequest request = config.getChainedRequest(); if (handleRawUpload(config, ts)) { return; } final Object body = checkNull(request.actualBody()); final String json = ((body instanceof String || body instanceof GString) ? body.toString() : new JsonBuilder(body).toString()); ts.toServer(stringToStream(json, request.actualCharset())); } }