Java Code Examples for javax.xml.ws.BindingProvider#getBinding()

The following examples show how to use javax.xml.ws.BindingProvider#getBinding() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ClientMtomXopWithJMSTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
private static <T> T createPort(QName serviceName, QName portName, Class<T> serviceEndpointInterface,
                                boolean enableMTOM) throws Exception {
    JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
    factory.setBus(bus);
    factory.setServiceName(serviceName);
    factory.setServiceClass(serviceEndpointInterface);
    factory.setWsdlURL(ClientMtomXopTest.class.getResource("/wsdl/mtom_xop.wsdl").toExternalForm());
    factory.setFeatures(Collections.singletonList(cff));
    factory.getInInterceptors().add(new TestMultipartMessageInterceptor());
    factory.getOutInterceptors().add(new TestAttachmentOutInterceptor());
    @SuppressWarnings("unchecked")
    T proxy = (T)factory.create();
    BindingProvider bp = (BindingProvider)proxy;
    SOAPBinding binding = (SOAPBinding)bp.getBinding();
    binding.setMTOMEnabled(true);
    return proxy;
}
 
Example 2
Source File: AbstractUDDIClientTestCase.java    From juddi with Apache License 2.0 5 votes vote down vote up
protected void registerService(BindingProvider bindingProvider)
{
    Binding binding = bindingProvider.getBinding();
    List<Handler> handlerChain = binding.getHandlerChain();

    handlerChain.add(new LoggingHandler());

    // set the handler chain again for the changes to take effect
    binding.setHandlerChain(handlerChain);
}
 
Example 3
Source File: JUDDIServiceProvider.java    From juddi with Apache License 2.0 5 votes vote down vote up
private void registerService(BindingProvider bindingProvider) {
	Binding binding = bindingProvider.getBinding();
	List<Handler> handlerChain = binding.getHandlerChain();

	handlerChain.add(new LoggingHandler());

	// set the handler chain again for the changes to take effect
	binding.setHandlerChain(handlerChain);
}
 
Example 4
Source File: ValidationWithAttachmentTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
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);
}
 
Example 5
Source File: HandlerInvocationTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
public void testAddingUnusedHandlersThroughConfigFile() {
    HandlerTestServiceWithAnnotation service1 = new HandlerTestServiceWithAnnotation(wsdl, serviceName);
    HandlerTest handlerTest1 = service1.getPort(portName, HandlerTest.class);

    BindingProvider bp1 = (BindingProvider)handlerTest1;
    Binding binding1 = bp1.getBinding();
    @SuppressWarnings("rawtypes")
    List<Handler> port1HandlerChain = binding1.getHandlerChain();
    assertEquals(1, port1HandlerChain.size());
}
 
Example 6
Source File: SOAPBindingTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@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
    }
}
 
Example 7
Source File: JaxWsProviderWrapper.java    From tomee with Apache License 2.0 5 votes vote down vote up
private void setProperties(final BindingProvider proxy, final QName qname) {
    for (final PortRefMetaData portRef : portRefs) {
        Class<?> intf = null;
        if (portRef.getServiceEndpointInterface() != null) {
            try {
                intf = proxy.getClass().getClassLoader().loadClass(portRef.getServiceEndpointInterface());
            } catch (ClassNotFoundException e) {
                logger.log(Level.INFO, "Not loading: " + portRef.getServiceEndpointInterface());
            }
        }
        if ((qname != null && qname.equals(portRef.getQName())) || (intf != null && intf.isInstance(proxy))) {
            // set address
            if (!portRef.getAddresses().isEmpty()) {
                proxy.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, portRef.getAddresses().get(0));
            }

            // set mtom
            final boolean enableMTOM = portRef.isEnableMtom();
            if (enableMTOM && proxy.getBinding() instanceof SOAPBinding) {
                ((SOAPBinding) proxy.getBinding()).setMTOMEnabled(enableMTOM);
            }

            // set properties
            for (final Map.Entry<Object, Object> entry : portRef.getProperties().entrySet()) {
                final String name = (String) entry.getKey();
                final String value = (String) entry.getValue();
                proxy.getRequestContext().put(name, value);
            }

            return;
        }
    }
}
 
Example 8
Source File: ProviderWrapper.java    From tomee with Apache License 2.0 5 votes vote down vote up
private void setProperties(final BindingProvider proxy, final QName qname) {
    for (final PortRefData portRef : portRefs) {
        Class intf = null;
        if (portRef.getServiceEndpointInterface() != null) {
            try {
                intf = proxy.getClass().getClassLoader().loadClass(portRef.getServiceEndpointInterface());
            } catch (final Exception e) {
                // no-op
            }
        }
        if (qname != null && qname.equals(portRef.getQName()) || intf != null && intf.isInstance(proxy)) {
            // set address
            if (!portRef.getAddresses().isEmpty()) {
                proxy.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, portRef.getAddresses().get(0));
            }

            // set mtom
            final boolean enableMTOM = portRef.isEnableMtom();
            if (enableMTOM && proxy.getBinding() instanceof SOAPBinding) {
                ((SOAPBinding) proxy.getBinding()).setMTOMEnabled(enableMTOM);
            }

            // set properties
            for (final Map.Entry<Object, Object> entry : portRef.getProperties().entrySet()) {
                final String name = (String) entry.getKey();
                final String value = (String) entry.getValue();
                proxy.getRequestContext().put(name, value);
            }

            return;
        }
    }
}
 
Example 9
Source File: SOAPBindingTest.java    From cxf with Apache License 2.0 4 votes vote down vote up
@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());
}
 
Example 10
Source File: JAXWSEnvironment.java    From dropwizard-jaxws with Apache License 2.0 4 votes vote down vote up
/**
 * JAX-WS client factory
 * @param clientBuilder ClientBuilder.
 * @param <T> Service interface type.
 * @return JAX-WS client proxy.
 */
public <T> T getClient(ClientBuilder<T> clientBuilder) {

    JaxWsProxyFactoryBean proxyFactory = new JaxWsProxyFactoryBean();
    proxyFactory.setServiceClass(clientBuilder.getServiceClass());
    proxyFactory.setAddress(clientBuilder.getAddress());

    // JAX-WS handlers
    if (clientBuilder.getHandlers() != null) {
        for (Handler h : clientBuilder.getHandlers()) {
            proxyFactory.getHandlers().add(h);
        }
    }

    // ClientProxyFactoryBean bindingId
    if (clientBuilder.getBindingId() != null) {
        proxyFactory.setBindingId(clientBuilder.getBindingId());
    }

    // CXF interceptors
    if (clientBuilder.getCxfInInterceptors() != null) {
        proxyFactory.getInInterceptors().addAll(clientBuilder.getCxfInInterceptors());
    }
    if (clientBuilder.getCxfInFaultInterceptors() != null) {
        proxyFactory.getInFaultInterceptors().addAll(clientBuilder.getCxfInFaultInterceptors());
    }
    if (clientBuilder.getCxfOutInterceptors() != null) {
        proxyFactory.getOutInterceptors().addAll(clientBuilder.getCxfOutInterceptors());
    }
    if (clientBuilder.getCxfOutFaultInterceptors() != null) {
        proxyFactory.getOutFaultInterceptors().addAll(clientBuilder.getCxfOutFaultInterceptors());
    }

    T proxy = clientBuilder.getServiceClass().cast(proxyFactory.create());

    // MTOM support
    if (clientBuilder.isMtomEnabled()) {
        BindingProvider bp = (BindingProvider)proxy;
        SOAPBinding binding = (SOAPBinding)bp.getBinding();
        binding.setMTOMEnabled(true);
    }

    HTTPConduit http = (HTTPConduit)ClientProxy.getClient(proxy).getConduit();
    HTTPClientPolicy client = http.getClient();
    client.setConnectionTimeout(clientBuilder.getConnectTimeout());
    client.setReceiveTimeout(clientBuilder.getReceiveTimeout());

    return proxy;
}
 
Example 11
Source File: JAXWSEnvironmentTest.java    From dropwizard-jaxws with Apache License 2.0 4 votes vote down vote up
@Test
public void getClient() {

    String address = "http://address";
    Handler handler = mock(Handler.class);

    // simple
    DummyInterface clientProxy = jaxwsEnvironment.getClient(
            new ClientBuilder<>(DummyInterface.class, address)
    );
    assertThat(clientProxy, is(instanceOf(Proxy.class)));

    Client c = ClientProxy.getClient(clientProxy);
    assertThat(c.getEndpoint().getEndpointInfo().getAddress(), equalTo(address));
    assertThat(c.getEndpoint().getService().get("endpoint.class").equals(DummyInterface.class), equalTo(true));
    assertThat(((BindingProvider)clientProxy).getBinding() .getHandlerChain().size(), equalTo(0));

    HTTPClientPolicy httpclient = ((HTTPConduit)c.getConduit()).getClient();
    assertThat(httpclient.getConnectionTimeout(), equalTo(500L));
    assertThat(httpclient.getReceiveTimeout(), equalTo(2000L));

    // with timeouts, handlers, interceptors, properties and MTOM

    TestInterceptor inInterceptor = new TestInterceptor(Phase.UNMARSHAL);
    TestInterceptor inInterceptor2 = new TestInterceptor(Phase.PRE_INVOKE);
    TestInterceptor outInterceptor = new TestInterceptor(Phase.MARSHAL);

    clientProxy = jaxwsEnvironment.getClient(
            new ClientBuilder<>(DummyInterface.class, address)
                    .connectTimeout(123)
                    .receiveTimeout(456)
                    .handlers(handler)
                    .bindingId(SoapBindingFactory.SOAP_12_BINDING)
                    .cxfInInterceptors(inInterceptor, inInterceptor2)
                    .cxfOutInterceptors(outInterceptor)
                    .enableMtom());
    c = ClientProxy.getClient(clientProxy);
    assertThat(((BindingProvider) clientProxy).getBinding().getBindingID(), equalTo("http://www.w3.org/2003/05/soap/bindings/HTTP/"));
    assertThat(c.getEndpoint().getEndpointInfo().getAddress(), equalTo(address));
    assertThat(c.getEndpoint().getService().get("endpoint.class").equals(DummyInterface.class), equalTo(true));

    httpclient = ((HTTPConduit)c.getConduit()).getClient();
    assertThat(httpclient.getConnectionTimeout(), equalTo(123L));
    assertThat(httpclient.getReceiveTimeout(), equalTo(456L));

    assertThat(((BindingProvider)clientProxy).getBinding().getHandlerChain(), contains(handler));

    BindingProvider bp = (BindingProvider)clientProxy;
    SOAPBinding binding = (SOAPBinding)bp.getBinding();
    assertThat(binding.isMTOMEnabled(), equalTo(true));
}