use of javax.xml.ws.soap.SOAPBinding in project cxf by apache.
the class Client method main.
public static void main(String[] args) throws Exception {
if (args.length == 0) {
System.out.println("Please specify the WSDL file.");
System.exit(1);
}
URL wsdlURL;
File wsdlFile = new File(args[0]);
if (wsdlFile.exists()) {
wsdlURL = wsdlFile.toURI().toURL();
} else {
wsdlURL = new URL(args[0]);
}
System.out.println(wsdlURL);
TestMtomService tms = new TestMtomService(wsdlURL, SERVICE_NAME);
TestMtomPortType port = (TestMtomPortType) tms.getPort(PORT_NAME, TestMtomPortType.class);
Binding binding = ((BindingProvider) port).getBinding();
((SOAPBinding) binding).setMTOMEnabled(true);
URL fileURL = Client.class.getResource("/me.bmp");
File aFile = new File(new URI(fileURL.toString()));
long fileSize = aFile.length();
System.out.println("Filesize of me.bmp image is: " + fileSize);
System.out.println("\nStarting MTOM Test using basic byte array:");
Holder<String> name = new Holder<>("Sam");
Holder<byte[]> param = new Holder<>();
param.value = new byte[(int) fileSize];
InputStream in = fileURL.openStream();
int len = in.read(param.value);
while (len < fileSize) {
len += in.read(param.value, len, (int) (fileSize - len));
}
System.out.println("--Sending the me.bmp image to server");
System.out.println("--Sending a name value of " + name.value);
port.testByteArray(name, param);
System.out.println("--Received byte[] back from server, returned size is " + param.value.length);
System.out.println("--Returned string value is " + name.value);
Image image = ImageIO.read(new ByteArrayInputStream(param.value));
System.out.println("--Loaded image from byte[] successfully, hashCode=" + image.hashCode());
System.out.println("Successfully ran MTOM/byte array demo");
System.out.println("\nStarting MTOM test with DataHandler:");
name.value = "Bob";
Holder<DataHandler> handler = new Holder<>();
handler.value = new DataHandler(fileURL);
System.out.println("--Sending the me.bmp image to server");
System.out.println("--Sending a name value of " + name.value);
port.testDataHandler(name, handler);
InputStream mtomIn = handler.value.getInputStream();
fileSize = 0;
for (int i = mtomIn.read(); i != -1; i = mtomIn.read()) {
fileSize++;
}
System.out.println("--Received DataHandler back from server, " + "returned size is " + fileSize);
System.out.println("--Returned string value is " + name.value);
System.out.println("Successfully ran MTOM/DataHandler demo");
System.exit(0);
}
use of javax.xml.ws.soap.SOAPBinding in project cxf by apache.
the class ServiceImpl method initializePorts.
private void initializePorts() {
try {
Definition def = bus.getExtension(WSDLManager.class).getDefinition(wsdlURL);
javax.wsdl.Service serv = def.getService(serviceName);
if (serv == null) {
throw new WebServiceException("Could not find service named " + serviceName + " in wsdl " + wsdlURL);
}
Map<String, Port> wsdlports = CastUtils.cast(serv.getPorts());
for (Port port : wsdlports.values()) {
QName name = new QName(serviceName.getNamespaceURI(), port.getName());
String address = null;
String bindingID = null;
List<? extends ExtensibilityElement> extensions = CastUtils.cast(port.getBinding().getExtensibilityElements());
if (!extensions.isEmpty()) {
ExtensibilityElement e = extensions.get(0);
if (e instanceof SoapBinding) {
bindingID = SOAPBinding.SOAP11HTTP_BINDING;
} else if (e instanceof SOAP12Binding) {
bindingID = SOAPBinding.SOAP12HTTP_BINDING;
} else if (e instanceof javax.wsdl.extensions.soap.SOAPBinding) {
bindingID = SOAPBinding.SOAP11HTTP_BINDING;
}
}
extensions = CastUtils.cast(port.getExtensibilityElements());
if (!extensions.isEmpty()) {
ExtensibilityElement e = extensions.get(0);
if (e instanceof SoapAddress) {
address = ((SoapAddress) e).getLocationURI();
} else if (e instanceof AddressType) {
address = ((AddressType) e).getLocation();
} else if (e instanceof SOAP12Address) {
address = ((SOAP12Address) e).getLocationURI();
} else if (e instanceof SOAPAddress) {
address = ((SOAPAddress) e).getLocationURI();
} else if (e instanceof HTTPAddress) {
address = ((HTTPAddress) e).getLocationURI();
}
}
addPort(name, bindingID, address);
}
} catch (WebServiceException e) {
throw e;
} catch (Throwable e) {
if (e instanceof UncheckedException && LOG.isLoggable(Level.FINE)) {
LOG.log(Level.FINE, e.getLocalizedMessage(), e);
}
WSDLServiceFactory sf = new WSDLServiceFactory(bus, wsdlURL, serviceName);
Service service = sf.create();
for (ServiceInfo si : service.getServiceInfos()) {
for (EndpointInfo ei : si.getEndpoints()) {
String bindingID = BindingID.getJaxwsBindingID(ei.getTransportId());
addPort(ei.getName(), bindingID, ei.getAddress());
}
}
}
}
use of javax.xml.ws.soap.SOAPBinding in project cxf by apache.
the class DispatchTest method testSOAPPBinding.
@Test
public void testSOAPPBinding() throws Exception {
ServiceImpl service = new ServiceImpl(getBus(), null, SERVICE_NAME, null);
service.addPort(PORT_NAME, SOAPBinding.SOAP11HTTP_BINDING, "local://foobar");
Dispatch<Source> disp = service.createDispatch(PORT_NAME, Source.class, Service.Mode.MESSAGE);
assertTrue(disp.getBinding() instanceof SOAPBinding);
}
use of javax.xml.ws.soap.SOAPBinding in project cxf by apache.
the class SOAPBindingTest method testSAAJ.
@Test
public void testSAAJ() throws Exception {
URL wsdl1 = getClass().getResource("/wsdl/calculator.wsdl");
assertNotNull(wsdl1);
ServiceImpl service = new ServiceImpl(getBus(), wsdl1, SERVICE_1, ServiceImpl.class);
CalculatorPortType cal = service.getPort(PORT_1, CalculatorPortType.class);
BindingProvider bindingProvider = (BindingProvider) cal;
assertTrue(bindingProvider.getBinding() instanceof SOAPBinding);
SOAPBinding binding = (SOAPBinding) bindingProvider.getBinding();
assertNotNull(binding.getMessageFactory());
assertNotNull(binding.getSOAPFactory());
}
use of javax.xml.ws.soap.SOAPBinding in project cxf by apache.
the class SOAPBindingTest method testRoles.
@Test
public void testRoles() throws Exception {
URL wsdl1 = getClass().getResource("/wsdl/calculator.wsdl");
assertNotNull(wsdl1);
ServiceImpl service = new ServiceImpl(getBus(), wsdl1, SERVICE_1, ServiceImpl.class);
CalculatorPortType cal = service.getPort(PORT_1, CalculatorPortType.class);
BindingProvider bindingProvider = (BindingProvider) cal;
assertTrue(bindingProvider.getBinding() instanceof SOAPBinding);
SOAPBinding binding = (SOAPBinding) bindingProvider.getBinding();
assertNotNull(binding.getRoles());
assertEquals(2, binding.getRoles().size());
assertTrue(binding.getRoles().contains(Soap12.getInstance().getNextRole()));
assertTrue(binding.getRoles().contains(Soap12.getInstance().getUltimateReceiverRole()));
String myrole = "http://myrole";
Set<String> roles = new HashSet<>();
roles.add(myrole);
binding.setRoles(roles);
assertNotNull(binding.getRoles());
assertEquals(3, binding.getRoles().size());
assertTrue(binding.getRoles().contains(myrole));
assertTrue(binding.getRoles().contains(Soap12.getInstance().getNextRole()));
assertTrue(binding.getRoles().contains(Soap12.getInstance().getUltimateReceiverRole()));
roles.add(Soap12.getInstance().getNoneRole());
try {
binding.setRoles(roles);
fail("did not throw exception");
} catch (WebServiceException e) {
// that's expected with none role
}
}
Aggregations