From a64a52341189df00dbd7f92dc5d11c86618aed48 Mon Sep 17 00:00:00 2001 From: Peter Palaga Date: Tue, 9 May 2023 22:23:24 +0200 Subject: [PATCH] Test CXF client with a method referencing class with runtime initialization #4208 https://github.com/quarkiverse/quarkus-cxf/issues/580 --- .../mtom/awt/it/CxfSoapMtomAwtResource.java | 8 +-- .../mtom/awt/it/CxfSoapMtomAwtRoutes.java | 13 +++++ .../cxf/soap/mtom/awt/it/IImageService.java | 6 ++- .../cxf/soap/mtom/awt/it/ImageData.java | 53 ------------------- .../cxf/soap/mtom/awt/it/ImageService.java | 14 ++--- 5 files changed, 28 insertions(+), 66 deletions(-) delete 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 69be8bdf6aad..bcd6bb648c56 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 @@ -55,7 +55,7 @@ public Response upload(@PathParam("imageName") String imageName, @QueryParam("mt try (ByteArrayInputStream bais = new ByteArrayInputStream(image)) { final String response = producerTemplate.requestBodyAndHeader( "direct:" + mtomEndpoint(mtomEnabled), - new ImageData(ImageIO.read(bais), imageName), + new Object[] { ImageIO.read(bais), imageName }, OPERATION_NAME, "uploadImage", String.class); return Response .created(new URI("https://camel.apache.org/")) @@ -68,13 +68,13 @@ public Response upload(@PathParam("imageName") String imageName, @QueryParam("mt @GET public Response download(@PathParam("imageName") String imageName, @QueryParam("mtomEnabled") boolean mtomEnabled) throws Exception { - final ImageData image = (ImageData) producerTemplate.requestBodyAndHeader( + final java.awt.Image image = producerTemplate.requestBodyAndHeader( "direct:" + mtomEndpoint(mtomEnabled), imageName, OPERATION_NAME, - "downloadImage", ImageData.class); + "downloadImage", java.awt.Image.class); try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) { - ImageIO.write((BufferedImage) image.getData(), "png", baos); + ImageIO.write((BufferedImage) image, "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 0bb9e318c229..78988487d951 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 @@ -29,6 +29,7 @@ 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; @@ -55,6 +56,18 @@ public void configure() { .to("direct:processAwtImage"); from("direct:processAwtImage") + .process(exchange -> { + String operationName = (String) exchange.getIn().getHeaders().get("operationName"); + MessageContentsList list = exchange.getIn().getBody(MessageContentsList.class); + 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)); + } + }) .recipientList((simple("bean:imageAwtService?method=${header.operationName}"))); } 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 6816daae832c..cf963420d9e5 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,6 +16,8 @@ */ package org.apache.camel.quarkus.component.cxf.soap.mtom.awt.it; +import java.awt.Image; + import javax.jws.WebMethod; import javax.jws.WebService; @@ -23,9 +25,9 @@ public interface IImageService { @WebMethod - ImageData downloadImage(String name); + Image downloadImage(String name); @WebMethod - String uploadImage(ImageData image); + String uploadImage(Image image, String imageName); } 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 deleted file mode 100644 index e39a79a9c5f2..000000000000 --- 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 +++ /dev/null @@ -1,53 +0,0 @@ -/* - * 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 6a213f973273..cd1e6c00b3ba 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 @@ -32,11 +32,11 @@ public class ImageService implements IImageService { public static final String MSG_SUCCESS = "Upload Successful"; private static final Logger log = Logger.getLogger(ImageService.class); - private final Map imageRepository = new ConcurrentHashMap<>(); + private final Map imageRepository = new ConcurrentHashMap<>(); @Override - public ImageData downloadImage(String name) { - final ImageData image = imageRepository.get(name); + public Image downloadImage(String name) { + final Image image = imageRepository.get(name); if (image == null) { throw new IllegalStateException("Image with name " + name + " does not exist."); } @@ -44,12 +44,12 @@ public ImageData downloadImage(String name) { } @Override - public String uploadImage(ImageData image) { + public String uploadImage(Image image, String imageName) { - log.infof("Upload image: %s", image.getName()); + log.infof("Upload image: %s", imageName); - if (image.getData() != null && image.getName() != null) { - imageRepository.put(image.getName(), image); + if (image != null && imageName != null) { + imageRepository.put(imageName, image); return MSG_SUCCESS; } throw new IllegalStateException("Illegal Data Format.");