You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by GitBox <gi...@apache.org> on 2022/11/08 14:03:11 UTC

[GitHub] [camel-quarkus] ppalaga commented on a diff in pull request #4264: Enhance test covarege of MTOM with PAYLOAD data format

ppalaga commented on code in PR #4264:
URL: https://github.com/apache/camel-quarkus/pull/4264#discussion_r1016661885


##########
integration-test-groups/cxf-soap/cxf-soap-mtom/src/main/java/org/apache/camel/quarkus/component/cxf/soap/mtom/it/CxfSoapMtomResource.java:
##########
@@ -56,22 +74,30 @@ public Response upload(@QueryParam("imageName") String imageName, @QueryParam("m
 
     @Path("/download")
     @POST
+    @Produces(MediaType.APPLICATION_OCTET_STREAM)
     @Consumes(MediaType.TEXT_PLAIN)
-    public Response download(@QueryParam("imageName") String imageName, @QueryParam("mtomEnabled") boolean mtomEnabled)
+    public Response download(@QueryParam("imageName") String imageName, @QueryParam("mtomEnabled") boolean mtomEnabled,
+            @QueryParam("endpointDataFormat") String endpointDataFormat)
             throws Exception {
-        final ImageFile response = (ImageFile) producerTemplate.requestBodyAndHeader(
-                "direct:" + mtomEndpoint(mtomEnabled),
-                imageName,
-                OPERATION_NAME,
-                "downloadImage", ImageFile.class);
+        Map<String, Object> headers = new LinkedHashMap<>();
+        headers.put(OPERATION_NAME, "downloadImage");
+        headers.put("endpointDataFormat", endpointDataFormat);
+        headers.put("mtomEnabled", mtomEnabled);
+        Exchange result = producerTemplate.request("direct:invoker", exchange -> {
+            exchange.setPattern(ExchangePattern.InOut);
+            exchange.getIn().setBody(imageName);
+            exchange.getIn().setHeaders(headers);
+        });
+        Object response = null;
+        if ("PAYLOAD".equals(endpointDataFormat)) {
+            response = result.getMessage(AttachmentMessage.class).getAttachment(imageName).getContent();
+        } else {
+            response = result.getMessage().getBody(ImageFile.class).getContent();
+        }

Review Comment:
   I wonder whether we should make our assumption about the runtime type of `getAttachment(imageName).getContent()` explicit? In that way all future readers will clearly see what is sent back over the wire.
   
   Something like 
   
   ```suggestion
           final byte[] response = null;
           if ("PAYLOAD".equals(endpointDataFormat)) {
               response = (byte[]) result.getMessage(AttachmentMessage.class).getAttachment(imageName).getContent();
           } else {
               response = result.getMessage().getBody(ImageFile.class).getContent();
           }
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org