List of usage examples for org.apache.http.protocol HTTP DEFAULT_CONTENT_TYPE
String DEFAULT_CONTENT_TYPE
To view the source code for org.apache.http.protocol HTTP DEFAULT_CONTENT_TYPE.
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 .j av a2s. co 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.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 . jav a 2 s.c om * @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:com.googlecode.osde.internal.igoogle.IgHostingUtil.java
/** * Uploads a file to iGoogle.// w ww .j a v a 2 s.c o m * * @throws IgException */ public static void uploadFile(IgCredentials igCredentials, String sourceFileRootPath, String sourceFileRelativePath, String hostingFolder) throws IgException { // Prepare HttpPost. String httpPostUrl = URL_IG_GADGETS_FILE + igCredentials.getPublicId() + hostingFolder + sourceFileRelativePath + "?et=" + igCredentials.getEditToken(); logger.fine("httpPostUrl: " + httpPostUrl); HttpPost httpPost = new HttpPost(httpPostUrl); File sourceFile = new File(sourceFileRootPath, sourceFileRelativePath); String httpContentType = isTextExtensionForGadgetFile(sourceFileRelativePath) ? HTTP_PLAIN_TEXT_TYPE : HTTP.DEFAULT_CONTENT_TYPE; httpPost.setHeader(HTTP.CONTENT_TYPE, httpContentType); FileEntity fileEntity = new FileEntity(sourceFile, httpContentType); logger.fine("fileEntity length: " + fileEntity.getContentLength()); httpPost.setEntity(fileEntity); // Add cookie headers. Cookie PREF must be placed before SID. httpPost.addHeader(IgHttpUtil.HTTP_HEADER_COOKIE, "PREF=" + igCredentials.getPref()); httpPost.addHeader(IgHttpUtil.HTTP_HEADER_COOKIE, "SID=" + igCredentials.getSid()); // Execute request. HttpClient httpClient = new DefaultHttpClient(); HttpResponse httpResponse; try { httpResponse = httpClient.execute(httpPost); } catch (ClientProtocolException e) { throw new IgException(e); } catch (IOException e) { throw new IgException(e); } // Verify if the file is created. StatusLine statusLine = httpResponse.getStatusLine(); logger.fine("statusLine: " + statusLine); if (HttpStatus.SC_CREATED != statusLine.getStatusCode()) { String response = IgHttpUtil.retrieveHttpResponseAsString(httpClient, httpPost, httpResponse); throw new IgException("Failed file-upload with status line: " + statusLine.toString() + ",\nand response:\n" + response); } }
From source file:de.aflx.sardine.impl.SardineImpl.java
/** * Upload the entity using <code>PUT</code> * /* w w w. j a v a 2s . com*/ * @param url * Resource * @param entity * The entity to read from * @param headers * Headers to add to request */ public void put(String url, HttpEntity entity, Map<String, String> headers) throws IOException { HttpPut put = new HttpPut(url); _currentRequest = put; _isAborted = false; put.setEntity(entity); for (String header : headers.keySet()) { put.addHeader(header, headers.get(header)); } if (!put.containsHeader("Content-Type")) { put.addHeader("Content-Type", HTTP.DEFAULT_CONTENT_TYPE); } try { this.execute(put, new VoidResponseHandler()); } catch (HttpResponseException e) { if (e.getStatusCode() == HttpStatus.SC_EXPECTATION_FAILED) { // Retry with the Expect header removed put.removeHeaders(HTTP.EXPECT_DIRECTIVE); if (entity.isRepeatable()) { this.execute(put, new VoidResponseHandler()); return; } } throw e; } }
From source file:com.googlecode.sardine.impl.SardineImpl.java
/** * Upload the entity using <code>PUT</code> * //from w w w . j a v a2s. c o m * @param url * Resource * @param entity * The entity to read from * @param headers * Headers to add to request */ public void put(String url, HttpEntity entity, Map<String, String> headers) throws IOException { HttpPut put = new HttpPut(url); put.setEntity(entity); for (String header : headers.keySet()) { put.addHeader(header, headers.get(header)); } if (!put.containsHeader("Content-Type")) { put.addHeader("Content-Type", HTTP.DEFAULT_CONTENT_TYPE); } try { this.execute(put, new VoidResponseHandler()); } catch (HttpResponseException e) { if (e.getStatusCode() == HttpStatus.SC_EXPECTATION_FAILED) { // Retry with the Expect header removed put.removeHeaders(HTTP.EXPECT_DIRECTIVE); if (entity.isRepeatable()) { this.execute(put, new VoidResponseHandler()); return; } } throw e; } }