List of usage examples for org.apache.http.entity.mime MultipartEntity MultipartEntity
public MultipartEntity()
From source file:bluej.collect.DataCollectorImpl.java
public static void removeClass(Package pkg, final File sourceFile) { final ProjectDetails projDetails = new ProjectDetails(pkg.getProject()); MultipartEntity mpe = new MultipartEntity(); mpe.addPart("source_histories[][source_history_type]", CollectUtility.toBody("file_delete")); mpe.addPart("source_histories[][name]", CollectUtility.toBodyLocal(projDetails, sourceFile)); submitEvent(pkg.getProject(), pkg, EventName.DELETE, new PlainEvent(mpe) { @Override/*w w w . ja v a2s . c o m*/ public MultipartEntity makeData(int sequenceNum, Map<FileKey, List<String>> fileVersions) { // We should remove the old source from the fileVersions hash: fileVersions.remove(new FileKey(projDetails, CollectUtility.toPath(projDetails, sourceFile))); return super.makeData(sequenceNum, fileVersions); } }); }
From source file:org.ow2.proactive_grid_cloud_portal.scheduler.server.SchedulerServiceImpl.java
private MultipartEntity createLoginPasswordSSHKeyMultipart(String login, String pass, String ssh) throws UnsupportedEncodingException { MultipartEntity entity = new MultipartEntity(); entity.addPart("username", new StringBody(login)); entity.addPart("password", new StringBody(pass)); if (ssh != null && !ssh.isEmpty()) { entity.addPart("sshKey", new ByteArrayBody(ssh.getBytes(), MediaType.APPLICATION_OCTET_STREAM, null)); }//from w w w.j a v a2s .c o m return entity; }
From source file:immf.ImodeNetClient.java
/** * imode.net????//from w w w.j a v a2s .co m * * @param mail * @return * @throws IOException */ public synchronized void sendMail(SenderMail mail, boolean forcePlaintext) throws IOException, LoginException { if (this.logined == null) { log.warn("i.net????????"); this.logined = Boolean.FALSE; throw new LoginException("imode.net nologin"); } if (this.logined != null && this.logined == Boolean.FALSE) { try { this.login(); } catch (LoginException e) { throw new IOException("Could not login to imode.net"); } } List<String> inlineFileIdList = new LinkedList<String>(); List<String> attachmentFileIdList = new LinkedList<String>(); if (!forcePlaintext) { // html????? for (SenderAttachment file : mail.getInlineFile()) { String docomoFileId = this.sendAttachFile(inlineFileIdList, true, file.getContentTypeWithoutParameter(), file.getFilename(), file.getData()); file.setDocomoFileId(docomoFileId); } } List<SenderAttachment> attachFiles = mail.getAttachmentFile(); for (SenderAttachment file : attachFiles) { // ? this.sendAttachFile(attachmentFileIdList, false, file.getContentTypeWithoutParameter(), file.getFilename(), file.getData()); } // html?? boolean htmlMail = false; String body = null; if (forcePlaintext) { htmlMail = false; body = mail.getPlainBody(); } else { body = mail.getHtmlBody(true); if (body == null) { htmlMail = false; body = mail.getPlainBody(); } else { htmlMail = true; } } // html??????cid? if (htmlMail) { // (???? <img src="40_... ??) body = HtmlConvert.replaceAllCaseInsenstive(body, "<img src=\"cid:[^>]*>", ""); } log.info("Html " + htmlMail); log.info("body " + body); MultipartEntity multi = new MultipartEntity(); try { multi.addPart("folder.id", new StringBody("0", Charset.forName("UTF-8"))); String mailType = null; if (htmlMail) { mailType = "1"; } else { mailType = "0"; } multi.addPart("folder.mail.type", new StringBody(mailType, Charset.forName("UTF-8"))); // ? int recipient = 0; for (InternetAddress ia : mail.getTo()) { multi.addPart("folder.mail.addrinfo(" + recipient + ").mladdr", new StringBody(ia.getAddress(), Charset.forName("UTF-8"))); multi.addPart("folder.mail.addrinfo(" + recipient + ").type", new StringBody("1", Charset.forName("UTF-8"))); recipient++; } for (InternetAddress ia : mail.getCc()) { multi.addPart("folder.mail.addrinfo(" + recipient + ").mladdr", new StringBody(ia.getAddress(), Charset.forName("UTF-8"))); multi.addPart("folder.mail.addrinfo(" + recipient + ").type", new StringBody("2", Charset.forName("UTF-8"))); recipient++; } for (InternetAddress ia : mail.getBcc()) { multi.addPart("folder.mail.addrinfo(" + recipient + ").mladdr", new StringBody(ia.getAddress(), Charset.forName("UTF-8"))); multi.addPart("folder.mail.addrinfo(" + recipient + ").type", new StringBody("3", Charset.forName("UTF-8"))); recipient++; } if (recipient > 5) { throw new IOException("Too Much Recipient"); } // ?? multi.addPart("folder.mail.subject", new StringBody(Util.reverseReplaceUnicodeMapping(mail.getSubject()), Charset.forName("UTF-8"))); // body = Util.reverseReplaceUnicodeMapping(body); // imode.net?? ?10000Bytes? if (body.getBytes().length > 10000) { // ?byte???????????byte?? log.warn("????????10000byte"); throw new IOException("Too Big Message Body. Max 10000 byte."); } multi.addPart("folder.mail.data", new StringBody(body, Charset.forName("UTF-8"))); if (!attachmentFileIdList.isEmpty()) { // for (int i = 0; i < attachmentFileIdList.size(); i++) { multi.addPart("folder.tmpfile(" + i + ").file(0).id", new StringBody(attachmentFileIdList.get(i), Charset.forName("UTF-8"))); } } // ?????? multi.addPart("iemoji(0).id", new StringBody(Character.toString((char) 0xe709), Charset.forName("UTF-8"))); // e709 = UTF-8?ee89c9? multi.addPart("iemoji(1).id", new StringBody(Character.toString((char) 0xe6f0), Charset.forName("UTF-8"))); // e6f0 = UTF-8?ee9bb0? multi.addPart("reqtype", new StringBody("0", Charset.forName("UTF-8"))); HttpPost post = new HttpPost(SendMailUrl); try { addDumyHeader(post); post.setEntity(multi); HttpResponse res = this.executeHttp(post); if (!isJson(res)) { log.warn("?JSON??????"); if (res != null) { // JSON????????????????? log.debug(toStringBody(res)); this.logined = Boolean.FALSE; throw new LoginException("Bad response. no json format."); } else { throw new IOException("imode.net not responding. Try later."); } } JSONObject json = JSONObject.fromObject(toStringBody(res)); String result = json.getJSONObject("common").getString("result"); if (result.equals("PW1409")) { // ???? this.logined = Boolean.FALSE; throw new IOException("PW1409 - session terminated because of your bad mail."); } else if (result.equals("PW1430")) { // ??? throw new IOException("PW1430 - User Unknown."); } else if (result.equals("PW1436")) { // ????? JSONArray jsonaddrs = json.getJSONObject("data").getJSONArray("seaddr"); String addrs = ""; for (int i = 0; i < jsonaddrs.size(); i++) { if (i > 0) { addrs += ", "; } addrs += jsonaddrs.getString(i); } throw new IOException("PW1436 - User Unknown.: " + addrs); } else if (!result.equals("PW1000")) { log.debug(json.toString(2)); throw new IOException("Bad response " + result); } } finally { post.abort(); log.info("??"); } } catch (UnsupportedEncodingException e) { log.fatal(e); } }
From source file:bluej.collect.DataCollectorImpl.java
public static void ConvertStrideToJava(Package pkg, File sourceFile) { final ProjectDetails projDetails = new ProjectDetails(pkg.getProject()); MultipartEntity mpe = new MultipartEntity(); mpe.addPart("source_histories[][source_history_type]", CollectUtility.toBody("stride_converted_to_java")); mpe.addPart("source_histories[][name]", CollectUtility.toBodyLocal(projDetails, sourceFile)); submitEvent(pkg.getProject(), pkg, EventName.CONVERT_TO_JAVA, new PlainEvent(mpe) { @Override/*w w w .j a v a2s .c o m*/ public MultipartEntity makeData(int sequenceNum, Map<FileKey, List<String>> fileVersions) { return super.makeData(sequenceNum, fileVersions); } }); }
From source file:project.cs.lisa.netinf.node.resolution.NameResolutionService.java
/** * Creates an HTTP POST representation of a NetInf PUBLISH message. * @param io/* w ww . j a va 2 s. co m*/ * The information object to publish * @return * A HttpPost representing the NetInf PUBLISH message * @throws UnsupportedEncodingException * In case the encoding is not supported */ private HttpPost createPublish(InformationObject io) throws UnsupportedEncodingException { Log.d(TAG, "createPublish()"); // Extracting values from IO's identifier String hashAlg = getHashAlg(io.getIdentifier()); String hash = getHash(io.getIdentifier()); String contentType = getContentType(io.getIdentifier()); String meta = getMetadata(io.getIdentifier()); String bluetoothMac = getBluetoothMac(io); String filePath = getFilePath(io); HttpPost post = new HttpPost(mHost + ":" + mPort + "/netinfproto/publish"); MultipartEntity entity = new MultipartEntity(); StringBody uri = new StringBody("ni:///" + hashAlg + ";" + hash + "?ct=" + contentType); entity.addPart("URI", uri); StringBody msgid = new StringBody(Integer.toString(mRandomGenerator.nextInt(MSG_ID_MAX))); entity.addPart("msgid", msgid); if (bluetoothMac != null) { StringBody l = new StringBody(bluetoothMac); entity.addPart("loc1", l); } if (meta != null) { StringBody ext = new StringBody(meta.toString()); entity.addPart("ext", ext); } if (filePath != null) { StringBody fullPut = new StringBody("true"); entity.addPart("fullPut", fullPut); FileBody octets = new FileBody(new File(filePath)); entity.addPart("octets", octets); } StringBody rform = new StringBody("json"); entity.addPart("rform", rform); try { entity.writeTo(System.out); } catch (IOException e) { Log.e(TAG, "Failed to write MultipartEntity to System.out"); } post.setEntity(entity); return post; }
From source file:bluej.collect.DataCollectorImpl.java
public static void addClass(Package pkg, File sourceFile) { final MultipartEntity mpe = new MultipartEntity(); final ProjectDetails projDetails = new ProjectDetails(pkg.getProject()); final String contents = CollectUtility.readFileAndAnonymise(projDetails, sourceFile); mpe.addPart("project[source_files][][name]", CollectUtility.toBodyLocal(projDetails, sourceFile)); mpe.addPart("source_histories[][source_history_type]", CollectUtility.toBody("complete")); mpe.addPart("source_histories[][name]", CollectUtility.toBodyLocal(projDetails, sourceFile)); mpe.addPart("source_histories[][content]", CollectUtility.toBody(contents)); final FileKey key = new FileKey(projDetails, CollectUtility.toPath(projDetails, sourceFile)); submitEvent(pkg.getProject(), pkg, EventName.ADD, new Event() { @Override// w ww . j a va 2 s . co m public void success(Map<FileKey, List<String>> fileVersions) { fileVersions.put(key, Arrays.asList(Utility.splitLines(contents))); } @Override public MultipartEntity makeData(int sequenceNum, Map<FileKey, List<String>> fileVersions) { return mpe; } }); }
From source file:de.geomobile.joined.api.service.JOWebService.java
/** * Activate or deactivate user/*w w w .j a va 2 s. c o m*/ * * @param userId * The users id. * * @param secureToken * The users secureToken. * @param active * active or deactive * @throws JOFriendFinderUnexpectedException * @throws JOFriendFinderServerException * @throws JOFriendFinderHTTPException */ public void activateUser(String userId, String secureToken, boolean active) throws JOFriendFinderUnexpectedException, JOFriendFinderServerException, JOFriendFinderHTTPException { try { HttpClient httpClient = getNewHttpClient(); HttpPut httpput = new HttpPut(getJoinedServerUrl() + JOConfig.FF_FRIENDS + "/" + userId); httpput.addHeader(getAuthenticationHeader(userId, secureToken)); MultipartEntity entity = new MultipartEntity(); entity.addPart(JOConfig.IS_ACTIVE, new StringBody(String.valueOf(active), Charset.forName(JOConfig.UTF_8))); httpput.setEntity(entity); HttpResponse httpResponse = httpClient.execute(httpput); if (httpResponse.getStatusLine().getStatusCode() == HttpStatus.SC_INTERNAL_SERVER_ERROR) { throw new JOFriendFinderServerException(); } else if (httpResponse.getStatusLine().getStatusCode() != HttpStatus.SC_NO_CONTENT) { throw new JOFriendFinderUnexpectedException( "HTTP Error Code " + httpResponse.getStatusLine().getStatusCode()); } } catch (UnsupportedEncodingException e) { throw new JOFriendFinderUnexpectedException(e); } catch (ClientProtocolException e) { throw new JOFriendFinderHTTPException(e); } catch (IOException e) { throw new JOFriendFinderHTTPException(e); } }
From source file:com.parworks.androidlibrary.ar.ARSiteImpl.java
public String startImageAugment(InputStream image, boolean withCD) { handleStateSync(mId, State.READY_TO_AUGMENT_IMAGES); Map<String, String> params = new HashMap<String, String>(); params.put("site", mId); params.put("withCD", Boolean.toString(withCD)); MultipartEntity imageEntity = new MultipartEntity(); InputStreamBody imageInputStreamBody = new InputStreamBody(image, "image"); imageEntity.addPart("image", imageInputStreamBody); HttpUtils httpUtils = new HttpUtils(mApiKey, mTime, mSignature); HttpResponse serverResponse = httpUtils .doPost(HttpUtils.PARWORKS_API_BASE_URL + HttpUtils.AUGMENT_IMAGE_PATH, imageEntity, params); HttpUtils.handleStatusCode(serverResponse.getStatusLine().getStatusCode()); ARResponseHandler responseHandler = new ARResponseHandlerImpl(); AugmentImageResponse augmentImageResponse = responseHandler.handleResponse(serverResponse, AugmentImageResponse.class); if (augmentImageResponse.getSuccess() == false) { throw new ARException( "Successfully communicated with the server, failed to augment the image. Perhaps the site does not exist or has no overlays."); }//from w w w . j av a 2 s. co m return augmentImageResponse.getImgId(); }