PutMethod redirectedReq = new PutMethod(redirectedReqString); File localFile = new File(localFilePath); RequestEntity requestEntity = new FileRequestEntity(localFile, "application/binary"); redirectedReq.setRequestEntity(requestEntity);
FileRequestEntity fre = new FileRequestEntity(new File("C://xxx/test.txt"), "text/plain"); post.setRequestEntity(fre); postMethod.setRequestEntity(fre);
private RequestEntity configureFileUpload(String fileName) { final File file = new File(fileName); if (!file.exists()) { throw new IllegalArgumentException("File not found: " + fileName); } return new FileRequestEntity(file, "application/octet-stream"); }
/** * PUTs a File to the given URL. * * @param url The URL where to connect to. * @param file The File to be sent. * @param contentType The content-type to advert in the PUT. * @return The HTTP response as a String if the HTTP response code was 200 (OK). * @throws MalformedURLException * @return the HTTP response or <TT>null</TT> on errors. */ public String put(String url, File file, String contentType) { return put(url, new FileRequestEntity(file, contentType)); }
/** * POSTs a File to the given URL. * * @param url The URL where to connect to. * @param file The File to be sent. * @param contentType The content-type to advert in the POST. * @return The HTTP response as a String if the HTTP response code was 200 (OK). * @throws MalformedURLException * @return the HTTP response or <TT>null</TT> on errors. */ public String post(String url, File file, String contentType) { return post(url, new FileRequestEntity(file, contentType)); }
public InvocationResult invoke( File request, WiseMapper mapper ) { return invoke(new FileRequestEntity(request, produceMediaTypes), mapper); }
/** * POSTs a File to the given URL. <BR> * Basic auth is used if both username and pw are not null. * * @param url The URL where to connect to. * @param file The File to be sent. * @param contentType The content-type to advert in the POST. * @param username Basic auth credential. No basic auth if null. * @param pw Basic auth credential. No basic auth if null. * @return The HTTP response as a String if the HTTP response code was 200 * (OK). * @throws MalformedURLException * @return the HTTP response or <TT>null</TT> on errors. */ public static String post(String url, File file, String contentType, String username, String pw) { return post(url, new FileRequestEntity(file, contentType), username, pw); }
/** * PUTs a File to the given URL. <BR> * Basic auth is used if both username and pw are not null. * * @param url The URL where to connect to. * @param file The File to be sent. * @param contentType The content-type to advert in the PUT. * @param username Basic auth credential. No basic auth if null. * @param pw Basic auth credential. No basic auth if null. * @return The HTTP response as a String if the HTTP response code was 200 * (OK). * @throws MalformedURLException * @return the HTTP response or <TT>null</TT> on errors. */ public static String put(String url, File file, String contentType, String username, String pw) { return put(url, new FileRequestEntity(file, contentType), username, pw); }
protected static void handleRequestData(EntityEnclosingMethod method, Object data) { if (method == null) { throw new IllegalArgumentException("Invalid method, cannot be null"); } if (data != null) { RequestEntity re = null; if (data.getClass().isAssignableFrom(InputStream.class)) { re = new InputStreamRequestEntity((InputStream) data, CONTENT_TYPE_UTF8); } else if (data.getClass().isAssignableFrom(byte[].class)) { re = new ByteArrayRequestEntity((byte[]) data, CONTENT_TYPE_UTF8); } else if (data.getClass().isAssignableFrom(File.class)) { re = new FileRequestEntity((File) data, CONTENT_TYPE_UTF8); } else { // handle as a string try { re = new StringRequestEntity(data.toString(), "text/xml", ENCODING_UTF8); } catch (UnsupportedEncodingException e) { throw new HttpIOException("Encoding data using UTF8 failed :: " + e.getMessage(), e); } } method.setRequestEntity(re); } }
File input = new File(inputFile); PutMethod put = new PutMethod("http://localhost:8181/cxf/crm/customerservice/customers"); RequestEntity entity = new FileRequestEntity(input, "text/xml; charset=ISO-8859-1"); put.setRequestEntity(entity); HttpClient httpclient = new HttpClient(); PostMethod post = new PostMethod("http://localhost:8181/cxf/crm/customerservice/customers"); post.addRequestHeader("Accept" , "text/xml"); entity = new FileRequestEntity(input, "text/xml; charset=ISO-8859-1"); post.setRequestEntity(entity); httpclient = new HttpClient();
File input = new File(inputFile); PutMethod put = new PutMethod("http://localhost:8181/cxf/crm/customerservice/customers"); RequestEntity entity = new FileRequestEntity(input, "text/xml; charset=ISO-8859-1"); put.setRequestEntity(entity); HttpClient httpclient = new HttpClient(); PostMethod post = new PostMethod("http://localhost:8181/cxf/crm/customerservice/customers"); post.addRequestHeader("Accept" , "text/xml"); entity = new FileRequestEntity(input, "text/xml; charset=ISO-8859-1"); post.setRequestEntity(entity); httpclient = new HttpClient();
public void uploadFile(BintrayPackage bintrayPackage, String targetPath, File file, String version, String contentType){ String url = String.format("https://api.bintray.com/content/%s/%s/%s/%s/%s?publish=1", bintrayPackage.getOwner(), bintrayPackage.getRepository(), bintrayPackage.getName(), version, targetPath); PutMethod put = new PutMethod(url); assertAuthorized(); put.addRequestHeader("Authorization", "Basic "+ new String(Base64.encodeBase64((username+":"+password).getBytes()))); put.setRequestEntity(new FileRequestEntity(file, contentType)); try{ new HttpClient().executeMethod(put); validateAuthorizedRequestResult(bintrayPackage.getOwner(), put, 201); } catch (Exception e) { throw new RuntimeException("Failed to upload files to package: "+bintrayPackage.getName(), e); } }
answer = new FileRequestEntity(file, contentType);
public void putInitFile(File script) throws Exception { http().put(server.getServerURL() + "/initfile", null, null, new FileRequestEntity(script, "text/plain"), null); }
public void putScript(String path, File script) throws Exception { http().put(server.getServerURL() + "/scripts/" + path, null, null, new FileRequestEntity(script, "text/plain"), null); }
FileRequestEntity requestEntity = new FileRequestEntity( new File(message.getFilepath()), message.getFiletype()); httppost.setRequestEntity(requestEntity);
FileRequestEntity requestEntity = new FileRequestEntity( new File(message.getFilepath()), message.getFiletype()); httppost.setRequestEntity(requestEntity);