From 163368161e0ba9e8a30d2ee3dfeeb20782450f65 Mon Sep 17 00:00:00 2001 From: Peter Palaga Date: Tue, 25 Oct 2022 18:04:18 +0200 Subject: [PATCH] CxfSoapMtomIT fails in native mode #4208 --- .../mtom/awt/it/CxfSoapMtomAwtResource.java | 22 ++++---- .../mtom/awt/it/CxfSoapMtomAwtRoutes.java | 23 -------- .../cxf/soap/mtom/awt/it/IImageService.java | 6 +-- .../cxf/soap/mtom/awt/it/ImageData.java | 53 +++++++++++++++++++ .../cxf/soap/mtom/awt/it/ImageService.java | 23 ++++---- .../soap/mtom/awt/it/CxfSoapMtomAwtTest.java | 9 +--- 6 files changed, 78 insertions(+), 58 deletions(-) create mode 100644 integration-test-groups/cxf-soap/cxf-soap-mtom-awt/src/main/java/org/apache/camel/quarkus/component/cxf/soap/mtom/awt/it/ImageData.java diff --git a/integration-test-groups/cxf-soap/cxf-soap-mtom-awt/src/main/java/org/apache/camel/quarkus/component/cxf/soap/mtom/awt/it/CxfSoapMtomAwtResource.java b/integration-test-groups/cxf-soap/cxf-soap-mtom-awt/src/main/java/org/apache/camel/quarkus/component/cxf/soap/mtom/awt/it/CxfSoapMtomAwtResource.java index fac4c2d1f9e0..69be8bdf6aad 100644 --- a/integration-test-groups/cxf-soap/cxf-soap-mtom-awt/src/main/java/org/apache/camel/quarkus/component/cxf/soap/mtom/awt/it/CxfSoapMtomAwtResource.java +++ b/integration-test-groups/cxf-soap/cxf-soap-mtom-awt/src/main/java/org/apache/camel/quarkus/component/cxf/soap/mtom/awt/it/CxfSoapMtomAwtResource.java @@ -26,8 +26,10 @@ import javax.imageio.ImageIO; import javax.inject.Inject; import javax.ws.rs.Consumes; +import javax.ws.rs.GET; import javax.ws.rs.POST; import javax.ws.rs.Path; +import javax.ws.rs.PathParam; import javax.ws.rs.Produces; import javax.ws.rs.QueryParam; import javax.ws.rs.core.MediaType; @@ -44,15 +46,16 @@ public class CxfSoapMtomAwtResource { @Inject ProducerTemplate producerTemplate; - @Path("/upload") + @Path("/image/{imageName}") @POST + @Consumes(MediaType.APPLICATION_OCTET_STREAM) @Produces(MediaType.TEXT_PLAIN) - public Response upload(@QueryParam("imageName") String imageName, @QueryParam("mtomEnabled") boolean mtomEnabled, + public Response upload(@PathParam("imageName") String imageName, @QueryParam("mtomEnabled") boolean mtomEnabled, byte[] image) throws Exception { try (ByteArrayInputStream bais = new ByteArrayInputStream(image)) { final String response = producerTemplate.requestBodyAndHeader( "direct:" + mtomEndpoint(mtomEnabled), - new Object[] { ImageIO.read(bais), imageName }, + new ImageData(ImageIO.read(bais), imageName), OPERATION_NAME, "uploadImage", String.class); return Response .created(new URI("https://camel.apache.org/")) @@ -61,18 +64,17 @@ public Response upload(@QueryParam("imageName") String imageName, @QueryParam("m } } - @Path("/download") - @POST - @Consumes(MediaType.TEXT_PLAIN) - public Response download(@QueryParam("imageName") String imageName, @QueryParam("mtomEnabled") boolean mtomEnabled) + @Path("/image/{imageName}") + @GET + public Response download(@PathParam("imageName") String imageName, @QueryParam("mtomEnabled") boolean mtomEnabled) throws Exception { - final BufferedImage response = (BufferedImage) producerTemplate.requestBodyAndHeader( + final ImageData image = (ImageData) producerTemplate.requestBodyAndHeader( "direct:" + mtomEndpoint(mtomEnabled), imageName, OPERATION_NAME, - "downloadImage", Image.class); + "downloadImage", ImageData.class); try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) { - ImageIO.write(response, "png", baos); + ImageIO.write((BufferedImage) image.getData(), "png", baos); byte[] bytes = baos.toByteArray(); return Response .created(new URI("https://camel.apache.org/")) diff --git a/integration-test-groups/cxf-soap/cxf-soap-mtom-awt/src/main/java/org/apache/camel/quarkus/component/cxf/soap/mtom/awt/it/CxfSoapMtomAwtRoutes.java b/integration-test-groups/cxf-soap/cxf-soap-mtom-awt/src/main/java/org/apache/camel/quarkus/component/cxf/soap/mtom/awt/it/CxfSoapMtomAwtRoutes.java index 388a8cb0930c..0bb9e318c229 100644 --- a/integration-test-groups/cxf-soap/cxf-soap-mtom-awt/src/main/java/org/apache/camel/quarkus/component/cxf/soap/mtom/awt/it/CxfSoapMtomAwtRoutes.java +++ b/integration-test-groups/cxf-soap/cxf-soap-mtom-awt/src/main/java/org/apache/camel/quarkus/component/cxf/soap/mtom/awt/it/CxfSoapMtomAwtRoutes.java @@ -26,12 +26,9 @@ import javax.xml.ws.handler.Handler; import io.quarkus.runtime.LaunchMode; -import org.apache.camel.Exchange; -import org.apache.camel.Processor; import org.apache.camel.builder.RouteBuilder; import org.apache.camel.component.cxf.jaxws.CxfEndpoint; import org.apache.cxf.ext.logging.LoggingFeature; -import org.apache.cxf.message.MessageContentsList; import org.eclipse.microprofile.config.Config; import org.eclipse.microprofile.config.ConfigProvider; @@ -58,30 +55,10 @@ public void configure() { .to("direct:processAwtImage"); from("direct:processAwtImage") - .process("imageAwtServiceProcessor") .recipientList((simple("bean:imageAwtService?method=${header.operationName}"))); } - @ApplicationScoped - @Named("imageAwtServiceProcessor") - static class ImageServiceProcessor implements Processor { - @Override - public void process(Exchange exchange) throws Exception { - String operationName = (String) exchange.getIn().getHeaders().get("operationName"); - MessageContentsList list = (MessageContentsList) exchange.getIn().getBody(); - if ("uploadImage".equals(operationName)) { - exchange.getIn().getHeaders().put("image", list.get(0)); - exchange.getIn().getHeaders().put("imageName", list.get(1)); - exchange.getIn().getHeaders() - .put("operationName", "uploadImage(${header.image},${header.imageName})"); - } else if ("downloadImage".equals(operationName)) { - exchange.getIn().setBody(list.get(0)); - } - } - - } - @Produces @ApplicationScoped @Named("loggingMtomAwtFeatureClient") diff --git a/integration-test-groups/cxf-soap/cxf-soap-mtom-awt/src/main/java/org/apache/camel/quarkus/component/cxf/soap/mtom/awt/it/IImageService.java b/integration-test-groups/cxf-soap/cxf-soap-mtom-awt/src/main/java/org/apache/camel/quarkus/component/cxf/soap/mtom/awt/it/IImageService.java index 686c53bbc6d2..6816daae832c 100644 --- a/integration-test-groups/cxf-soap/cxf-soap-mtom-awt/src/main/java/org/apache/camel/quarkus/component/cxf/soap/mtom/awt/it/IImageService.java +++ b/integration-test-groups/cxf-soap/cxf-soap-mtom-awt/src/main/java/org/apache/camel/quarkus/component/cxf/soap/mtom/awt/it/IImageService.java @@ -16,8 +16,6 @@ */ package org.apache.camel.quarkus.component.cxf.soap.mtom.awt.it; -import java.awt.*; - import javax.jws.WebMethod; import javax.jws.WebService; @@ -25,9 +23,9 @@ public interface IImageService { @WebMethod - Image downloadImage(String name); + ImageData downloadImage(String name); @WebMethod - String uploadImage(Image image, String name); + String uploadImage(ImageData image); } diff --git a/integration-test-groups/cxf-soap/cxf-soap-mtom-awt/src/main/java/org/apache/camel/quarkus/component/cxf/soap/mtom/awt/it/ImageData.java b/integration-test-groups/cxf-soap/cxf-soap-mtom-awt/src/main/java/org/apache/camel/quarkus/component/cxf/soap/mtom/awt/it/ImageData.java new file mode 100644 index 000000000000..e39a79a9c5f2 --- /dev/null +++ b/integration-test-groups/cxf-soap/cxf-soap-mtom-awt/src/main/java/org/apache/camel/quarkus/component/cxf/soap/mtom/awt/it/ImageData.java @@ -0,0 +1,53 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.camel.quarkus.component.cxf.soap.mtom.awt.it; + +import java.awt.Image; + +import javax.xml.bind.annotation.XmlType; + +@XmlType(name = "imageData", namespace = "http://org.jboss.ws/xop/doclit") +public class ImageData { + + private Image data; + private String name; + + public ImageData() { + } + + public ImageData(Image data, String name) { + super(); + this.data = data; + this.name = name; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public Image getData() { + return data; + } + + public void setData(Image data) { + this.data = data; + } +} diff --git a/integration-test-groups/cxf-soap/cxf-soap-mtom-awt/src/main/java/org/apache/camel/quarkus/component/cxf/soap/mtom/awt/it/ImageService.java b/integration-test-groups/cxf-soap/cxf-soap-mtom-awt/src/main/java/org/apache/camel/quarkus/component/cxf/soap/mtom/awt/it/ImageService.java index aa0f0ab5c430..6a213f973273 100644 --- a/integration-test-groups/cxf-soap/cxf-soap-mtom-awt/src/main/java/org/apache/camel/quarkus/component/cxf/soap/mtom/awt/it/ImageService.java +++ b/integration-test-groups/cxf-soap/cxf-soap-mtom-awt/src/main/java/org/apache/camel/quarkus/component/cxf/soap/mtom/awt/it/ImageService.java @@ -23,25 +23,20 @@ import javax.enterprise.context.ApplicationScoped; import javax.inject.Named; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +import org.jboss.logging.Logger; @ApplicationScoped @Named("imageAwtService") public class ImageService implements IImageService { public static final String MSG_SUCCESS = "Upload Successful"; - private static final Logger log = LoggerFactory.getLogger(ImageService.class); + private static final Logger log = Logger.getLogger(ImageService.class); - private final Map imageRepository; - - public ImageService() { - imageRepository = new ConcurrentHashMap<>(); - } + private final Map imageRepository = new ConcurrentHashMap<>(); @Override - public Image downloadImage(String name) { - final Image image = imageRepository.get(name); + public ImageData downloadImage(String name) { + final ImageData image = imageRepository.get(name); if (image == null) { throw new IllegalStateException("Image with name " + name + " does not exist."); } @@ -49,12 +44,12 @@ public Image downloadImage(String name) { } @Override - public String uploadImage(Image image, String name) { + public String uploadImage(ImageData image) { - log.info("Upload image: " + image + " with name: " + name); + log.infof("Upload image: %s", image.getName()); - if (image != null && name != null && !"".equals(name)) { - imageRepository.put(name, image); + if (image.getData() != null && image.getName() != null) { + imageRepository.put(image.getName(), image); return MSG_SUCCESS; } throw new IllegalStateException("Illegal Data Format."); diff --git a/integration-test-groups/cxf-soap/cxf-soap-mtom-awt/src/test/java/org/apache/camel/quarkus/component/cxf/soap/mtom/awt/it/CxfSoapMtomAwtTest.java b/integration-test-groups/cxf-soap/cxf-soap-mtom-awt/src/test/java/org/apache/camel/quarkus/component/cxf/soap/mtom/awt/it/CxfSoapMtomAwtTest.java index ba52a0377160..de6ff4da340b 100644 --- a/integration-test-groups/cxf-soap/cxf-soap-mtom-awt/src/test/java/org/apache/camel/quarkus/component/cxf/soap/mtom/awt/it/CxfSoapMtomAwtTest.java +++ b/integration-test-groups/cxf-soap/cxf-soap-mtom-awt/src/test/java/org/apache/camel/quarkus/component/cxf/soap/mtom/awt/it/CxfSoapMtomAwtTest.java @@ -22,7 +22,6 @@ import javax.imageio.ImageIO; -import io.quarkus.test.junit.DisabledOnIntegrationTest; import io.quarkus.test.junit.QuarkusTest; import io.restassured.RestAssured; import io.restassured.http.ContentType; @@ -34,7 +33,6 @@ @QuarkusTest class CxfSoapMtomAwtTest { - @DisabledOnIntegrationTest("https://github.com/apache/camel-quarkus/issues/4208") @ParameterizedTest @ValueSource(booleans = { true, false }) public void uploadDownloadMtom(boolean mtomEnabled) throws IOException { @@ -42,18 +40,15 @@ public void uploadDownloadMtom(boolean mtomEnabled) throws IOException { String imageName = "linux-image-name"; RestAssured.given() .contentType(ContentType.BINARY) - .queryParam("imageName", imageName) .queryParam("mtomEnabled", mtomEnabled) .body(imageBytes) - .post("/cxf-soap/mtom-awt/upload") + .post("/cxf-soap/mtom-awt/image/" + imageName) .then() .statusCode(201) .body(CoreMatchers.equalTo(ImageService.MSG_SUCCESS)); byte[] downloadedImageBytes = RestAssured.given() - .contentType(ContentType.TEXT) - .queryParam("imageName", imageName) .queryParam("mtomEnabled", mtomEnabled) - .post("/cxf-soap/mtom-awt/download") + .get("/cxf-soap/mtom-awt/image/" + imageName) .then() .statusCode(201) .extract().asByteArray();