private void addHeaders() throws URISyntaxException { final ChainedHttpConfig.ChainedRequest cr = requestConfig.getChainedRequest(); for (Map.Entry<String, CharSequence> entry : cr.actualHeaders(new LinkedHashMap<>()).entrySet()) { connection.addRequestProperty(entry.getKey(), entry.getValue() != null ? entry.getValue().toString() : null); } final String contentType = cr.actualContentType(); if (contentType != null) { final Charset charset = cr.actualCharset(); if (charset != null) { connection.addRequestProperty("Content-Type", contentType + "; charset=" + charset.toString().toLowerCase()); } else { connection.addRequestProperty("Content-Type", contentType); } } connection.addRequestProperty("Accept-Encoding", "gzip, deflate"); for (Map.Entry<String, String> e : cookiesToAdd(clientConfig, cr).entrySet()) { connection.addRequestProperty(e.getKey(), e.getValue()); } if (headerLog.isDebugEnabled()) { connection.getRequestProperties().forEach((name, values) -> headerLog.debug("Request-Header: {} -> {}", name, values)); } }
@SuppressWarnings("Duplicates") private <T extends HttpUriRequest> void addHeaders(final ChainedHttpConfig.ChainedRequest cr, final T message) throws URISyntaxException { for (Map.Entry<String, CharSequence> entry : cr.actualHeaders(new LinkedHashMap<>()).entrySet()) { message.addHeader(entry.getKey(), entry.getValue() != null ? entry.getValue().toString() : null); } final String contentType = cr.actualContentType(); if (contentType != null) { final Charset charset = cr.actualCharset(); if (charset != null) { message.setHeader("Content-Type", contentType + "; charset=" + charset.toString().toLowerCase()); } else { message.setHeader("Content-Type", contentType); } } for (Map.Entry<String, String> e : cookiesToAdd(clientConfig, cr).entrySet()) { message.addHeader(e.getKey(), e.getValue()); } }
@SuppressWarnings("Duplicates") private <T extends HttpUriRequest> void addHeaders(final ChainedHttpConfig.ChainedRequest cr, final T message) throws URISyntaxException { for (Map.Entry<String, CharSequence> entry : cr.actualHeaders(new LinkedHashMap<>()).entrySet()) { message.addHeader(entry.getKey(), entry.getValue() != null ? entry.getValue().toString() : null); } final String contentType = cr.actualContentType(); if (contentType != null) { final Charset charset = cr.actualCharset(); if (charset != null) { message.setHeader("Content-Type", contentType + "; charset=" + charset.toString().toLowerCase()); } else { message.setHeader("Content-Type", contentType); } } for (Map.Entry<String, String> e : cookiesToAdd(clientConfig, cr).entrySet()) { message.addHeader(e.getKey(), e.getValue()); } }
/** * 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())); } }
/** * 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 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); } }
/** * 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 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())); }
/** * 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())); }
/** * 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())); }
default Charset findCharset(){ return getChainedRequest().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())); } }
private RequestBody resolveRequestBody(final ChainedHttpConfig chainedConfig) { final ChainedHttpConfig.ChainedRequest cr = chainedConfig.getChainedRequest(); final RequestBody body; if (cr.actualBody() != null) { final OkHttpToServer toServer = new OkHttpToServer(chainedConfig); chainedConfig.findEncoder().accept(chainedConfig, toServer); body = toServer; } else { body = RequestBody.create(resolveMediaType(cr.actualContentType(), cr.actualCharset()), ""); } return body; }
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())); } }
default Charset findCharset(){ return getChainedRequest().actualCharset(); } }