Skip to content

Commit

Permalink
Not use awt.* in MTOM test app
Browse files Browse the repository at this point in the history
  • Loading branch information
llowinge authored and jamesnetherton committed Nov 1, 2022
1 parent 49329e6 commit 6aabc26
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 40 deletions.
4 changes: 0 additions & 4 deletions integration-test-groups/cxf-soap/cxf-soap-mtom/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,6 @@
<description>Integration tests for Camel Quarkus CXF extension Mtom</description>

<dependencies>
<dependency><!-- for java.awt.Image -->
<groupId>io.quarkus</groupId>
<artifactId>quarkus-awt</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,9 @@
*/
package org.apache.camel.quarkus.component.cxf.soap.mtom.it;

import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.net.URI;

import javax.enterprise.context.ApplicationScoped;
import javax.imageio.ImageIO;
import javax.inject.Inject;
import javax.ws.rs.Consumes;
import javax.ws.rs.POST;
Expand All @@ -49,36 +44,30 @@ public class CxfSoapMtomResource {
@Produces(MediaType.TEXT_PLAIN)
public Response upload(@QueryParam("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 },
OPERATION_NAME, "uploadImage", String.class);
return Response
.created(new URI("https://camel.apache.org/"))
.entity(response)
.build();
}
final String response = producerTemplate.requestBodyAndHeader(
"direct:" + mtomEndpoint(mtomEnabled),
new Object[] { new ImageFile(image), imageName },
OPERATION_NAME, "uploadImage", String.class);
return Response
.created(new URI("https://camel.apache.org/"))
.entity(response)
.build();
}

@Path("/download")
@POST
@Consumes(MediaType.TEXT_PLAIN)
public Response download(@QueryParam("imageName") String imageName, @QueryParam("mtomEnabled") boolean mtomEnabled)
throws Exception {
final BufferedImage response = (BufferedImage) producerTemplate.requestBodyAndHeader(
final ImageFile response = (ImageFile) producerTemplate.requestBodyAndHeader(
"direct:" + mtomEndpoint(mtomEnabled),
imageName,
OPERATION_NAME,
"downloadImage", Image.class);
try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
ImageIO.write(response, "png", baos);
byte[] bytes = baos.toByteArray();
return Response
.created(new URI("https://camel.apache.org/"))
.entity(bytes)
.build();
}
"downloadImage", ImageFile.class);
return Response
.created(new URI("https://camel.apache.org/"))
.entity(response.getContent())
.build();
}

private String mtomEndpoint(boolean mtomEnabled) {
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.it;

import java.awt.*;

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

@WebService
public interface IImageService {

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

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

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* 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.it;

import javax.xml.bind.annotation.XmlType;

@XmlType(name = "imageFile")
public class ImageFile {

public ImageFile() {
}

private byte[] content;

public ImageFile(byte[] content) {
this.content = content;
}

public byte[] getContent() {
return this.content;
}

public void setContent(byte[] content) {
this.content = content;
}

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

import java.awt.*;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

Expand All @@ -33,23 +32,23 @@ public class ImageService implements IImageService {
public static final String MSG_SUCCESS = "Upload Successful";
private static final Logger log = LoggerFactory.getLogger(ImageService.class);

private final Map<String, Image> imageRepository;
private final Map<String, ImageFile> imageRepository;

public ImageService() {
imageRepository = new ConcurrentHashMap<>();
}

@Override
public Image downloadImage(String name) {
final Image image = imageRepository.get(name);
public ImageFile downloadImage(String name) {
final ImageFile 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(ImageFile image, String name) {

log.info("Upload image: " + image + " with name: " + name);

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,7 +33,6 @@
@QuarkusTest
class CxfSoapMtomTest {

@DisabledOnIntegrationTest("https://github.com/apache/camel-quarkus/issues/4208")
@ParameterizedTest
@ValueSource(booleans = { true, false })
public void uploadDownloadMtom(boolean mtomEnabled) throws IOException {
Expand Down

0 comments on commit 6aabc26

Please sign in to comment.