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());
}
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());
}
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);
}
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));
}
}
}
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());
}
Aggregations