Skip to content

Commit

Permalink
Test CXF client with a method referencing class with runtime initiali…
Browse files Browse the repository at this point in the history
  • Loading branch information
ppalaga committed May 15, 2023
1 parent 8b06c57 commit be29faf
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 66 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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/"))
Expand All @@ -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/"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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}")));

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,18 @@
*/
package org.apache.camel.quarkus.component.cxf.soap.mtom.awt.it;

import java.awt.Image;

import javax.jws.WebMethod;
import javax.jws.WebService;

@WebService
public interface IImageService {

@WebMethod
ImageData downloadImage(String name);
Image downloadImage(String name);

@WebMethod
String uploadImage(ImageData image);
String uploadImage(Image image, String imageName);

}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -32,24 +32,24 @@ 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<String, ImageData> imageRepository = new ConcurrentHashMap<>();
private final Map<String, Image> 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.");
}
return image;
}

@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.");
Expand Down

0 comments on commit be29faf

Please sign in to comment.