List of usage examples for org.apache.http.entity.mime MultipartEntity addPart
public void addPart(final String name, final ContentBody contentBody)
From source file:org.opencastproject.remotetest.server.resource.IngestResources.java
public static HttpResponse addZippedMediaPackage(TrustedHttpClient client, InputStream mediaPackage) throws Exception { HttpPost post = new HttpPost(getServiceUrl() + "addZippedMediaPackage"); MultipartEntity entity = new MultipartEntity(); entity.addPart("mediaPackage", new InputStreamBody(mediaPackage, "mediapackage.zip")); post.setEntity(entity);/*from ww w . j a va 2 s . co m*/ return client.execute(post); }
From source file:org.opencastproject.remotetest.server.resource.IngestResources.java
/** * // w ww. j a v a 2 s . c o m * @param type * Type of media to add: Track, Catalog, Attachment * */ public static HttpResponse addTrack(TrustedHttpClient client, String type, InputStream media, String flavor, String mediaPackage) throws Exception { HttpPost post = new HttpPost(getServiceUrl() + "add" + type); MultipartEntity entity = new MultipartEntity(); entity.addPart("flavor", new StringBody(flavor)); entity.addPart("mediaPackage", new StringBody(mediaPackage)); post.setEntity(entity); return client.execute(post); }
From source file:at.uni_salzburg.cs.ckgroup.cscpp.utils.HttpQueryUtils.java
public static String[] fileUpload(String uploadUrl, String name, byte[] byteArray) throws IOException { HttpClient httpclient = new DefaultHttpClient(); HttpPost httppost = new HttpPost(uploadUrl); String paramName = "vehicle"; String paramValue = name;/*from w w w . j av a2 s . co m*/ MultipartEntity entity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE); entity.addPart(paramName, new InputStreamBody((new ByteArrayInputStream(byteArray)), "application/zip")); entity.addPart(paramName, new StringBody(paramValue, "text/plain", Charset.forName("UTF-8"))); httppost.setEntity(entity); HttpResponse httpResponse = httpclient.execute(httppost); StatusLine statusLine = httpResponse.getStatusLine(); String reason = statusLine.getReasonPhrase(); int rc = statusLine.getStatusCode(); String response = EntityUtils.toString(httpResponse.getEntity(), "UTF-8"); httpclient.getConnectionManager().shutdown(); return new String[] { String.valueOf(rc), reason, response }; }
From source file:niclients.main.pubni.java
/** * Creates NI publish HTTP POST signal.//from w w w . j a va2s . c o m * * @return boolean true/false in success/failure * @throws UnsupportedEncodingException */ static boolean createpub() throws UnsupportedEncodingException { post = new HttpPost(fqdn + "/.well-known/netinfproto/publish"); ContentBody url = new StringBody(niname); ContentBody msgid = new StringBody(Integer.toString(randomGenerator.nextInt(100000000))); ContentBody fullPut = new StringBody("yes"); ContentBody ext = new StringBody("no extension"); ContentBody bin = new FileBody(new File(filename)); MultipartEntity reqEntity = new MultipartEntity(); reqEntity.addPart("octets", bin); reqEntity.addPart("URI", url); reqEntity.addPart("msgid", msgid); reqEntity.addPart("fullPut", fullPut); reqEntity.addPart("ext", ext); post.setEntity(reqEntity); return true; }
From source file:com.waku.mmdataextract.ComprehensiveSearch.java
@SuppressWarnings("deprecation") private static MultipartEntity getMultipartEntity(String brandId, int pageNumber) { MultipartEntity reqEntity = new MultipartEntity(); try {// ww w . j a v a2 s .c o m reqEntity.addPart("flag", new StringBody("search")); reqEntity.addPart("brandId", new StringBody(brandId)); reqEntity.addPart("currentPage", new StringBody(pageNumber + "")); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } return reqEntity; }
From source file:hpcc.hut.edu.vn.ocr.ocrserviceconnector.HpccOcrServiceConnector.java
public static String postToOcrService(byte[] data, int size, int imgw, int imgh, String lang, int psm, boolean isPrePostProcess) { System.out.println("Sent data: w = " + imgw + ", h = " + imgh + ", psm = " + psm + ", process: " + isPrePostProcess + ", with lang: " + lang); String result = ""; try {//from ww w .jav a 2 s. c om HttpParams httpParamenters = new BasicHttpParams(); HttpConnectionParams.setConnectionTimeout(httpParamenters, 30000); DefaultHttpClient httpClient = new DefaultHttpClient(httpParamenters); HttpPost postRequest = new HttpPost(HOST); ByteArrayBody bab = new ByteArrayBody(data, "input.jpg"); MultipartEntity reqEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE); reqEntity.addPart("image", bab); reqEntity.addPart("size", new StringBody("" + size)); // size to // check if // decompress // fail reqEntity.addPart("width", new StringBody("" + imgw)); reqEntity.addPart("height", new StringBody("" + imgh)); reqEntity.addPart("lang", new StringBody(lang)); reqEntity.addPart("psm", new StringBody("" + psm)); reqEntity.addPart("process", new StringBody("" + isPrePostProcess)); postRequest.setEntity(reqEntity); HttpResponse response = httpClient.execute(postRequest); BufferedReader reader = new BufferedReader( new InputStreamReader(response.getEntity().getContent(), "UTF-8")); String sResponse; StringBuilder s = new StringBuilder(); while ((sResponse = reader.readLine()) != null) { s = s.append(sResponse); } result = s.toString(); System.out.println("result in Json: " + result); } catch (Exception e) { // handle exception here Log.e(e.getClass().getName(), e.getMessage()); return null; } return result; }
From source file:net.ccghe.utils.Server.java
public static void UploadFile(String path, FileTransmitter transmitter) { MultipartEntity entity = new MultipartEntity(); try {/* w w w .ja v a 2 s . c om*/ entity.addPart("usr", new StringBody(user)); entity.addPart("pwd", new StringBody(password)); entity.addPart("cmd", new StringBody(CMD_UPLOAD_FILE)); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } new UploadOneFile(path, serverURL, transmitter, entity); }
From source file:uk.ac.diamond.scisoft.feedback.FeedbackRequest.java
/** * Method used to submit a form data/file through HTTP to a GAE servlet * // www .j a v a 2 s. co m * @param email * @param to * @param name * @param subject * @param messageBody * @param attachmentFiles * @param monitor */ public static IStatus doRequest(String email, String to, String name, String subject, String messageBody, List<File> attachmentFiles, IProgressMonitor monitor) throws Exception { Status status = null; DefaultHttpClient httpclient = new DefaultHttpClient(); FeedbackProxy.init(); host = FeedbackProxy.getHost(); port = FeedbackProxy.getPort(); if (monitor.isCanceled()) return Status.CANCEL_STATUS; // if there is a proxy if (host != null) { HttpHost proxy = new HttpHost(host, port); httpclient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy); } if (monitor.isCanceled()) return Status.CANCEL_STATUS; try { HttpPost httpost = new HttpPost(SERVLET_URL + SERVLET_NAME); MultipartEntity entity = new MultipartEntity(); entity.addPart("name", new StringBody(name)); entity.addPart("email", new StringBody(email)); entity.addPart("to", new StringBody(to)); entity.addPart("subject", new StringBody(subject)); entity.addPart("message", new StringBody(messageBody)); // add attachement files to the multipart entity for (int i = 0; i < attachmentFiles.size(); i++) { if (attachmentFiles.get(i) != null && attachmentFiles.get(i).exists()) entity.addPart("attachment" + i + ".html", new FileBody(attachmentFiles.get(i))); } if (monitor.isCanceled()) return Status.CANCEL_STATUS; httpost.setEntity(entity); // HttpPost post = new HttpPost("http://dawnsci-feedback.appspot.com/dawnfeedback?name=baha&email=baha@email.com&subject=thisisasubject&message=thisisthemessage"); HttpResponse response = httpclient.execute(httpost); if (monitor.isCanceled()) return Status.CANCEL_STATUS; final String reasonPhrase = response.getStatusLine().getReasonPhrase(); int statusCode = response.getStatusLine().getStatusCode(); if (statusCode == 200) { logger.debug("Status code 200"); status = new Status(IStatus.OK, "Feedback successfully sent", "Thank you for your contribution"); } else { logger.debug("Feedback email not sent - HTTP response: " + reasonPhrase); status = new Status(IStatus.WARNING, "Feedback not sent", "The response from the server is the following:\n" + reasonPhrase + "\nClick on OK to submit your feedback using the online feedback form available at http://dawnsci-feedback.appspot.com/"); } logger.debug("HTTP Response: " + response.getStatusLine()); } finally { // When HttpClient instance is no longer needed, // shut down the connection manager to ensure // immediate deallocation of all system resources httpclient.getConnectionManager().shutdown(); } return status; }
From source file:nl.igorski.lib.utils.network.HTTPTransfer.java
/** * quick wrapper to POST data to a server * * @param aURL {String} URL of the server * @param aParams {List<NameValuePair>} optional list of parameters to send /*from w w w.j a va2 s . co m*/ * @return {HttpResponse} */ public static HttpResponse post(String aURL, List<NameValuePair> aParams) { HttpPost post = new HttpPost(urlEncode(aURL, null)); post.getParams().setBooleanParameter("http.protocol.expect-continue", false); MultipartEntity entity = new MultipartEntity(); for (NameValuePair pair : aParams) { try { entity.addPart(pair.getName(), new StringBodyNoHeaders(pair.getValue())); } catch (UnsupportedEncodingException e) { } } post.setEntity(entity); HttpResponse out = null; try { out = getClient().execute(post); } catch (Exception e) { } return out; }
From source file:gov.nist.appvet.tool.sigverifier.util.ReportUtil.java
/** This method should be used for sending files back to AppVet. */ public static boolean sendInNewHttpRequest(String appId, String reportFilePath, ToolStatus reportStatus) { HttpParams httpParameters = new BasicHttpParams(); HttpConnectionParams.setConnectionTimeout(httpParameters, 30000); HttpConnectionParams.setSoTimeout(httpParameters, 1200000); HttpClient httpClient = new DefaultHttpClient(httpParameters); httpClient = SSLWrapper.wrapClient(httpClient); try {/*from w w w . j av a 2 s . c o m*/ /* * To send reports back to AppVet, the following parameters must be * sent: - command: SUBMIT_REPORT - username: AppVet username - * password: AppVet password - appid: The app ID - toolid: The ID of * this tool - toolrisk: The risk assessment (LOW, MODERATE, HIGH, * ERROR) - report: The report file. */ MultipartEntity entity = new MultipartEntity(); entity.addPart("command", new StringBody("SUBMIT_REPORT", Charset.forName("UTF-8"))); entity.addPart("username", new StringBody(Properties.appvetUsername, Charset.forName("UTF-8"))); entity.addPart("password", new StringBody(Properties.appvetPassword, Charset.forName("UTF-8"))); entity.addPart("appid", new StringBody(appId, Charset.forName("UTF-8"))); entity.addPart("toolid", new StringBody(Properties.toolId, Charset.forName("UTF-8"))); entity.addPart("toolrisk", new StringBody(reportStatus.name(), Charset.forName("UTF-8"))); File report = new File(reportFilePath); FileBody fileBody = new FileBody(report); entity.addPart("file", fileBody); HttpPost httpPost = new HttpPost(Properties.appvetUrl); httpPost.setEntity(entity); // Send the report to AppVet log.debug("Sending report file to AppVet"); final HttpResponse response = httpClient.execute(httpPost); log.debug("Received from AppVet: " + response.getStatusLine()); HttpEntity httpEntity = response.getEntity(); InputStream is = httpEntity.getContent(); String result = IOUtils.toString(is, "UTF-8"); log.info(result); // Clean up httpPost = null; return true; } catch (Exception e) { log.error(e.toString()); return false; } }