Search in sources :

Example 36 with SOAPBinding

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();
}
Also used : Binding(javax.xml.ws.Binding) SOAPBinding(javax.xml.ws.soap.SOAPBinding) QName(javax.xml.namespace.QName) Holder(javax.xml.ws.Holder) Closeable(java.io.Closeable) SOAPBinding(javax.xml.ws.soap.SOAPBinding) JMSMTOMPortType(org.apache.cxf.jms_mtom.JMSMTOMPortType) BindingProvider(javax.xml.ws.BindingProvider) DataHandler(javax.activation.DataHandler) URL(java.net.URL) Endpoint(javax.xml.ws.Endpoint) JMSMTOMService(org.apache.cxf.jms_mtom.JMSMTOMService) Test(org.junit.Test)

Example 37 with SOAPBinding

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);
}
Also used : JaxWsProxyFactoryBean(org.apache.cxf.jaxws.JaxWsProxyFactoryBean) SOAPBinding(javax.xml.ws.soap.SOAPBinding) BindingProvider(javax.xml.ws.BindingProvider)

Example 38 with SOAPBinding

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());
        }
    }
}
Also used : Binding(javax.xml.ws.Binding) SOAPBinding(javax.xml.ws.soap.SOAPBinding) Set(java.util.Set) NameValuePairDescriptor(com.sun.enterprise.deployment.NameValuePairDescriptor) Iterator(java.util.Iterator) SOAPBinding(javax.xml.ws.soap.SOAPBinding) ServiceRefPortInfo(com.sun.enterprise.deployment.ServiceRefPortInfo)

Example 39 with SOAPBinding

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);
        }
    }
}
Also used : MalformedURLException(java.net.MalformedURLException) URI(java.net.URI) URL(java.net.URL) Callable(java.util.concurrent.Callable) ClientConfig(com.sun.jersey.api.client.config.ClientConfig) DefaultClientConfig(com.sun.jersey.api.client.config.DefaultClientConfig) Client(com.sun.jersey.api.client.Client) ExecutionException(java.util.concurrent.ExecutionException) DefaultClientConfig(com.sun.jersey.api.client.config.DefaultClientConfig) QName(javax.xml.namespace.QName) IUserRoleListWebService(org.pentaho.platform.security.userrole.ws.IUserRoleListWebService) Service(javax.xml.ws.Service) IUnifiedRepositoryJaxwsWebService(org.pentaho.platform.repository2.unified.webservices.jaxws.IUnifiedRepositoryJaxwsWebService) ExecutorService(java.util.concurrent.ExecutorService) IRepositorySyncWebService(com.pentaho.pdi.ws.IRepositorySyncWebService) IAuthorizationPolicyWebService(org.pentaho.platform.security.policy.rolebased.ws.IAuthorizationPolicyWebService) IRoleAuthorizationPolicyRoleBindingDaoWebService(org.pentaho.platform.security.policy.rolebased.ws.IRoleAuthorizationPolicyRoleBindingDaoWebService) IUserRoleWebService(org.pentaho.platform.security.userroledao.ws.IUserRoleWebService) SOAPBinding(javax.xml.ws.soap.SOAPBinding) Method(java.lang.reflect.Method) HTTPBasicAuthFilter(com.sun.jersey.api.client.filter.HTTPBasicAuthFilter)

Example 40 with SOAPBinding

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();
}
Also used : MessageProvider(nl.nn.adapterframework.http.cxf.MessageProvider) EndpointImpl(org.apache.cxf.jaxws.EndpointImpl) SOAPBinding(javax.xml.ws.soap.SOAPBinding)

Aggregations

SOAPBinding (javax.xml.ws.soap.SOAPBinding)51 Test (org.junit.Test)20 URL (java.net.URL)19 BindingProvider (javax.xml.ws.BindingProvider)19 QName (javax.xml.namespace.QName)18 Service (javax.xml.ws.Service)14 DataHandler (javax.activation.DataHandler)13 WebServiceException (javax.xml.ws.WebServiceException)7 RunAsClient (org.jboss.arquillian.container.test.api.RunAsClient)7 JBossWSTest (org.jboss.wsf.test.JBossWSTest)7 ArrayList (java.util.ArrayList)6 Holder (javax.xml.ws.Holder)6 Image (java.awt.Image)5 IOException (java.io.IOException)5 Binding (javax.xml.ws.Binding)5 File (java.io.File)4 Before (org.junit.Before)4 FileDataSource (javax.activation.FileDataSource)3 Handler (javax.xml.ws.handler.Handler)3 MTOMFeature (javax.xml.ws.soap.MTOMFeature)3