use of org.apache.cxf.jaxrs.ext.multipart.MultipartBody in project cxf by apache.
the class FormEncodingProvider method populateMap.
/**
* Retrieve map of parameters from the passed in message
*/
protected void populateMap(MultivaluedMap<String, String> params, Annotation[] anns, InputStream is, MediaType mt, boolean decode) {
if (mt.isCompatible(MediaType.MULTIPART_FORM_DATA_TYPE)) {
MultipartBody body = AttachmentUtils.getMultipartBody(mc, attachmentDir, attachmentThreshold, attachmentMaxSize);
FormUtils.populateMapFromMultipart(params, body, PhaseInterceptorChain.getCurrentMessage(), decode);
} else {
String enc = HttpUtils.getEncoding(mt, StandardCharsets.UTF_8.name());
Object servletRequest = mc != null ? mc.getHttpServletRequest() : null;
if (servletRequest == null) {
FormUtils.populateMapFromString(params, PhaseInterceptorChain.getCurrentMessage(), FormUtils.readBody(is, enc), enc, decode);
} else {
FormUtils.populateMapFromString(params, PhaseInterceptorChain.getCurrentMessage(), FormUtils.readBody(is, enc), enc, decode, (javax.servlet.http.HttpServletRequest) servletRequest);
}
}
}
use of org.apache.cxf.jaxrs.ext.multipart.MultipartBody in project cxf by apache.
the class AbstractJwsMultipartSignatureFilter method getAttachmentParts.
protected List<Object> getAttachmentParts(Object rootEntity) {
final List<Object> parts;
if (rootEntity instanceof MultipartBody) {
parts = CastUtils.cast(((MultipartBody) rootEntity).getAllAttachments());
} else {
if (rootEntity instanceof List) {
List<Object> entityList = CastUtils.cast((List<?>) rootEntity);
parts = new ArrayList<>(entityList);
} else {
parts = new ArrayList<>(2);
parts.add(rootEntity);
}
}
JwsHeaders headers = new JwsHeaders();
headers.setPayloadEncodingStatus(false);
JwsSignatureProvider theSigProvider = sigProvider != null ? sigProvider : JwsUtils.loadSignatureProvider(headers, true);
JwsSignature jwsSignature = theSigProvider.createJwsSignature(headers);
String base64UrlEncodedHeaders = Base64UrlUtility.encode(writer.toJson(headers));
byte[] headerBytesWithDot = StringUtils.toBytesASCII(base64UrlEncodedHeaders + '.');
jwsSignature.update(headerBytesWithDot, 0, headerBytesWithDot.length);
AttachmentUtils.addMultipartOutFilter(new JwsMultipartSignatureOutFilter(jwsSignature));
JwsDetachedSignature jws = new JwsDetachedSignature(headers, base64UrlEncodedHeaders, jwsSignature, useJwsJsonSignatureFormat);
Attachment jwsPart = new Attachment("signature", JoseConstants.MEDIA_TYPE_JOSE, jws);
parts.add(jwsPart);
return parts;
}
use of org.apache.cxf.jaxrs.ext.multipart.MultipartBody in project cxf by apache.
the class JAXRSClientServerTikaTest method testUploadIndexAndSearchPdfFile.
@Test
public void testUploadIndexAndSearchPdfFile() {
final WebClient wc = createWebClient("/catalog").type(MediaType.MULTIPART_FORM_DATA);
final ContentDisposition disposition = new ContentDisposition("attachment;filename=testPDF.pdf");
final Attachment attachment = new Attachment("root", getClass().getResourceAsStream("/files/testPDF.pdf"), disposition);
wc.post(new MultipartBody(attachment));
final Collection<ScoreDoc> hits = search("dcterms:modified=le=2007-09-16T09:00:00");
assertEquals(hits.size(), 1);
}
use of org.apache.cxf.jaxrs.ext.multipart.MultipartBody in project cxf by apache.
the class JAXRSMultipartTest method testUpdateBookMultipart.
@Test
public void testUpdateBookMultipart() {
final WebTarget target = ClientBuilder.newClient().register(JacksonJsonProvider.class).target("http://localhost:" + PORT + "/bookstore");
final MultipartBody builder = new MultipartBody(Arrays.asList(new AttachmentBuilder().id("name").contentDisposition(new ContentDisposition("form-data; name=\"name\"")).object("The Book").build()));
try (Response response = target.path("1").request().put(Entity.entity(builder, MediaType.MULTIPART_FORM_DATA))) {
assertThat(response.getStatus(), equalTo(200));
assertThat(response.readEntity(Book.class).getName(), equalTo("The Book"));
}
}
use of org.apache.cxf.jaxrs.ext.multipart.MultipartBody in project cxf by apache.
the class MultipartStore method addBookFormImage.
@POST
@Path("/books/formimage")
@Consumes("multipart/form-data")
@Produces("multipart/form-data")
public MultipartBody addBookFormImage(MultipartBody image) throws Exception {
List<Attachment> atts = image.getAllAttachments();
if (atts.size() != 1) {
throw new WebApplicationException();
}
List<Attachment> newAtts = new ArrayList<>();
Attachment at = atts.get(0);
MultivaluedMap<String, String> headers = at.getHeaders();
if (!"http://host/bar".equals(headers.getFirst("Content-Location"))) {
throw new WebApplicationException();
}
if (!"custom".equals(headers.getFirst("Custom-Header"))) {
throw new WebApplicationException();
}
headers.putSingle("Content-Location", "http://host/location");
newAtts.add(new Attachment(at.getContentId(), at.getDataHandler(), headers));
return new MultipartBody(newAtts);
}
Aggregations