Search in sources :

Example 1 with SendImageResponse

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

the class MtomSampleByteArrayTests method testAttachmentByteArrayAPI11.

/*
     * Enable attachment Optimization through the SOAPBinding method 
     * -- setMTOMEnabled([true|false])
     * Using SOAP11
     */
@Ignore
@Test
public void testAttachmentByteArrayAPI11() throws Exception {
    TestLogger.logger.debug("----------------------------------");
    String imageResourceDir = IMAGE_DIR;
    Service svc = Service.create(QNAME_SERVICE);
    svc.addPort(QNAME_PORT, SOAPBinding.SOAP11HTTP_BINDING, getEndpoint());
    JAXBContext jbc = JAXBContext.newInstance("org.apache.axis2.jaxws.sample.mtom1");
    Dispatch<Object> dispatch = svc.createDispatch(QNAME_PORT, jbc, Service.Mode.PAYLOAD);
    SOAPBinding binding = (SOAPBinding) dispatch.getBinding();
    binding.setMTOMEnabled(true);
    Image image = ImageIO.read(new File(imageResourceDir + File.separator + "test.jpg"));
    ImageDepot imageDepot = new ObjectFactory().createImageDepot();
    imageDepot.setImageData(image);
    setText(imageDepot);
    // Create a request bean with imagedepot bean as value
    ObjectFactory factory = new ObjectFactory();
    Invoke request = factory.createInvoke();
    request.setInput(imageDepot);
    SendImageResponse response = (SendImageResponse) dispatch.invoke(request);
    assertNotNull(response);
    assertNotNull(response.getOutput().getImageData());
    checkText(response.getOutput());
    // Repeat to verify behavior
    response = (SendImageResponse) dispatch.invoke(request);
    assertNotNull(response);
    assertNotNull(response.getOutput().getImageData());
    checkText(response.getOutput());
}
Also used : ObjectFactory(org.apache.axis2.jaxws.sample.mtom1.ObjectFactory) ImageDepot(org.apache.axis2.jaxws.sample.mtom1.ImageDepot) Service(javax.xml.ws.Service) SOAPBinding(javax.xml.ws.soap.SOAPBinding) JAXBContext(javax.xml.bind.JAXBContext) SendImageResponse(org.apache.axis2.jaxws.sample.mtom1.SendImageResponse) File(java.io.File) Invoke(org.apache.axis2.jaxws.sample.mtom1.Invoke) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 2 with SendImageResponse

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

the class MtomSampleByteArrayTests method testAttachmentByteArrayProperty11.

/*
     * Enable attachment optimization using the SOAP11 binding
     * property for MTOM.
     */
@Test
public void testAttachmentByteArrayProperty11() throws Exception {
    TestLogger.logger.debug("----------------------------------");
    String imageResourceDir = IMAGE_DIR;
    Service svc = Service.create(QNAME_SERVICE);
    svc.addPort(QNAME_PORT, SOAPBinding.SOAP11HTTP_MTOM_BINDING, getEndpoint());
    JAXBContext jbc = JAXBContext.newInstance("org.apache.axis2.jaxws.sample.mtom1");
    Dispatch<Object> dispatch = svc.createDispatch(QNAME_PORT, jbc, Service.Mode.PAYLOAD);
    Image image = ImageIO.read(new File(imageResourceDir + File.separator + "test.jpg"));
    ImageDepot imageDepot = new ObjectFactory().createImageDepot();
    imageDepot.setImageData(image);
    setText(imageDepot);
    // Create a request bean with imagedepot bean as value
    ObjectFactory factory = new ObjectFactory();
    Invoke request = factory.createInvoke();
    request.setInput(imageDepot);
    SendImageResponse response = (SendImageResponse) dispatch.invoke(request);
    assertNotNull(response);
    assertNotNull(response.getOutput().getImageData());
    checkText(response.getOutput());
    // Repeat to verify behavior
    response = (SendImageResponse) dispatch.invoke(request);
    assertNotNull(response);
    assertNotNull(response.getOutput().getImageData());
    checkText(response.getOutput());
}
Also used : ObjectFactory(org.apache.axis2.jaxws.sample.mtom1.ObjectFactory) ImageDepot(org.apache.axis2.jaxws.sample.mtom1.ImageDepot) Service(javax.xml.ws.Service) JAXBContext(javax.xml.bind.JAXBContext) SendImageResponse(org.apache.axis2.jaxws.sample.mtom1.SendImageResponse) File(java.io.File) Invoke(org.apache.axis2.jaxws.sample.mtom1.Invoke) Test(org.junit.Test)

Example 3 with SendImageResponse

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

the class MtomSampleTests method testSendImage_MTOMDisable.

/*
     * Enable attachment Optimization but call an endpoint with @MTOM(enable=false)
     */
@Test
public void testSendImage_MTOMDisable() throws Exception {
    TestLogger.logger.debug("----------------------------------");
    String imageResourceDir = IMAGE_DIR;
    // Create a DataSource from an image
    File file = new File(imageResourceDir + File.separator + "test.jpg");
    ImageInputStream fiis = new FileImageInputStream(file);
    Image image = ImageIO.read(fiis);
    DataSource imageDS = new DataSourceImpl("image/jpeg", "test.jpg", image);
    // Create a DataHandler with the String DataSource object
    DataHandler dataHandler = new DataHandler(imageDS);
    // Store the data handler in ImageDepot bean
    ImageDepot imageDepot = new ObjectFactory().createImageDepot();
    imageDepot.setImageData(dataHandler);
    SendImage request = new ObjectFactory().createSendImage();
    request.setInput(imageDepot);
    // Create the necessary JAXBContext
    JAXBContext jbc = JAXBContext.newInstance("org.test.mtom");
    MTOMFeature mtom21 = new MTOMFeature();
    // Create the JAX-WS client needed to send the request
    Service service = Service.create(QNAME_SERVICE);
    service.addPort(QNAME_PORT, SOAPBinding.SOAP11HTTP_BINDING, server.getEndpoint("MtomSampleMTOMDisableService.MtomSampleMTOMDisableServicePort"));
    Dispatch<Object> dispatch = service.createDispatch(QNAME_PORT, jbc, Mode.PAYLOAD, mtom21);
    List cids = null;
    SendImageResponse response = null;
    try {
        JAXBAttachmentUnmarshallerMonitor.setMonitoring(true);
        response = (SendImageResponse) dispatch.invoke(request);
        // The cids are collected in the monitor.  We will check
        // this to make sure the response mtom is not inlined
        cids = JAXBAttachmentUnmarshallerMonitor.getBlobCIDs();
    } finally {
        JAXBAttachmentUnmarshallerMonitor.setMonitoring(false);
    }
    assertNotNull(response);
    assertNotNull(response.getOutput().getImageData());
    int numCIDs = (cids == null) ? 0 : cids.size();
    assertTrue("Expected zero attachments but there were:" + numCIDs, numCIDs == 0);
    // Repeat to verify behavior
    response = null;
    try {
        JAXBAttachmentUnmarshallerMonitor.setMonitoring(true);
        response = (SendImageResponse) dispatch.invoke(request);
        // The cids are collected in the monitor.  We will check
        // this to make sure the response mtom is not inlined
        cids = JAXBAttachmentUnmarshallerMonitor.getBlobCIDs();
    } finally {
        JAXBAttachmentUnmarshallerMonitor.setMonitoring(false);
    }
    assertNotNull(response);
    assertNotNull(response.getOutput().getImageData());
    numCIDs = (cids == null) ? 0 : cids.size();
    assertTrue("Expected zero attachments but there were:" + numCIDs, numCIDs == 0);
}
Also used : SendImage(org.test.mtom.SendImage) DataSourceImpl(org.apache.axis2.jaxws.provider.DataSourceImpl) FileImageInputStream(javax.imageio.stream.FileImageInputStream) ImageInputStream(javax.imageio.stream.ImageInputStream) MTOMFeature(javax.xml.ws.soap.MTOMFeature) Service(javax.xml.ws.Service) JAXBContext(javax.xml.bind.JAXBContext) DataHandler(javax.activation.DataHandler) SendImage(org.test.mtom.SendImage) Image(java.awt.Image) DataSource(javax.activation.DataSource) FileImageInputStream(javax.imageio.stream.FileImageInputStream) ObjectFactory(org.test.mtom.ObjectFactory) ImageDepot(org.test.mtom.ImageDepot) List(java.util.List) SendImageResponse(org.test.mtom.SendImageResponse) File(java.io.File) Test(org.junit.Test)

Example 4 with SendImageResponse

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

the class MtomSampleTests method testSendImageAttachmentProperty12.

/*
     * Enable attachment optimization using both the SOAP12 binding
     * property for MTOM
     * 
     * Sending SOAP12 message to SOAP11 endpoint will correctly result in exception
     * 
     */
@Test
public void testSendImageAttachmentProperty12() throws Exception {
    TestLogger.logger.debug("----------------------------------");
    String imageResourceDir = IMAGE_DIR;
    // Create a DataSource from an image
    File file = new File(imageResourceDir + File.separator + "test.jpg");
    ImageInputStream fiis = new FileImageInputStream(file);
    Image image = ImageIO.read(fiis);
    DataSource imageDS = new DataSourceImpl("image/jpeg", "test.jpg", image);
    // Create a DataHandler with the String DataSource object
    DataHandler dataHandler = new DataHandler(imageDS);
    // Store the data handler in ImageDepot bean
    ImageDepot imageDepot = new ObjectFactory().createImageDepot();
    imageDepot.setImageData(dataHandler);
    SendImage request = new ObjectFactory().createSendImage();
    request.setInput(imageDepot);
    // Create the necessary JAXBContext
    JAXBContext jbc = JAXBContext.newInstance("org.test.mtom");
    // Create the JAX-WS client needed to send the request with soap 11 binding
    // property for MTOM
    Service service = Service.create(QNAME_SERVICE);
    service.addPort(QNAME_PORT, SOAPBinding.SOAP12HTTP_MTOM_BINDING, server.getEndpoint("MtomSampleService.MtomSampleServicePort"));
    Dispatch<Object> dispatch = service.createDispatch(QNAME_PORT, jbc, Mode.PAYLOAD);
    try {
        SendImageResponse response = (SendImageResponse) dispatch.invoke(request);
        fail("Was expecting an exception due to sending SOAP12 message to SOAP11 endpoint.");
    } catch (Exception e) {
        assertNotNull(e);
        if (CHECK_VERSIONMISMATCH) {
            assertTrue("Expected SOAPFaultException, but received: " + e.getClass(), e instanceof SOAPFaultException);
            SOAPFaultException sfe = (SOAPFaultException) e;
            SOAPFault fault = sfe.getFault();
            assertTrue("SOAPFault is null ", fault != null);
            QName faultCode = sfe.getFault().getFaultCodeAsQName();
            assertTrue("Expected VERSION MISMATCH but received: " + faultCode, new QName(SOAPConstants.URI_NS_SOAP_1_1_ENVELOPE, "VersionMismatch", SOAPConstants.SOAP_ENV_PREFIX).equals(faultCode));
        }
    }
    // Repeat to verify behavior
    try {
        SendImageResponse response = (SendImageResponse) dispatch.invoke(request);
        fail("Was expecting an exception due to sending SOAP12 message to SOAP11 endpoint.");
    } catch (Exception e) {
        assertNotNull(e);
        if (CHECK_VERSIONMISMATCH) {
            assertTrue("Expected SOAPFaultException, but received: " + e.getClass(), e instanceof SOAPFaultException);
            SOAPFaultException sfe = (SOAPFaultException) e;
            SOAPFault fault = sfe.getFault();
            assertTrue("SOAPFault is null ", fault != null);
            QName faultCode = sfe.getFault().getFaultCodeAsQName();
            assertTrue("Expected VERSION MISMATCH but received: " + faultCode, new QName(SOAPConstants.URI_NS_SOAP_1_1_ENVELOPE, "VersionMismatch", SOAPConstants.SOAP_ENV_PREFIX).equals(faultCode));
        }
    }
}
Also used : SendImage(org.test.mtom.SendImage) DataSourceImpl(org.apache.axis2.jaxws.provider.DataSourceImpl) QName(javax.xml.namespace.QName) FileImageInputStream(javax.imageio.stream.FileImageInputStream) ImageInputStream(javax.imageio.stream.ImageInputStream) Service(javax.xml.ws.Service) JAXBContext(javax.xml.bind.JAXBContext) SOAPFaultException(javax.xml.ws.soap.SOAPFaultException) DataHandler(javax.activation.DataHandler) SendImage(org.test.mtom.SendImage) Image(java.awt.Image) SOAPFaultException(javax.xml.ws.soap.SOAPFaultException) DataSource(javax.activation.DataSource) FileImageInputStream(javax.imageio.stream.FileImageInputStream) ObjectFactory(org.test.mtom.ObjectFactory) ImageDepot(org.test.mtom.ImageDepot) SOAPFault(javax.xml.soap.SOAPFault) SendImageResponse(org.test.mtom.SendImageResponse) File(java.io.File) Test(org.junit.Test)

Example 5 with SendImageResponse

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

the class MtomSampleTests method testSendImageAttachmentProperty11.

/*
     * Enable attachment optimization using the SOAP11 binding
     * property for MTOM.
     */
@Test
public void testSendImageAttachmentProperty11() throws Exception {
    TestLogger.logger.debug("----------------------------------");
    String imageResourceDir = IMAGE_DIR;
    // Create a DataSource from an image
    File file = new File(imageResourceDir + File.separator + "test.jpg");
    ImageInputStream fiis = new FileImageInputStream(file);
    Image image = ImageIO.read(fiis);
    DataSource imageDS = new DataSourceImpl("image/jpeg", "test.jpg", image);
    // Create a DataHandler with the String DataSource object
    DataHandler dataHandler = new DataHandler(imageDS);
    // Store the data handler in ImageDepot bean
    ImageDepot imageDepot = new ObjectFactory().createImageDepot();
    imageDepot.setImageData(dataHandler);
    SendImage request = new ObjectFactory().createSendImage();
    request.setInput(imageDepot);
    // Create the necessary JAXBContext
    JAXBContext jbc = JAXBContext.newInstance("org.test.mtom");
    // Create the JAX-WS client needed to send the request with soap 11 binding
    // property for MTOM
    Service service = Service.create(QNAME_SERVICE);
    service.addPort(QNAME_PORT, SOAPBinding.SOAP11HTTP_MTOM_BINDING, server.getEndpoint("MtomSampleService.MtomSampleServicePort"));
    Dispatch<Object> dispatch = service.createDispatch(QNAME_PORT, jbc, Mode.PAYLOAD);
    SendImageResponse response = (SendImageResponse) dispatch.invoke(request);
    assertNotNull(response);
    assertNotNull(response.getOutput().getImageData());
    // Repeat to verify behavior
    response = (SendImageResponse) dispatch.invoke(request);
    assertNotNull(response);
    assertNotNull(response.getOutput().getImageData());
}
Also used : SendImage(org.test.mtom.SendImage) DataSourceImpl(org.apache.axis2.jaxws.provider.DataSourceImpl) FileImageInputStream(javax.imageio.stream.FileImageInputStream) ImageInputStream(javax.imageio.stream.ImageInputStream) Service(javax.xml.ws.Service) JAXBContext(javax.xml.bind.JAXBContext) DataHandler(javax.activation.DataHandler) SendImage(org.test.mtom.SendImage) Image(java.awt.Image) DataSource(javax.activation.DataSource) FileImageInputStream(javax.imageio.stream.FileImageInputStream) ObjectFactory(org.test.mtom.ObjectFactory) ImageDepot(org.test.mtom.ImageDepot) SendImageResponse(org.test.mtom.SendImageResponse) File(java.io.File) Test(org.junit.Test)

Aggregations

JAXBContext (javax.xml.bind.JAXBContext)15 Service (javax.xml.ws.Service)15 File (java.io.File)14 Test (org.junit.Test)14 Image (java.awt.Image)11 DataHandler (javax.activation.DataHandler)11 DataSource (javax.activation.DataSource)11 FileImageInputStream (javax.imageio.stream.FileImageInputStream)11 ImageInputStream (javax.imageio.stream.ImageInputStream)11 DataSourceImpl (org.apache.axis2.jaxws.provider.DataSourceImpl)11 ImageDepot (org.test.mtom.ImageDepot)11 ObjectFactory (org.test.mtom.ObjectFactory)11 SendImage (org.test.mtom.SendImage)11 SendImageResponse (org.test.mtom.SendImageResponse)11 List (java.util.List)6 MTOMFeature (javax.xml.ws.soap.MTOMFeature)6 SOAPBinding (javax.xml.ws.soap.SOAPBinding)6 ImageDepot (org.apache.axis2.jaxws.sample.mtom1.ImageDepot)3 Invoke (org.apache.axis2.jaxws.sample.mtom1.Invoke)3 ObjectFactory (org.apache.axis2.jaxws.sample.mtom1.ObjectFactory)3