/** * Builder pattern method to add the specified {@link BodyPart} to this * {@link MultiPart}. * * @param bodyPart {@link BodyPart} to be added. */ public MultiPart bodyPart(BodyPart bodyPart) { getBodyParts().add(bodyPart); return this; }
/** * Performs any necessary cleanup at the end of processing this * {@link MultiPart}. */ @Override public void cleanup() { for (BodyPart bp : getBodyParts()) { bp.cleanup(); } }
if ((entity.getBodyParts() == null) || (entity.getBodyParts().size() < 1)) { throw new IllegalArgumentException(LocalizationMessages.MUST_SPECIFY_BODY_PART()); for (final BodyPart bodyPart : entity.getBodyParts()) {
protected final Response getFormPostResponse(String data, String endpoint, Class<? extends OutputStream> compressingClass, String encoding) throws IOException { byte[] bytes; if (compressingClass == null) { bytes = data.getBytes(StandardCharsets.UTF_8); } else { bytes = compress(data, compressingClass); } MediaType type = encoding == null ? MediaType.TEXT_PLAIN_TYPE : new MediaType("application", encoding); InputStream in = new ByteArrayInputStream(bytes); StreamDataBodyPart filePart = new StreamDataBodyPart("data", in, "data", type); try (MultiPart multiPart = new MultiPart(MediaType.MULTIPART_FORM_DATA_TYPE)) { multiPart.getBodyParts().add(filePart); return target(endpoint).request().post( Entity.entity(multiPart, MediaType.MULTIPART_FORM_DATA_TYPE)); } }
multiPart.getBodyParts().add(bodyPart);
@POST @Consumes(MediaType.MULTIPART_FORM_DATA) @Produces(MediaType.APPLICATION_JSON) public void postHotel(MultiPart hotelParams) throws SQLException, FileNotFoundException, IOException { stmt.executeUpdate("insert into hotel(user_name,password)values('" +hotelParams.getBodyParts().get(0) + "','" + hotelParams.getBodyParts().get(1) + "'");
/** * Builder pattern method to add the specified {@link BodyPart} to this * {@link MultiPart}. * * @param bodyPart {@link BodyPart} to be added. */ public MultiPart bodyPart(BodyPart bodyPart) { getBodyParts().add(bodyPart); return this; }
/** * Builder pattern method to add the specified {@link BodyPart} to this * {@link MultiPart}. * * @param bodyPart {@link BodyPart} to be added. */ public MultiPart bodyPart(BodyPart bodyPart) { getBodyParts().add(bodyPart); return this; }
/** * Builder pattern method to add the specified {@link BodyPart} to this * {@link MultiPart}. * * @param bodyPart {@link BodyPart} to be added. */ public MultiPart bodyPart(BodyPart bodyPart) { getBodyParts().add(bodyPart); return this; }
/** * Builder pattern method to add the specified {@link BodyPart} to this * {@link MultiPart}. * * @param bodyPart {@link BodyPart} to be added. */ public MultiPart bodyPart(BodyPart bodyPart) { getBodyParts().add(bodyPart); return this; }
private boolean hasAttachment() { return !attachments.getBodyParts().isEmpty(); }
private boolean hasAttachment() { return !attachments.getBodyParts().isEmpty(); }
/** * Performs any necessary cleanup at the end of processing this * {@link MultiPart}. */ @Override public void cleanup() { for (BodyPart bp : getBodyParts()) { bp.cleanup(); } }
/** * Performs any necessary cleanup at the end of processing this * {@link MultiPart}. */ @Override public void cleanup() { for (BodyPart bp : getBodyParts()) { bp.cleanup(); } }
/** * Performs any necessary cleanup at the end of processing this * {@link MultiPart}. */ @Override public void cleanup() { for (BodyPart bp : getBodyParts()) { bp.cleanup(); } }
/** * Performs any necessary cleanup at the end of processing this * {@link MultiPart}. */ @Override public void cleanup() { for (BodyPart bp : getBodyParts()) { bp.cleanup(); } }
@POST @Consumes(MultiPartMediaTypes.MULTIPART_MIXED) public Response post(MultiPart multiPart) { for(BodyPart part : multiPart.getBodyParts()) { System.out.println(part.getMediaType()); } return Response.status(Response.Status.ACCEPTED). entity("Attachements processed successfully."). type(MediaType.TEXT_PLAIN).build(); }
@POST @Consumes("multipart/*") public String create(MultiPart multiPart) throws Exception { String message; try (BodyPartEntity bpe = (BodyPartEntity) multiPart.getBodyParts().get(0).getEntity()) { message = getString(bpe.getInputStream()); } return message; } private String getString(InputStream is) throws Exception { StringBuilder builder = new StringBuilder(); try (BufferedReader reader = new BufferedReader(new InputStreamReader(is))) { String line; while((line = reader.readLine()) != null) { builder.append(line).append("\n"); } } return builder.toString(); }
/** * POST a multipart object streaming * * @param path the path to access * @param name the name of the param the endpoint is expecting * @param fileName the name of the file * @param stream the stream itself * @param returnType the type to return from the post * @return the response of type T */ public <T> T postMultiPartStream(String path, String name, String fileName, InputStream stream, Class<T> returnType) { WebTarget target = buildTarget(path, null); MultiPart multiPart = new MultiPart(MediaType.MULTIPART_FORM_DATA_TYPE); StreamDataBodyPart streamDataBodyPart = new StreamDataBodyPart(name, stream, fileName, MediaType.APPLICATION_OCTET_STREAM_TYPE); multiPart.getBodyParts().add(streamDataBodyPart); MediaType contentType = MediaType.MULTIPART_FORM_DATA_TYPE; contentType = Boundary.addBoundary(contentType); return target.request().post( Entity.entity(multiPart, contentType), returnType); }
multiPart.getBodyParts().add(bodyPart);