public void writeTo(Map<String, Object> map, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream) throws IOException, WebApplicationException { PartType partType = FindAnnotation.findAnnotation(annotations, PartType.class); MediaType partMediaType = MediaType.valueOf(partType.value()); MultipartFormDataOutput output = new MultipartFormDataOutput(); for (Map.Entry<String, Object> entry : map.entrySet()) { output.addFormData(entry.getKey(), entry.getValue(), partMediaType); } write(output, mediaType, httpHeaders, entityStream); } }
protected void getFields(Class<?> type, MultipartFormDataOutput output, Object obj) throws IOException { for (Field field : type.getDeclaredFields()) { if (field.isAnnotationPresent(FormParam.class) && field.isAnnotationPresent(PartType.class)) { AccessController.doPrivileged(new FieldEnablerPrivilegedAction(field)); FormParam param = field.getAnnotation(FormParam.class); Object value = null; try { value = field.get(obj); } catch (IllegalAccessException e) { throw new WriterException(e); } PartType partType = field.getAnnotation(PartType.class); String filename = getFilename(field); output.addFormData(param.value(), value, field.getType(), field.getGenericType(), MediaType.valueOf(partType.value()), filename); } } }
String filename = getFilename(method); multipart.addFormData(param.value(), value, method.getReturnType(), method.getGenericReturnType(), MediaType.valueOf(partType.value()), filename);
WebTarget target = ClientBuilder.newClient().target("some/url"); MultipartFormDataOutput formData = new MultipartFormDataOutput(); Map<String, Object> json = new HashMap<>(); json.put("foo", "bar"); formData.addFormData("json", json, MediaType.APPLICATION_JSON_TYPE); FileInputStream fis = new FileInputStream(new File("/path/to/image")); formData.addFormData("image", fis, MediaType.APPLICATION_OCTET_STREAM_TYPE); Entity<MultipartFormDataOutput> entity = Entity.entity(formData, MediaType.MULTIPART_FORM_DATA); Response response = target.request().post(entity);
MultipartFormDataOutput output = new MultipartFormDataOutput(); // file (below) doesn't have to be a `byte[]` // It can be a `File` object and work just the same output.addFormData("file", file, MediaType.APPLICATION_OCTET_STREAM_TYPE); Response response = target.request() .post(Entity.entity(output, MediaType.MULTIPART_FORM_DATA));
WebTarget target = client.target("/some-resource"); MultipartFormDataOutput formData = new MultipartFormDataOutput(); formData.addFormData("file", fileContent, MediaType.TEXT_PLAIN_TYPE.withCharset("utf-8")); Entity<MultipartFormDataOutput> entity = Entity.entity(formData, MediaType.MULTIPART_FORM_DATA); Response response = target.request().post(entity);
ResteasyClient client = (ResteasyClient) this.client; ResteasyWebTarget target = client.target("http://localhost:8080").path("path"); MultipartFormDataOutput mdo = new MultipartFormDataOutput(); mdo.addFormData("firstPart", new ByteArrayInputStream("firstContent".getBytes()), MediaType.TEXT_PLAIN_TYPE); mdo.addFormData("secondPart", new ByteArrayInputStream("secondContent".getBytes()), MediaType.TEXT_PLAIN_TYPE); GenericEntity<MultipartFormDataOutput> entity = new GenericEntity<MultipartFormDataOutput>(mdo) { }; Response response = target.request().put(Entity.entity(entity, MediaType.MULTIPART_FORM_DATA_TYPE)); response.close();
public void writeTo(Map<String, Object> map, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream) throws IOException, WebApplicationException { PartType partType = FindAnnotation.findAnnotation(annotations, PartType.class); MediaType partMediaType = MediaType.valueOf(partType.value()); MultipartFormDataOutput output = new MultipartFormDataOutput(); for (Map.Entry<String, Object> entry : map.entrySet()) { output.addFormData(entry.getKey(), entry.getValue(), partMediaType); } write(output, mediaType, httpHeaders, entityStream); } }
protected void getFields(Class<?> type, MultipartFormDataOutput output, Object obj) throws IOException { for (Field field : type.getDeclaredFields()) { if (field.isAnnotationPresent(FormParam.class) && field.isAnnotationPresent(PartType.class)) { AccessController.doPrivileged(new FieldEnablerPrivilegedAction(field)); FormParam param = field.getAnnotation(FormParam.class); Object value = null; try { value = field.get(obj); } catch (IllegalAccessException e) { throw new WriterException(e); } PartType partType = field.getAnnotation(PartType.class); String filename = getFilename(field); output.addFormData(param.value(), value, field.getType(), field.getGenericType(), MediaType.valueOf(partType.value()), filename); } } }
ClientRequest request = createClientRequest(atomUrl); MultipartFormDataOutput formData = new MultipartFormDataOutput(); formData.addFormData("query", xpath, MediaType.TEXT_PLAIN_TYPE); //$NON-NLS-1$ formData.addFormData("startIndex", String.valueOf(startIndex), MediaType.TEXT_PLAIN_TYPE); //$NON-NLS-1$ formData.addFormData("count", String.valueOf(count), MediaType.TEXT_PLAIN_TYPE); //$NON-NLS-1$ formData.addFormData("orderBy", orderBy, MediaType.TEXT_PLAIN_TYPE); //$NON-NLS-1$ formData.addFormData("ascending", String.valueOf(ascending), MediaType.TEXT_PLAIN_TYPE); //$NON-NLS-1$ if (propertyNames != null) { for (String propertyName : propertyNames) { formData.addFormData("propertyName", propertyName, MediaType.TEXT_PLAIN_TYPE); //$NON-NLS-1$
ClientRequest request = createClientRequest(atomUrl); MultipartFormDataOutput formData = new MultipartFormDataOutput(); formData.addFormData("query", xpath, MediaType.TEXT_PLAIN_TYPE); formData.addFormData("startIndex", String.valueOf(startIndex), MediaType.TEXT_PLAIN_TYPE); formData.addFormData("count", String.valueOf(count), MediaType.TEXT_PLAIN_TYPE); formData.addFormData("orderBy", orderBy, MediaType.TEXT_PLAIN_TYPE); formData.addFormData("ascending", String.valueOf(ascending), MediaType.TEXT_PLAIN_TYPE); if (propertyNames != null) { for (String propertyName : propertyNames) { formData.addFormData("propertyName", propertyName, MediaType.TEXT_PLAIN_TYPE);
String filename = getFilename(method); multipart.addFormData(param.value(), value, method.getReturnType(), method.getGenericReturnType(), MediaType.valueOf(partType.value()), filename);