List of usage examples for org.apache.http.protocol HTTP DEFAULT_PROTOCOL_CHARSET
String DEFAULT_PROTOCOL_CHARSET
To view the source code for org.apache.http.protocol HTTP DEFAULT_PROTOCOL_CHARSET.
Click Source Link
From source file:com.strato.hidrive.api.utils.multipart.StreamPart.java
public StreamPart(String name, InputStream stream, long streamLength, String filename, String contentType) { this.stream = stream; this.streamLength = streamLength; final String partName = UrlEncodingHelper.encode(name, HTTP.DEFAULT_PROTOCOL_CHARSET); final String partFilename = UrlEncodingHelper.encode(filename, HTTP.DEFAULT_PROTOCOL_CHARSET); final String partContentType = (contentType == null) ? HTTP.DEFAULT_CONTENT_TYPE : contentType; headersProvider = new IHeadersProvider() { public String getContentDisposition() { return "Content-Disposition: form-data; name=\"" + partName //$NON-NLS-1$ + "\"; filename=\"" + partFilename + '"'; //$NON-NLS-1$ }// w w w. ja v a2s. c o m public String getContentType() { return "Content-Type: " + partContentType; //$NON-NLS-1$ } public String getContentTransferEncoding() { return "Content-Transfer-Encoding: binary"; //$NON-NLS-1$ } }; }
From source file:com.cloudbase.CBStringPart.java
/** * @param name String - name of parameter (may not be <code>null</code>). * @param value String - value of parameter (may not be <code>null</code>). * @param charset String, if null is passed then default "ISO-8859-1" charset is used. * /*w w w . ja v a 2s. c o m*/ * @throws IllegalArgumentException if either <code>value</code> * or <code>name</code> is <code>null</code>. * @throws RuntimeException if <code>charset</code> is unsupported by OS. */ public CBStringPart(String name, String value, String charset) { if (name == null) { throw new IllegalArgumentException("Name may not be null"); //$NON-NLS-1$ } if (value == null) { throw new IllegalArgumentException("Value may not be null"); //$NON-NLS-1$ } final String partName = CBUrlEncodingHelper.encode(name, HTTP.DEFAULT_PROTOCOL_CHARSET); if (charset == null) { charset = HTTP.DEFAULT_CONTENT_CHARSET; } final String partCharset = charset; try { this.valueBytes = value.getBytes(partCharset); } catch (UnsupportedEncodingException e) { throw new RuntimeException(e); } headersProvider = new IHeadersProvider() { public String getContentDisposition() { return "Content-Disposition: form-data; name=\"" + partName + '"'; //$NON-NLS-1$ } public String getContentType() { return "Content-Type: " + HTTP.PLAIN_TEXT_TYPE + HTTP.CHARSET_PARAM + partCharset; //$NON-NLS-1$ } public String getContentTransferEncoding() { return "Content-Transfer-Encoding: 8bit"; //$NON-NLS-1$ } }; }
From source file:com.strato.hidrive.api.utils.multipart.StringPart.java
/** * @param name/*from ww w. j a v a 2 s. c o m*/ * String - name of parameter (may not be <code>null</code>). * @param value * String - value of parameter (may not be <code>null</code>). * @param charset * String, if null is passed then default "ISO-8859-1" charset is * used. * * @throws IllegalArgumentException * if either <code>value</code> or <code>name</code> is * <code>null</code>. * @throws RuntimeException * if <code>charset</code> is unsupported by OS. */ public StringPart(String name, String value, String charset) { if (name == null) { throw new IllegalArgumentException("Name may not be null"); //$NON-NLS-1$ } if (value == null) { throw new IllegalArgumentException("Value may not be null"); //$NON-NLS-1$ } final String partName = UrlEncodingHelper.encode(name, HTTP.DEFAULT_PROTOCOL_CHARSET); if (charset == null) { charset = HTTP.DEFAULT_CONTENT_CHARSET; } final String partCharset = charset; try { this.valueBytes = value.getBytes(partCharset); } catch (UnsupportedEncodingException e) { throw new RuntimeException(e); } headersProvider = new IHeadersProvider() { public String getContentDisposition() { return "Content-Disposition: form-data; name=\"" + partName + '"'; //$NON-NLS-1$ } public String getContentType() { return "Content-Type: " + HTTP.PLAIN_TEXT_TYPE + HTTP.CHARSET_PARAM + partCharset; //$NON-NLS-1$ } public String getContentTransferEncoding() { return "Content-Transfer-Encoding: 8bit"; //$NON-NLS-1$ } }; }
From source file:com.cloudbase.CBFilePart.java
/** * @param name String - name of parameter (may not be <code>null</code>). * @param file File (may not be <code>null</code>). * @param filename String. If <code>null</code> is passed, * then <code>file.getName()</code> is used. * @param contentType String. If <code>null</code> is passed, * then default "application/octet-stream" is used. * /*from w ww. j a v a 2s . c o m*/ * @throws IllegalArgumentException if either <code>file</code> * or <code>name</code> is <code>null</code>. */ public CBFilePart(String name, File file, String filename, String contentType) { if (file == null) { throw new IllegalArgumentException("File may not be null"); //$NON-NLS-1$ } if (name == null) { throw new IllegalArgumentException("Name may not be null"); //$NON-NLS-1$ } this.file = file; final String partName = CBUrlEncodingHelper.encode(name, HTTP.DEFAULT_PROTOCOL_CHARSET); final String partFilename = CBUrlEncodingHelper.encode((filename == null) ? file.getName() : filename, HTTP.DEFAULT_PROTOCOL_CHARSET); final String partContentType = (contentType == null) ? HTTP.DEFAULT_CONTENT_TYPE : contentType; headersProvider = new IHeadersProvider() { public String getContentDisposition() { return "Content-Disposition: form-data; name=\"" + partName //$NON-NLS-1$ + "\"; filename=\"" + partFilename + '"'; //$NON-NLS-1$ } public String getContentType() { return "Content-Type: " + partContentType; //$NON-NLS-1$ } public String getContentTransferEncoding() { return "Content-Transfer-Encoding: binary"; //$NON-NLS-1$ } }; }
From source file:ro.zg.netcell.datasources.executors.http.HttpCommandExecutor.java
public HttpCommandResponse executeCommand(CommandContext commandContext) throws Exception { HttpClient httpClient = (HttpClient) commandContext.getConnectionManager().getConnection(); ScriptDaoCommand command = commandContext.getCommand(); String method = (String) command.getArgument("method"); String url = (String) command.getArgument("url"); /* encode the url passed on the http request */ // URI requestUri = new URI(url); // requestUri = URIUtils.createURI(requestUri.getScheme(), requestUri.getHost(), requestUri.getPort(), // requestUri.getPath(), URLEncoder.encode(requestUri.getQuery(),HTTP.DEFAULT_PROTOCOL_CHARSET), // requestUri.getFragment()); String encodedUrl = URLEncoder.encode(url, HTTP.DEFAULT_PROTOCOL_CHARSET); boolean returnHeaders = false; Object rh = command.getArgument("returnHeaders"); if (rh != null) { returnHeaders = (Boolean) rh; }//from w ww. j a va2 s . c om HttpRequestBase request = null; if ("GET".equals(method)) { request = new HttpGet(encodedUrl); } else if ("POST".equals(method)) { HttpPost post = new HttpPost(encodedUrl); String content = (String) command.getArgument("content"); if (content != null) { post.setEntity(new StringEntity(content)); } request = post; } else if ("HEAD".equals(method)) { request = new HttpHead(encodedUrl); } Map<String, String> requestHeaders = (Map) command.getArgument("requestHeaders"); if (requestHeaders != null) { for (Map.Entry<String, String> entry : requestHeaders.entrySet()) { request.setHeader(entry.getKey(), entry.getValue()); } } HttpContext localContext = new BasicHttpContext(); HttpEntity responseEntity = null; HttpCommandResponse commandResponse = new HttpCommandResponse(); try { HttpResponse response = httpClient.execute(request, localContext); responseEntity = response.getEntity(); StatusLine statusLine = response.getStatusLine(); commandResponse.setStatusCode(statusLine.getStatusCode()); commandResponse.setProtocol(statusLine.getProtocolVersion().getProtocol()); commandResponse.setReasonPhrase(statusLine.getReasonPhrase()); commandResponse.setRequestUrl(url); HttpRequest actualRequest = (HttpRequest) localContext.getAttribute(ExecutionContext.HTTP_REQUEST); HttpHost targetHost = (HttpHost) localContext.getAttribute(ExecutionContext.HTTP_TARGET_HOST); commandResponse.setTargetUrl(targetHost.toURI() + actualRequest.getRequestLine().getUri()); if (returnHeaders) { Map<String, String> headers = new HashMap<String, String>(); for (Header h : response.getAllHeaders()) { headers.put(h.getName().toLowerCase(), h.getValue().toLowerCase()); } commandResponse.setHeaders(headers); } if (responseEntity != null) { long responseLength = responseEntity.getContentLength(); String responseContent = EntityUtils.toString(responseEntity, HTTP.UTF_8); if (responseLength == -1) { responseLength = responseContent.length(); } commandResponse.setLength(responseLength); commandResponse.setContent(responseContent); } } finally { if (responseEntity != null) { responseEntity.consumeContent(); } else { request.abort(); } } return commandResponse; }