Search in sources :

Example 1 with ImageDepot

use of org.apache.axis2.jaxws.sample.mtom1.ImageDepot in project axis-axis2-java-core by apache.

the class MtomSampleMTOMDisable2Service method sendImage.

public ImageDepot sendImage(ImageDepot input) {
    TestLogger.logger.debug("MtomSampleMTOMDisable2Service [new sendImage request received]");
    DataHandler data = input.getImageData();
    TestLogger.logger.debug("[contentType] " + data.getContentType());
    ImageDepot output = (new ObjectFactory()).createImageDepot();
    Image image = null;
    resetAttachmentUnmarshallingMonitor();
    try {
        InputStream stream = (InputStream) data.getContent();
        image = ImageIO.read(stream);
        DataSource imageDS = new DataSourceImpl("image/jpeg", "test.jpg", image);
        DataHandler handler = new DataHandler(imageDS);
        output.setImageData(handler);
    } catch (Exception e) {
        throw new WebServiceException(e);
    }
    return output;
}
Also used : ObjectFactory(org.test.mtom.ObjectFactory) WebServiceException(javax.xml.ws.WebServiceException) ImageDepot(org.test.mtom.ImageDepot) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) DataSourceImpl(org.apache.axis2.jaxws.provider.DataSourceImpl) DataHandler(javax.activation.DataHandler) WebServiceException(javax.xml.ws.WebServiceException) DataSource(javax.activation.DataSource)

Example 2 with ImageDepot

use of org.apache.axis2.jaxws.sample.mtom1.ImageDepot in project axis-axis2-java-core by apache.

the class MtomSampleMTOMDisableService method sendImage.

public ImageDepot sendImage(ImageDepot input) {
    TestLogger.logger.debug("MtomSampleMTOMDisableService [new sendImage request received]");
    DataHandler data = input.getImageData();
    TestLogger.logger.debug("[contentType] " + data.getContentType());
    ImageDepot output = (new ObjectFactory()).createImageDepot();
    Image image = null;
    resetAttachmentUnmarshallingMonitor();
    try {
        InputStream stream = (InputStream) data.getContent();
        image = ImageIO.read(stream);
        DataSource imageDS = new DataSourceImpl("image/jpeg", "test.jpg", image);
        DataHandler handler = new DataHandler(imageDS);
        output.setImageData(handler);
    } catch (Exception e) {
        throw new WebServiceException(e);
    }
    return output;
}
Also used : ObjectFactory(org.test.mtom.ObjectFactory) WebServiceException(javax.xml.ws.WebServiceException) ImageDepot(org.test.mtom.ImageDepot) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) DataSourceImpl(org.apache.axis2.jaxws.provider.DataSourceImpl) DataHandler(javax.activation.DataHandler) WebServiceException(javax.xml.ws.WebServiceException) DataSource(javax.activation.DataSource)

Example 3 with ImageDepot

use of org.apache.axis2.jaxws.sample.mtom1.ImageDepot in project axis-axis2-java-core by apache.

the class MtomSampleMTOMEnableService method sendImage.

public ImageDepot sendImage(ImageDepot input) {
    TestLogger.logger.debug("MtomSampleMTOMEnableService [new sendImage request received]");
    DataHandler data = input.getImageData();
    TestLogger.logger.debug("[contentType] " + data.getContentType());
    ImageDepot output = (new ObjectFactory()).createImageDepot();
    Image image = null;
    resetAttachmentUnmarshallingMonitor();
    try {
        InputStream stream = (InputStream) data.getContent();
        image = ImageIO.read(stream);
        DataSource imageDS = new DataSourceImpl("image/jpeg", "test.jpg", image);
        DataHandler handler = new DataHandler(imageDS);
        output.setImageData(handler);
    } catch (Exception e) {
        throw new WebServiceException(e);
    }
    return output;
}
Also used : ObjectFactory(org.test.mtom.ObjectFactory) WebServiceException(javax.xml.ws.WebServiceException) ImageDepot(org.test.mtom.ImageDepot) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) DataSourceImpl(org.apache.axis2.jaxws.provider.DataSourceImpl) DataHandler(javax.activation.DataHandler) WebServiceException(javax.xml.ws.WebServiceException) DataSource(javax.activation.DataSource)

Example 4 with ImageDepot

use of org.apache.axis2.jaxws.sample.mtom1.ImageDepot in project axis-axis2-java-core by apache.

the class MtomSampleMTOMThresholdService method sendImage.

public ImageDepot sendImage(ImageDepot input) {
    TestLogger.logger.debug("MtomSampleMTOMEnableService [new sendImage request received]");
    DataHandler data = input.getImageData();
    TestLogger.logger.debug("[contentType] " + data.getContentType());
    ImageDepot output = (new ObjectFactory()).createImageDepot();
    Image image = null;
    resetAttachmentUnmarshallingMonitor();
    try {
        InputStream stream = (InputStream) data.getContent();
        image = ImageIO.read(stream);
        DataSource imageDS = new DataSourceImpl("image/jpeg", "test.jpg", image);
        DataHandler handler = new DataHandler(imageDS);
        output.setImageData(handler);
    } catch (Exception e) {
        throw new WebServiceException(e);
    }
    return output;
}
Also used : ObjectFactory(org.test.mtom.ObjectFactory) WebServiceException(javax.xml.ws.WebServiceException) ImageDepot(org.test.mtom.ImageDepot) InputStream(java.io.InputStream) DataSourceImpl(org.apache.axis2.jaxws.provider.DataSourceImpl) DataHandler(javax.activation.DataHandler) Image(java.awt.Image) WebServiceException(javax.xml.ws.WebServiceException) DataSource(javax.activation.DataSource)

Example 5 with ImageDepot

use of org.apache.axis2.jaxws.sample.mtom1.ImageDepot in project axis-axis2-java-core by apache.

the class SampleMTOMTests method testMtomWithProxy.

/**
 * Tests sending an image with MTOM, using a JAX-WS Dynamic Proxy.
 *
 * @param result - String - used to pass back results to servlet.
 * @return String - the input string or null
 * @throws Exception
 */
public String testMtomWithProxy(String result, URL url) throws Exception {
    ImageDepot response;
    System.out.println(">>---------------------------------------");
    System.out.println(">>MTOM Proxy Test");
    init();
    // Set the data inside of the appropriate object
    ImageDepot imageDepot = new ObjectFactory().createImageDepot();
    imageDepot.setImageData(content);
    if (null != result) {
        result = result.concat("Invoking MTOM proxy with a binary payload\n");
    } else {
        System.out.println(">>MTOM Invoking proxy with a binary payload");
    }
    // Setup the necessary JAX-WS artifacts
    try {
        if (soap12) {
            // Use the generated proxy
            MtomSample12PortProxy proxy = new MtomSample12PortProxy(url);
            proxy._getDescriptor().setEndpoint(uriString + urlSuffix);
            // Enable MTOM
            BindingProvider bp = (BindingProvider) proxy._getDescriptor().getProxy();
            SOAPBinding binding = (SOAPBinding) bp.getBinding();
            binding.setMTOMEnabled(true);
            // Send the image and process the response image
            response = proxy.sendImage(imageDepot);
        } else {
            // SOAP 1.1 Create the service
            // Use the generated proxy
            MtomSamplePortProxy proxy = new MtomSamplePortProxy(url);
            proxy._getDescriptor().setEndpoint(uriString + urlSuffix);
            // Enable MTOM
            BindingProvider bp = (BindingProvider) proxy._getDescriptor().getProxy();
            SOAPBinding binding = (SOAPBinding) bp.getBinding();
            binding.setMTOMEnabled(true);
            // Send the image and process the response image
            response = proxy.sendImage(imageDepot);
        }
        if (null != result) {
            if (response != null) {
                result = result.concat("MTOM Proxy Response received - " + response.getImageData().getContentType());
            } else {
                result = result.concat("ERROR: MTOM Proxy NULL Response received\n");
            }
        } else {
            if (response != null) {
                System.out.println(">>MTOM Response received");
                System.out.println(">>MTOM Writing returned image to proxy_response.gif");
                processImageDepot(response, "proxy_response.gif");
            } else {
                System.out.println(">> [ERROR] - Response from the server was NULL");
            }
        }
    } catch (Exception e) {
        if (null != result) {
            result = result.concat(">> [ERROR] - Exception making connection.");
        }
        System.out.println(">> [ERROR] - Exception making connection.");
        e.printStackTrace();
    }
    System.out.println(">>MTOM Proxy Done");
    return (result);
}
Also used : ObjectFactory(org.apache.axis2.jaxws.samples.mtom.ObjectFactory) ImageDepot(org.apache.axis2.jaxws.samples.mtom.ImageDepot) SOAPBinding(javax.xml.ws.soap.SOAPBinding) BindingProvider(javax.xml.ws.BindingProvider) FileNotFoundException(java.io.FileNotFoundException)

Aggregations

DataHandler (javax.activation.DataHandler)21 ImageDepot (org.test.mtom.ImageDepot)21 ObjectFactory (org.test.mtom.ObjectFactory)19 DataSource (javax.activation.DataSource)17 DataSourceImpl (org.apache.axis2.jaxws.provider.DataSourceImpl)17 File (java.io.File)15 JAXBContext (javax.xml.bind.JAXBContext)15 Service (javax.xml.ws.Service)15 SendImage (org.test.mtom.SendImage)15 Test (org.junit.Test)14 Image (java.awt.Image)12 FileImageInputStream (javax.imageio.stream.FileImageInputStream)11 ImageInputStream (javax.imageio.stream.ImageInputStream)11 SendImageResponse (org.test.mtom.SendImageResponse)11 SOAPBinding (javax.xml.ws.soap.SOAPBinding)7 InputStream (java.io.InputStream)6 List (java.util.List)6 WebServiceException (javax.xml.ws.WebServiceException)6 MTOMFeature (javax.xml.ws.soap.MTOMFeature)6 ByteArrayInputStream (java.io.ByteArrayInputStream)5