Skip to content

Commit

Permalink
Add test for @ResponseWrapper and @RequestWrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
ppalaga committed Mar 17, 2023
1 parent dd5cbc1 commit 89b08e8
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,23 @@

import java.awt.Image;

import jakarta.xml.bind.annotation.XmlAccessType;
import jakarta.xml.bind.annotation.XmlAccessorType;
import jakarta.xml.bind.annotation.XmlElement;
import jakarta.xml.bind.annotation.XmlMimeType;
import jakarta.xml.bind.annotation.XmlType;

@XmlType(name = "imageData", namespace = "http://org.jboss.ws/xop/doclit")
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "ImageData", propOrder = {
"data",
"name"
}, namespace = io.quarkiverse.cxf.it.ws.mtom.awt.server.ImageService.NS)
public class ImageData {

@XmlElement(required = true)
@XmlMimeType("image/png")
private Image data;
@XmlElement(required = true)
private String name;

public ImageData() {
Expand All @@ -34,4 +45,4 @@ public Image getData() {
public void setData(Image data) {
this.data = data;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package io.quarkiverse.cxf.it.ws.mtom.awt.server;

import java.awt.Image;

import jakarta.xml.bind.annotation.XmlAccessType;
import jakarta.xml.bind.annotation.XmlAccessorType;
import jakarta.xml.bind.annotation.XmlElement;
import jakarta.xml.bind.annotation.XmlMimeType;
import jakarta.xml.bind.annotation.XmlType;

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "ImageResponse", propOrder = {
"_return"
}, namespace = io.quarkiverse.cxf.it.ws.mtom.awt.server.ImageService.NS)
public class ImageResponse {

@XmlElement(required = true)
@XmlMimeType("image/png")
private Image _return;

public ImageResponse() {
}

public ImageResponse(Image data) {
super();
this._return = data;
}

public Image getReturn() {
return _return;
}

public void setReturn(Image data) {
this._return = data;
}
}
Original file line number Diff line number Diff line change
@@ -1,19 +1,29 @@
package io.quarkiverse.cxf.it.ws.mtom.awt.server;

import java.awt.Image;

import jakarta.jws.WebMethod;
import jakarta.jws.WebParam;
import jakarta.jws.WebService;
import jakarta.jws.soap.SOAPBinding;
import jakarta.xml.ws.RequestWrapper;
import jakarta.xml.ws.ResponseWrapper;
import jakarta.xml.ws.soap.MTOM;

@WebService(name = "ImageService", targetNamespace = "https://quarkiverse.github.io/quarkiverse-docs/quarkus-cxf/test/mtom-awt")
@SOAPBinding(style = SOAPBinding.Style.DOCUMENT, parameterStyle = SOAPBinding.ParameterStyle.BARE)
@WebService(name = "ImageService", targetNamespace = ImageService.NS)
@MTOM
public interface ImageService {

public static final String NS = "https://quarkiverse.github.io/quarkiverse-docs/quarkus-cxf/test/mtom-awt";

@WebMethod
ImageData downloadImage(String name);
@ResponseWrapper(localName = "ImageResponse", targetNamespace = NS, className = "io.quarkiverse.cxf.it.ws.mtom.awt.server.ImageResponse")
Image downloadImage(
@WebParam(name = "name", targetNamespace = NS) String name);

@WebMethod
String uploadImage(ImageData image);
@RequestWrapper(localName = "ImageData", targetNamespace = NS, className = "io.quarkiverse.cxf.it.ws.mtom.awt.server.ImageData")
String uploadImage(
@WebParam(name = "data", targetNamespace = NS) Image data,
@WebParam(name = "name", targetNamespace = NS) String name);

}
Original file line number Diff line number Diff line change
@@ -1,38 +1,38 @@
package io.quarkiverse.cxf.it.ws.mtom.awt.server;

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

import jakarta.jws.WebService;
import jakarta.jws.soap.SOAPBinding;

import org.jboss.logging.Logger;

@WebService(name = "ImageService", serviceName = "ImageService", endpointInterface = "io.quarkiverse.cxf.it.ws.mtom.awt.server.ImageService", targetNamespace = "https://quarkiverse.github.io/quarkiverse-docs/quarkus-cxf/test/mtom-awt")
@SOAPBinding(parameterStyle = SOAPBinding.ParameterStyle.BARE)
public class ImageServiceImpl implements ImageService {

public static final String MSG_SUCCESS = "Upload Successful";
private static final Logger log = Logger.getLogger(ImageServiceImpl.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.");
}
log.infof("Downloading image: %s", name);
return image;
}

@Override
public String uploadImage(ImageData image) {
public String uploadImage(Image data, String name) {

log.infof("Uploaded image: %s");
log.infof("Uploaded image: %s", name);

if (image.getData() != null && image.getName() != null) {
imageRepository.put(image.getName(), image);
if (data != null && name != null) {
imageRepository.put(name, data);
return MSG_SUCCESS;
}
throw new IllegalStateException("Illegal Data Format.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public class MtomAwtResource {
@Consumes(MediaType.APPLICATION_OCTET_STREAM)
@Produces(MediaType.TEXT_PLAIN)
public Response upload(@PathParam("imageName") String imageName, InputStream in) throws Exception {
String response = imageServiceClient.uploadImage(new ImageData(ImageIO.read(in), imageName));
String response = imageServiceClient.uploadImage(ImageIO.read(in), imageName);
return Response
.created(new URI("https://quarkus.io/"))
.entity(response)
Expand All @@ -44,9 +44,9 @@ public Response upload(@PathParam("imageName") String imageName, InputStream in)
@GET
@Consumes(MediaType.TEXT_PLAIN)
public byte[] download(@PathParam("imageName") String imageName) throws Exception {
ImageData image = imageServiceClient.downloadImage(imageName);
java.awt.Image image = imageServiceClient.downloadImage(imageName);
try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
ImageIO.write((BufferedImage) image.getData(), "png", baos);
ImageIO.write((BufferedImage) image, "png", baos);
return baos.toByteArray();
}
}
Expand Down

0 comments on commit 89b08e8

Please sign in to comment.