try { Part[] parts = {new StringPart(schema.getSchemaName(), schema.toString())}; MultipartRequestEntity requestEntity = new MultipartRequestEntity(parts, new HttpMethodParams()); httpPost.setRequestEntity(requestEntity); int responseCode = HTTP_CLIENT.executeMethod(httpPost);
/** * Returns the MIME boundary string that is used to demarcate boundaries of * this part. The first call to this method will implicitly create a new * boundary string. To create a boundary string first the * HttpMethodParams.MULTIPART_BOUNDARY parameter is considered. Otherwise * a random one is generated. * * @return The boundary string of this entity in ASCII encoding. */ protected byte[] getMultipartBoundary() { if (multipartBoundary == null) { String temp = (String) params.getParameter(HttpMethodParams.MULTIPART_BOUNDARY); if (temp != null) { multipartBoundary = EncodingUtil.getAsciiBytes(temp); } else { multipartBoundary = generateMultipartBoundary(); } } return multipartBoundary; }
public String getContentType() { StringBuffer buffer = new StringBuffer(MULTIPART_FORM_CONTENT_TYPE); buffer.append("; boundary="); buffer.append(EncodingUtil.getAsciiString(getMultipartBoundary())); return buffer.toString(); }
new MultipartRequestEntity(parts, gm.getParams()); if (log.isDebugEnabled()) { entity.writeRequest(System.out); gm.addRequestHeader("content-type", entity.getContentType()); gm.addRequestHeader("content-length", entity.getContentLength() + ""); if (showRequest) { log.info("content-type : " + entity.getContentType() + ", content-length : " + entity.getContentLength());
MultipartRequestEntity multipartRequestEntity = new MultipartRequestEntity( listParts.toArray(new Part[]{}), entityEnclosingMethod.getParams() entityEnclosingMethod.setRequestHeader(STRING_CONTENT_TYPE_HEADER_NAME, multipartRequestEntity.getContentType()); } catch (FileUploadException fileUploadException) { throw new ServletException(fileUploadException);
parts.add(new FilePart(f.getName(), f)); MultipartRequestEntity multipart = new MultipartRequestEntity( parts.toArray(new Part[parts.size()]), new PostMethod().getParams()); multipart.writeRequest(bout);
MultipartRequestEntity mre = createMultipartRequestEntity(bodyCharset, request.getParts(), post.getParams()); post.setRequestEntity(mre); post.setRequestHeader("Content-Type", mre.getContentType()); post.setRequestHeader("Content-Length", String.valueOf(mre.getContentLength())); } else if (request.getFile() != null) { File file = request.getFile();
MultipartRequestEntity multipartRequestEntity = new MultipartRequestEntity( listParts.toArray(new Part[]{}), entityEnclosingMethod.getParams() entityEnclosingMethod.setRequestHeader(STRING_CONTENT_TYPE_HEADER_NAME, multipartRequestEntity.getContentType()); } catch (FileUploadException fileUploadException) { throw new ServletException(fileUploadException);
public static PostMethod sendMultipartPostRequest(String url, String body) throws IOException { HttpClient httpClient = new HttpClient(); PostMethod postMethod = new PostMethod(url); // our handlers ignore key...so we can put anything here Part[] parts = {new StringPart("body", body)}; postMethod.setRequestEntity(new MultipartRequestEntity(parts, postMethod.getParams())); httpClient.executeMethod(postMethod); return postMethod; }
public long getContentLength() { try { return Part.getLengthOfParts(parts, getMultipartBoundary()); } catch (Exception e) { log.error("An exception occurred while getting the length of the parts", e); return 0; } }
/** * Returns the MIME boundary string that is used to demarcate boundaries of * this part. The first call to this method will implicitly create a new * boundary string. To create a boundary string first the * HttpMethodParams.MULTIPART_BOUNDARY parameter is considered. Otherwise * a random one is generated. * * @return The boundary string of this entity in ASCII encoding. */ protected byte[] getMultipartBoundary() { if (multipartBoundary == null) { String temp = (String) params.getParameter(HttpMethodParams.MULTIPART_BOUNDARY); if (temp != null) { multipartBoundary = EncodingUtil.getAsciiBytes(temp); } else { multipartBoundary = generateMultipartBoundary(); } } return multipartBoundary; }
public static PutMethod sendMultipartPutRequest(String url, String body) throws IOException { HttpClient httpClient = new HttpClient(); PutMethod putMethod = new PutMethod(url); // our handlers ignore key...so we can put anything here Part[] parts = {new StringPart("body", body)}; putMethod.setRequestEntity(new MultipartRequestEntity(parts, putMethod.getParams())); httpClient.executeMethod(putMethod); return putMethod; } }
public void writeRequest(OutputStream out) throws IOException { Part.sendParts(out, parts, getMultipartBoundary()); }
/** * Returns the MIME boundary string that is used to demarcate boundaries of * this part. The first call to this method will implicitly create a new * boundary string. To create a boundary string first the * HttpMethodParams.MULTIPART_BOUNDARY parameter is considered. Otherwise * a random one is generated. * * @return The boundary string of this entity in ASCII encoding. */ protected byte[] getMultipartBoundary() { if (multipartBoundary == null) { String temp = (String) params.getParameter(HttpMethodParams.MULTIPART_BOUNDARY); if (temp != null) { multipartBoundary = EncodingUtil.getAsciiBytes(temp); } else { multipartBoundary = generateMultipartBoundary(); } } return multipartBoundary; }
private RequestEntity configureMultipartFileUpload(HttpMethod m, final RestRequest request, RequestEntity requestEntity, Map<String, RestMultipart> multipartFiles) { MultipartRequestEntity multipartRequestEntity = null; // Current File Name reading for tracking missing file String fileName = null; List<Part> fileParts = new ArrayList<Part>(multipartFiles.size()); // Read File Part for (Map.Entry<String, RestMultipart> multipartFile : multipartFiles.entrySet()) { Part filePart = createMultipart(multipartFile.getKey(), multipartFile.getValue()); fileParts.add(filePart); } Part[] parts = fileParts.toArray(new Part[fileParts.size()]); multipartRequestEntity = new MultipartRequestEntity(parts, ((EntityEnclosingMethod) m).getParams()); return multipartRequestEntity; }
public String getContentType() { StringBuffer buffer = new StringBuffer(MULTIPART_FORM_CONTENT_TYPE); buffer.append("; boundary="); buffer.append(EncodingUtil.getAsciiString(getMultipartBoundary())); return buffer.toString(); }
/** * Returns the MIME boundary string that is used to demarcate boundaries of * this part. The first call to this method will implicitly create a new * boundary string. To create a boundary string first the * HttpMethodParams.MULTIPART_BOUNDARY parameter is considered. Otherwise * a random one is generated. * * @return The boundary string of this entity in ASCII encoding. */ protected byte[] getMultipartBoundary() { if (multipartBoundary == null) { String temp = (String) params.getParameter(HttpMethodParams.MULTIPART_BOUNDARY); if (temp != null) { multipartBoundary = EncodingUtil.getAsciiBytes(temp); } else { multipartBoundary = generateMultipartBoundary(); } } return multipartBoundary; }
PostMethod getJsonUrlRequest() { PostMethod request = new PostMethod(getJsonUrl(this.packId)); List<Part> parts = new ArrayList<Part>(); for (NameValuePair part : this.stringParams.values()) { parts.add(new StringPart(part.getName(), part.getValue(), getCharset().name())); } for (Part part : this.fileParams.values()) { parts.add(part); } request.setRequestEntity(new MultipartRequestEntity(parts.toArray(new Part[parts.size()]), request.getParams())); return request; }
public long getContentLength() { try { return Part.getLengthOfParts(parts, getMultipartBoundary()); } catch (Exception e) { log.error("An exception occurred while getting the length of the parts", e); return 0; } }
/** * Returns the MIME boundary string that is used to demarcate boundaries of * this part. The first call to this method will implicitly create a new * boundary string. To create a boundary string first the * HttpMethodParams.MULTIPART_BOUNDARY parameter is considered. Otherwise * a random one is generated. * * @return The boundary string of this entity in ASCII encoding. */ protected byte[] getMultipartBoundary() { if (multipartBoundary == null) { String temp = (String) params.getParameter(HttpMethodParams.MULTIPART_BOUNDARY); if (temp != null) { multipartBoundary = EncodingUtil.getAsciiBytes(temp); } else { multipartBoundary = generateMultipartBoundary(); } } return multipartBoundary; }