use of javax.xml.ws.soap.SOAPBinding in project tomee by apache.
the class AttachmentTest method testAttachmentViaWsInterface.
// END SNIPPET: setup
/**
* Create a webservice client using wsdl url
*
* @throws Exception
*/
// START SNIPPET: webservice
public void testAttachmentViaWsInterface() throws Exception {
Service service = Service.create(new URL("http://localhost:" + port + "/webservice-attachments/AttachmentImpl?wsdl"), new QName("http://superbiz.org/wsdl", "AttachmentWsService"));
assertNotNull(service);
AttachmentWs ws = service.getPort(AttachmentWs.class);
// retrieve the SOAPBinding
SOAPBinding binding = (SOAPBinding) ((BindingProvider) ws).getBinding();
binding.setMTOMEnabled(true);
String request = "tsztelak@gmail.com";
// Byte array
String response = ws.stringFromBytes(request.getBytes());
assertEquals(request, response);
// Data Source
DataSource source = new ByteArrayDataSource(request.getBytes(), "text/plain; charset=UTF-8");
// not yet supported !
// response = ws.stringFromDataSource(source);
// assertEquals(request, response);
// Data Handler
response = ws.stringFromDataHandler(new DataHandler(source));
assertEquals(request, response);
}
use of javax.xml.ws.soap.SOAPBinding in project cxf by apache.
the class JaxWsClientProxy method mapException.
Exception mapException(Method method, BindingOperationInfo boi, Exception ex) {
if (method != null) {
for (Class<?> excls : method.getExceptionTypes()) {
if (excls.isInstance(ex)) {
return ex;
}
}
} else if (boi != null) {
for (BindingFaultInfo fi : boi.getFaults()) {
Class<?> c = fi.getFaultInfo().getProperty(Class.class.getName(), Class.class);
if (c != null && c.isInstance(ex)) {
return ex;
}
}
if (ex instanceof IOException) {
return ex;
}
}
if (ex instanceof Fault && ex.getCause() instanceof IOException) {
return new WebServiceException(ex.getMessage(), ex.getCause());
}
if (getBinding() instanceof HTTPBinding) {
HTTPException exception = new HTTPException(HttpURLConnection.HTTP_INTERNAL_ERROR);
exception.initCause(ex);
return exception;
} else if (getBinding() instanceof SOAPBinding) {
try {
SOAPFault soapFault = createSoapFault((SOAPBinding) getBinding(), ex);
if (soapFault == null) {
throw new WebServiceException(ex);
}
SOAPFaultException exception = new SOAPFaultException(soapFault);
if (ex instanceof Fault && ex.getCause() != null) {
exception.initCause(ex.getCause());
} else {
exception.initCause(ex);
}
return exception;
} catch (SOAPException e) {
return new WebServiceException(ex);
}
}
return new WebServiceException(ex);
}
use of javax.xml.ws.soap.SOAPBinding in project cxf by apache.
the class DispatchImpl method mapException.
private RuntimeException mapException(Exception ex) {
if (ex instanceof Fault && ex.getCause() instanceof IOException) {
throw new WebServiceException(ex.getMessage(), ex.getCause());
}
if (getBinding() instanceof HTTPBinding) {
HTTPException exception = new HTTPException(HttpURLConnection.HTTP_INTERNAL_ERROR);
exception.initCause(ex);
return exception;
} else if (getBinding() instanceof SOAPBinding) {
SOAPFault soapFault = null;
try {
soapFault = JaxWsClientProxy.createSoapFault((SOAPBinding) getBinding(), ex);
} catch (SOAPException e) {
// ignore
}
if (soapFault == null) {
return new WebServiceException(ex);
}
SOAPFaultException exception = new SOAPFaultException(soapFault);
exception.initCause(ex);
return exception;
}
return new WebServiceException(ex);
}
use of javax.xml.ws.soap.SOAPBinding in project cxf by apache.
the class ClientMtomXopWithJMSTest method startServers.
@BeforeClass
public static void startServers() throws Exception {
Object implementor = new TestMtomJMSImpl();
bus = BusFactory.getDefaultBus();
ActiveMQConnectionFactory cf = new ActiveMQConnectionFactory("vm://localhost?broker.persistent=false");
PooledConnectionFactory cfp = new PooledConnectionFactory(cf);
cff = new ConnectionFactoryFeature(cfp);
EndpointImpl ep = (EndpointImpl) Endpoint.create(implementor);
ep.getFeatures().add(cff);
ep.getInInterceptors().add(new TestMultipartMessageInterceptor());
ep.getOutInterceptors().add(new TestAttachmentOutInterceptor());
// ep.getInInterceptors().add(new LoggingInInterceptor());
// ep.getOutInterceptors().add(new LoggingOutInterceptor());
SOAPBinding jaxWsSoapBinding = (SOAPBinding) ep.getBinding();
jaxWsSoapBinding.setMTOMEnabled(true);
ep.publish();
}
use of javax.xml.ws.soap.SOAPBinding in project cxf by apache.
the class MTOMBindingTypeTest method testDetail.
@Test
public void testDetail() throws Exception {
ByteArrayOutputStream input = setupInLogging();
ByteArrayOutputStream output = setupOutLogging();
Holder<byte[]> photo = new Holder<>("CXF".getBytes());
Holder<Image> image = new Holder<>(getImage("/java.jpg"));
Hello port = getPort();
SOAPBinding binding = (SOAPBinding) ((BindingProvider) port).getBinding();
binding.setMTOMEnabled(true);
port.detail(photo, image);
String expected = "<xop:Include ";
assertTrue(output.toString().indexOf(expected) != -1);
assertTrue(input.toString().indexOf(expected) != -1);
assertEquals("CXF", new String(photo.value));
assertNotNull(image.value);
}
Aggregations