Skip to content

Commit

Permalink
CxfSoapMtomIT fails in native mode apache#4208
Browse files Browse the repository at this point in the history
  • Loading branch information
ppalaga authored and jamesnetherton committed Oct 31, 2022
1 parent bd148f6 commit 1a2cdd2
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 58 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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/"))
Expand All @@ -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/"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,16 @@
*/
package org.apache.camel.quarkus.component.cxf.soap.mtom.awt.it;

import java.awt.*;

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

@WebService
public interface IImageService {

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

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

}
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,38 +23,33 @@
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<String, Image> imageRepository;

public ImageService() {
imageRepository = new ConcurrentHashMap<>();
}
private final Map<String, ImageData> 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.");
}
return image;
}

@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.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -34,26 +33,22 @@
@QuarkusTest
class CxfSoapMtomAwtTest {

@DisabledOnIntegrationTest("https://github.com/apache/camel-quarkus/issues/4208")
@ParameterizedTest
@ValueSource(booleans = { true, false })
public void uploadDownloadMtom(boolean mtomEnabled) throws IOException {
byte[] imageBytes = CxfSoapMtomAwtTest.class.getClassLoader().getResourceAsStream("linux-image.png").readAllBytes();
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();
Expand Down

0 comments on commit 1a2cdd2

Please sign in to comment.