public MultipartBody field(String name, Object value, boolean file, String contentType) { List<Object> list = parameters.get(name); if (list == null) list = new LinkedList<Object>(); list.add(value); parameters.put(name, list); ContentType type = null; if (contentType != null && contentType.length() > 0) { type = ContentType.parse(contentType); } else if (file) { type = ContentType.APPLICATION_OCTET_STREAM; } else { type = ContentType.APPLICATION_FORM_URLENCODED.withCharset(UTF_8); } contentTypes.put(name, type); if (!hasFile && file) { hasFile = true; } return this; }
post.setEntity( ( new StringEntity( bodyParams, ContentType.TEXT_XML.withCharset( "US-ASCII" ) ) ) );
public static HttpEntity buildSingleLogoutRequest(String serviceTicket) { String id = "ID_" + UUID.randomUUID().toString(); String issueInstant = new SimpleDateFormat("yyyy-MM-dd'T'H:mm:ss").format(new Date()); String document = TEMPLATE.replace("$ID", id).replace("$ISSUE_INSTANT", issueInstant) .replace("$SESSION_IDENTIFIER", serviceTicket); return new StringEntity(document, ContentType.APPLICATION_XML.withCharset(StandardCharsets.UTF_8)); }
public ContentType getContentType() { if(contentType == null){ if(isFile()){ return ContentType.APPLICATION_OCTET_STREAM; } return ContentType.APPLICATION_FORM_URLENCODED.withCharset(StandardCharsets.UTF_8); } return contentType; }
private ContentType getContentType() { if(contentType == null){ if(isFile()){ return ContentType.APPLICATION_OCTET_STREAM; } return ContentType.APPLICATION_FORM_URLENCODED.withCharset(StandardCharsets.UTF_8); } return contentType; }
private ContentType getContentType() { if(contentType == null){ if(isFile()){ return ContentType.APPLICATION_OCTET_STREAM; } return ContentType.APPLICATION_FORM_URLENCODED.withCharset(StandardCharsets.UTF_8); } return contentType; }
public MultipartBody field(String name, Object value, boolean file, String contentType) { if (!keyOrder.contains(name)) keyOrder.add(name); List<Object> list = parameters.get(name); if (list == null) list = new LinkedList<Object>(); list.add(value); parameters.put(name, list); ContentType type = null; if (contentType != null && contentType.length() > 0) { type = ContentType.parse(contentType); } else if (file) { type = ContentType.APPLICATION_OCTET_STREAM; } else { type = ContentType.APPLICATION_FORM_URLENCODED.withCharset(UTF_8); } contentTypes.put(name, type); if (!hasFile && file) { hasFile = true; } return this; }
public MultipartBody field(String name, Object value, boolean file, String contentType) { List<Object> list = parameters.get(name); if (list == null) list = new LinkedList<Object>(); list.add(value); parameters.put(name, list); ContentType type = null; if (contentType != null && contentType.length() > 0) { type = ContentType.parse(contentType); } else if (file) { type = ContentType.APPLICATION_OCTET_STREAM; } else { type = ContentType.APPLICATION_FORM_URLENCODED.withCharset(UTF_8); } contentTypes.put(name, type); if (!hasFile && file) { hasFile = true; } return this; }
private ContentType receiveWithCharsetParameter(ContentType contentType, Charset charset) { if (contentType.getCharset() != null) { return contentType; } final String mimeType = contentType.getMimeType(); if (mimeType.equals(ContentType.TEXT_PLAIN.getMimeType()) || AbstractFutureCallback.ODATA_MIME_TYPE.matcher(mimeType).matches()) { return contentType.withCharset(charset); } return contentType; }
private ContentType receiveWithCharsetParameter(ContentType contentType, Charset charset) { if (contentType.getCharset() != null) { return contentType; } final String mimeType = contentType.getMimeType(); if (mimeType.equals(ContentType.TEXT_PLAIN.getMimeType()) || AbstractFutureCallback.ODATA_MIME_TYPE.matcher(mimeType).matches()) { return contentType.withCharset(charset); } return contentType; }
public ContentType buildContentType() { ContentType parsedContentType = null; if (StringUtils.isNotBlank(contentType)) { try { parsedContentType = ContentType.parse(contentType); } catch (ParseException | UnsupportedCharsetException e) { throw new IllegalArgumentException("Could not parse input '" + HttpClientInputs.CONTENT_TYPE + "'. " + e.getMessage(), e); } if (!StringUtils.isEmpty(requestCharacterSet)) { try { parsedContentType = parsedContentType.withCharset(requestCharacterSet); } catch (UnsupportedCharsetException e) { throw new IllegalArgumentException("Could not parse input '" + HttpClientInputs.REQUEST_CHARACTER_SET + "'. " + e.getMessage(), e); } } } return parsedContentType; } }
private ContentType getContentType(Request request) { ContentType contentType = ContentType.DEFAULT_TEXT; for (Map.Entry<String, Collection<String>> entry : request.headers().entrySet()) if (entry.getKey().equalsIgnoreCase("Content-Type")) { Collection<String> values = entry.getValue(); if (values != null && !values.isEmpty()) { contentType = ContentType.parse(values.iterator().next()); if (contentType.getCharset() == null) { contentType = contentType.withCharset(request.charset()); } break; } } return contentType; }
public ContentType buildContentType() { ContentType parsedContentType = null; if (StringUtils.isNotBlank(contentType)) { try { parsedContentType = ContentType.parse(contentType); } catch (ParseException | UnsupportedCharsetException e) { throw new IllegalArgumentException("Could not parse input '" + HttpClientInputs.CONTENT_TYPE + "'. " + e.getMessage(), e); } if (!StringUtils.isEmpty(requestCharacterSet)) { try { parsedContentType = parsedContentType.withCharset(requestCharacterSet); } catch (UnsupportedCharsetException e) { throw new IllegalArgumentException("Could not parse input '" + HttpClientInputs.REQUEST_CHARACTER_SET + "'. " + e.getMessage(), e); } } } return parsedContentType; } }
public ContentType buildContentType() { ContentType parsedContentType = null; if (StringUtils.isNotBlank(contentType)) { try { parsedContentType = ContentType.parse(contentType); } catch (ParseException | UnsupportedCharsetException e) { throw new IllegalArgumentException("Could not parse input '" + HttpClientInputs.CONTENT_TYPE + "'. " + e.getMessage(), e); } if (!StringUtils.isEmpty(requestCharacterSet)) { try { parsedContentType = parsedContentType.withCharset(requestCharacterSet); } catch (UnsupportedCharsetException e) { throw new IllegalArgumentException("Could not parse input '" + HttpClientInputs.REQUEST_CHARACTER_SET + "'. " + e.getMessage(), e); } } } return parsedContentType; } }
public ContentType buildContentType() { ContentType parsedContentType = null; if (StringUtils.isNotBlank(contentType)) { try { parsedContentType = ContentType.parse(contentType); } catch (ParseException | UnsupportedCharsetException e) { throw new IllegalArgumentException("Could not parse input '" + HttpClientInputs.CONTENT_TYPE + "'. " + e.getMessage(), e); } if (!StringUtils.isEmpty(requestCharacterSet)) { try { parsedContentType = parsedContentType.withCharset(requestCharacterSet); } catch (UnsupportedCharsetException e) { throw new IllegalArgumentException("Could not parse input '" + HttpClientInputs.REQUEST_CHARACTER_SET + "'. " + e.getMessage(), e); } } } return parsedContentType; } }
@Override protected NStringEntity createHttpEntity(CachedExchange jbiExchange) { // TODO should we leave the default charset? return new NStringEntity(this.postQuery.createURI(jbiExchange.getUriParameters()), ContentType.APPLICATION_FORM_URLENCODED.withCharset(StandardCharsets.UTF_8)); } }
private HttpEntity getHttpEntity(Object content) throws UnsupportedCharsetException, JAXBException { String xml = xmlHelper.objectToXml(content); LOGGER.debug("xml = " + xml); ContentType contentType = ContentType.APPLICATION_XML.withCharset(StandardCharsets.UTF_8); return new StringEntity(xml, contentType); }
private BatchQueryPart createBatchQueryPart(UriInfoWithType uriInfo, Olingo2BatchQueryRequest batchRequest) { final Map<String, String> headers = new HashMap<>(batchRequest.getHeaders()); final ContentType contentType = getResourceContentType(uriInfo); final Charset charset = contentType.getCharset(); if (!headers.containsKey(HttpHeaders.ACCEPT)) { // Olingo is sensitive to batch part charset case!! headers.put(HttpHeaders.ACCEPT, contentType.withCharset("").toString().toLowerCase()); } if (!headers.containsKey(HttpHeaders.ACCEPT_CHARSET) && (null != charset)) { headers.put(HttpHeaders.ACCEPT_CHARSET, charset.name().toLowerCase()); } return BatchQueryPart.method("GET") .uri(createBatchUri(batchRequest)) .headers(headers) .build(); }
@Override public IMessage sendFiles(String content, boolean tts, EmbedObject embed, AttachmentPartEntry... entries) { PermissionUtils.requirePermissions(this, client.getOurUser(), Permissions.SEND_MESSAGES, Permissions.ATTACH_FILES); try { MultipartEntityBuilder builder = MultipartEntityBuilder.create(); if (entries.length == 1) { builder.addBinaryBody("file", entries[0].getFileData(), ContentType.APPLICATION_OCTET_STREAM, entries[0].getFileName()); } else { for (int i = 0; i < entries.length; i++) { builder.addBinaryBody("file" + i, entries[i].getFileData(), ContentType.APPLICATION_OCTET_STREAM, entries[i].getFileName()); } } builder.addTextBody("payload_json", DiscordUtils.MAPPER_NO_NULLS.writeValueAsString(new FilePayloadObject(content, tts, embed)), ContentType.MULTIPART_FORM_DATA.withCharset("UTF-8")); HttpEntity fileEntity = builder.build(); MessageObject messageObject = DiscordUtils.MAPPER.readValue(client.REQUESTS.POST.makeRequest(DiscordEndpoints.CHANNELS + id + "/messages", fileEntity, new BasicNameValuePair("Content-Type", "multipart/form-data")), MessageObject.class); return DiscordUtils.getMessageFromJSON(this, messageObject); } catch (IOException e) { throw new DiscordException("JSON Parsing exception!", e); } }
private String getInboundResponseContentType( final HttpEntity entity ) { String fullContentType = null; if( entity != null ) { ContentType entityContentType = ContentType.get( entity ); if( entityContentType != null ) { if( entityContentType.getCharset() == null ) { final String entityMimeType = entityContentType.getMimeType(); final String defaultCharset = MimeTypes.getDefaultCharsetForMimeType( entityMimeType ); if( defaultCharset != null ) { LOG.usingDefaultCharsetForEntity( entityMimeType, defaultCharset ); entityContentType = entityContentType.withCharset( defaultCharset ); } } else { LOG.usingExplicitCharsetForEntity( entityContentType.getMimeType(), entityContentType.getCharset() ); } fullContentType = entityContentType.toString(); } } if( fullContentType == null ) { LOG.unknownResponseEntityContentType(); } else { LOG.inboundResponseEntityContentType( fullContentType ); } return fullContentType; }