use of javax.xml.ws.soap.SOAPBinding in project cxf by apache.
the class JMSTestMtom method testMTOM.
@Test
public void testMTOM() throws Exception {
QName serviceName = new QName("http://cxf.apache.org/jms_mtom", "JMSMTOMService");
QName portName = new QName("http://cxf.apache.org/jms_mtom", "MTOMPort");
URL wsdl = getWSDLURL("/wsdl/jms_test_mtom.wsdl");
JMSMTOMService service = new JMSMTOMService(wsdl, serviceName);
JMSMTOMPortType mtom = service.getPort(portName, JMSMTOMPortType.class);
Binding binding = ((BindingProvider) mtom).getBinding();
((SOAPBinding) binding).setMTOMEnabled(true);
Holder<String> name = new Holder<>("Sam");
URL fileURL = this.getClass().getResource("/org/apache/cxf/systest/jms/JMSClientServerTest.class");
Holder<DataHandler> handler1 = new Holder<>();
handler1.value = new DataHandler(fileURL);
int size = handler1.value.getInputStream().available();
mtom.testDataHandler(name, handler1);
byte[] bytes = IOUtils.readBytesFromStream(handler1.value.getInputStream());
Assert.assertEquals("The response file is not same with the sent file.", size, bytes.length);
((Closeable) mtom).close();
}
use of javax.xml.ws.soap.SOAPBinding in project cxf by apache.
the class ValidationWithAttachmentTest method initClient.
private static void initClient() {
JaxWsProxyFactoryBean clientFactory = new JaxWsProxyFactoryBean();
clientFactory.setServiceClass(AttachmentService.class);
clientFactory.setAddress(ADDRESS);
client = (AttachmentService) clientFactory.create();
// enable MTOM in client
BindingProvider bp = (BindingProvider) client;
SOAPBinding binding = (SOAPBinding) bp.getBinding();
binding.setMTOMEnabled(true);
}
use of javax.xml.ws.soap.SOAPBinding in project Payara by payara.
the class PortCreationCallbackImpl method postCreateProxy.
public void postCreateProxy(WSBindingProvider bp, Class<?> serviceEndpointInterface) {
ServiceRefPortInfo portInfo = ref.getPortInfoBySEI(serviceEndpointInterface.getName());
if (portInfo != null) {
// Set MTOM for this port
boolean mtomEnabled = false;
if (portInfo.getMtomEnabled() != null && Boolean.valueOf(portInfo.getMtomEnabled())) {
mtomEnabled = true;
}
if (mtomEnabled) {
Binding bType = bp.getBinding();
// enable mtom valid only for SOAPBindings
if (SOAPBinding.class.isAssignableFrom(bType.getClass())) {
((SOAPBinding) bType).setMTOMEnabled(true);
} else {
logger.log(Level.SEVERE, LogUtils.INVALID_MTOM, portInfo.getName());
}
}
// Set stub properties
Set properties = portInfo.getStubProperties();
for (Iterator iter = properties.iterator(); iter.hasNext(); ) {
NameValuePairDescriptor next = (NameValuePairDescriptor) iter.next();
bp.getRequestContext().put(next.getName(), next.getValue());
}
}
}
use of javax.xml.ws.soap.SOAPBinding in project pentaho-kettle by pentaho.
the class WebServiceManager method createService.
@Override
@SuppressWarnings("unchecked")
public <T> T createService(final String username, final String password, final Class<T> clazz) throws MalformedURLException {
final Future<Object> resultFuture;
synchronized (serviceCache) {
// if this is true, a coder did not make sure that clearServices was called on disconnect
if (lastUsername != null && !lastUsername.equals(username)) {
throw new IllegalStateException();
}
final WebServiceSpecification webServiceSpecification = serviceNameMap.get(clazz);
final String serviceName = webServiceSpecification.getServiceName();
if (serviceName == null) {
throw new IllegalStateException();
}
if (webServiceSpecification.getServiceType().equals(ServiceType.JAX_WS)) {
// build the url handling whether or not baseUrl ends with a slash
// String baseUrl = repositoryMeta.getRepositoryLocation().getUrl();
final URL url = // $NON-NLS-1$ //$NON-NLS-2$
new URL(baseUrl + (baseUrl.endsWith("/") ? "" : "/") + "webservices/" + serviceName + "?wsdl");
String key = url.toString() + '_' + serviceName + '_' + clazz.getName();
if (!serviceCache.containsKey(key)) {
resultFuture = executor.submit(new Callable<Object>() {
@Override
public Object call() throws Exception {
Service service = Service.create(url, new QName(NAMESPACE_URI, serviceName));
T port = service.getPort(clazz);
// add TRUST_USER if necessary
if (StringUtils.isNotBlank(System.getProperty("pentaho.repository.client.attemptTrust"))) {
((BindingProvider) port).getRequestContext().put(MessageContext.HTTP_REQUEST_HEADERS, Collections.singletonMap(TRUST_USER, Collections.singletonList(username)));
} else {
// http basic authentication
((BindingProvider) port).getRequestContext().put(BindingProvider.USERNAME_PROPERTY, username);
((BindingProvider) port).getRequestContext().put(BindingProvider.PASSWORD_PROPERTY, password);
}
// accept cookies to maintain session on server
((BindingProvider) port).getRequestContext().put(BindingProvider.SESSION_MAINTAIN_PROPERTY, true);
// support streaming binary data
// TODO mlowery this is not portable between JAX-WS implementations (uses com.sun)
((BindingProvider) port).getRequestContext().put(JAXWSProperties.HTTP_CLIENT_STREAMING_CHUNK_SIZE, 8192);
SOAPBinding binding = (SOAPBinding) ((BindingProvider) port).getBinding();
binding.setMTOMEnabled(true);
return port;
}
});
serviceCache.put(key, resultFuture);
} else {
resultFuture = serviceCache.get(key);
}
} else {
if (webServiceSpecification.getServiceType().equals(ServiceType.JAX_RS)) {
String key = baseUrl.toString() + '_' + serviceName + '_' + clazz.getName();
if (!serviceCache.containsKey(key)) {
resultFuture = executor.submit(new Callable<Object>() {
@Override
public Object call() throws Exception {
ClientConfig clientConfig = new DefaultClientConfig();
Client client = Client.create(clientConfig);
client.addFilter(new HTTPBasicAuthFilter(username, password));
Class<?>[] parameterTypes = new Class<?>[] { Client.class, URI.class };
String factoryClassName = webServiceSpecification.getServiceClass().getName();
factoryClassName = factoryClassName.substring(0, factoryClassName.lastIndexOf("$"));
Class<?> factoryClass = Class.forName(factoryClassName);
Method method = factoryClass.getDeclaredMethod(webServiceSpecification.getServiceName(), parameterTypes);
T port = (T) method.invoke(null, new Object[] { client, new URI(baseUrl + "/plugin") });
return port;
}
});
serviceCache.put(key, resultFuture);
} else {
resultFuture = serviceCache.get(key);
}
} else {
resultFuture = null;
}
}
try {
if (clazz.isInterface()) {
return UnifiedRepositoryInvocationHandler.forObject((T) resultFuture.get(), clazz);
} else {
return (T) resultFuture.get();
}
} catch (InterruptedException e) {
throw new RuntimeException(e);
} catch (ExecutionException e) {
Throwable cause = e.getCause();
if (cause != null) {
if (cause instanceof RuntimeException) {
throw (RuntimeException) cause;
} else if (cause instanceof MalformedURLException) {
throw (MalformedURLException) cause;
}
}
throw new RuntimeException(e);
}
}
}
use of javax.xml.ws.soap.SOAPBinding in project iaf by ibissource.
the class WebServiceListener method open.
@Override
public void open() throws ListenerException {
if (StringUtils.isNotEmpty(getAddress())) {
log.debug("registering listener [" + getName() + "] with JAX-WS CXF Dispatcher on SpringBus [" + cxfBus.getId() + "]");
endpoint = new EndpointImpl(cxfBus, new MessageProvider(this, getMultipartXmlSessionKey()));
// TODO: prepend with `local://` when used without application server
endpoint.publish("/" + getAddress());
SOAPBinding binding = (SOAPBinding) endpoint.getBinding();
binding.setMTOMEnabled(isMtomEnabled());
if (endpoint.isPublished()) {
log.debug("published listener [" + getName() + "] on CXF endpoint [" + getAddress() + "]");
} else {
log.error("unable to publish listener [" + getName() + "] on CXF endpoint [" + getAddress() + "]");
}
}
// Can bind on multiple endpoints
if (StringUtils.isNotEmpty(getServiceNamespaceURI())) {
log.debug("registering listener [" + getName() + "] with ServiceDispatcher by serviceNamespaceURI [" + getServiceNamespaceURI() + "]");
ServiceDispatcher.getInstance().registerServiceClient(getServiceNamespaceURI(), this);
} else {
log.debug("registering listener [" + getName() + "] with ServiceDispatcher");
// Backwards compatibility
ServiceDispatcher.getInstance().registerServiceClient(getName(), this);
}
super.open();
}
Aggregations