javax.xml.ws.Binding Java Examples

The following examples show how to use javax.xml.ws.Binding. 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: JMSTestMtom.java    From cxf with Apache License 2.0 6 votes vote down vote up
@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();
}
 
Example #2
Source File: JaxWsServiceFactoryBeanTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
public void testMtomFeature() throws Exception {
    JaxWsServiceFactoryBean bean = new JaxWsServiceFactoryBean();
    bean.setBus(getBus());
    bean.setServiceClass(GreeterImpl.class);
    bean.setWsdlURL(getClass().getResource("/wsdl/hello_world.wsdl"));
    bean.setWsFeatures(Arrays.asList(new WebServiceFeature[]{new MTOMFeature()}));
    Service service = bean.create();
    Endpoint endpoint = service.getEndpoints().values().iterator().next();
    assertTrue(endpoint instanceof JaxWsEndpointImpl);
    Binding binding = ((JaxWsEndpointImpl)endpoint).getJaxwsBinding();
    assertTrue(binding instanceof SOAPBinding);
    assertTrue(((SOAPBinding)binding).isMTOMEnabled());
}
 
Example #3
Source File: LogicalHandlerInterceptorTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() {
    control = createNiceControl();
    binding = control.createMock(Binding.class);
    invoker = control.createMock(HandlerChainInvoker.class);
    message = control.createMock(Message.class);
    exchange = control.createMock(Exchange.class);
}
 
Example #4
Source File: JMSTestMtom.java    From cxf with Apache License 2.0 5 votes vote down vote up
@BeforeClass
public static void startServers() throws Exception {
    broker = new EmbeddedJMSBrokerLauncher();
    broker.startInProcess();
    bus = BusFactory.getDefaultBus();
    broker.updateWsdl(bus, "testutils/jms_test_mtom.wsdl");
    Object mtom = new JMSMTOMImpl();
    EndpointImpl ep = (EndpointImpl)Endpoint
        .publish("jms:jndi:dynamicQueues/test.cxf.jmstransport.queue&amp;receiveTimeout=10000", mtom);
    Binding binding = ep.getBinding();
    ((SOAPBinding)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: WSSecurityClientTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
public void testTimestampSignEncrypt() throws Exception {
    Bus b = new SpringBusFactory()
        .createBus("org/apache/cxf/systest/ws/security/client.xml");
    BusFactory.setDefaultBus(b);
    final javax.xml.ws.Service svc = javax.xml.ws.Service.create(
        WSDL_LOC,
        GREETER_SERVICE_QNAME
    );
    final Greeter greeter = svc.getPort(
        TIMESTAMP_SIGN_ENCRYPT_PORT_QNAME,
        Greeter.class
    );
    updateAddressPort(greeter, test.getPort());

    // Add a No-Op JAX-WS SoapHandler to the dispatch chain to
    // verify that the SoapHandlerInterceptor can peacefully co-exist
    // with the explicitly configured SAAJOutInterceptor
    //
    @SuppressWarnings("rawtypes")
    List<Handler> handlerChain = new ArrayList<>();
    Binding binding = ((BindingProvider)greeter).getBinding();
    TestOutHandler handler = new TestOutHandler();
    handlerChain.add(handler);
    binding.setHandlerChain(handlerChain);

    greeter.sayHi();

    assertTrue("expected Handler.handleMessage() to be called",
               handler.handleMessageCalledOutbound);
    assertFalse("expected Handler.handleFault() not to be called",
                handler.handleFaultCalledOutbound);
    ((java.io.Closeable)greeter).close();
    b.shutdown(true);
    BusFactory.setDefaultBus(getStaticBus());
}
 
Example #7
Source File: Server.java    From cxf with Apache License 2.0 5 votes vote down vote up
protected Server() throws Exception {
    System.out.println("Starting Server");
    Object implementor = new TestMtomPortTypeImpl();
    String address = "http://localhost:9000/mime-test";
    Endpoint ep = Endpoint.publish(address, implementor);
    Binding binding = ep.getBinding();
    ((SOAPBinding)binding).setMTOMEnabled(true);
}
 
Example #8
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 #9
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 #10
Source File: AbstractProtocolHandlerInterceptorTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() {
    control = createNiceControl();
    invoker = control.createMock(HandlerChainInvoker.class);
    message = control.createMock(IIOPMessage.class);
    exchange = control.createMock(Exchange.class);
    binding = control.createMock(Binding.class);

    @SuppressWarnings("rawtypes")
    List<Handler> list = new ArrayList<>();
    list.add(null);
    expect(binding.getHandlerChain()).andReturn(list).anyTimes();
}
 
Example #11
Source File: EndpointImplTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
public void testEndpointPublishAfterGetBinding() throws Exception {
    Endpoint endpoint = Endpoint.create(new Hello());

    Binding binding = endpoint.getBinding();
    assertNotNull(binding);

    // CXF-6257
    endpoint.publish("http://localhost:8080/test");
    endpoint.stop();
}
 
Example #12
Source File: CampaignServiceInterfaceImpl.java    From googleads-java-lib with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("rawtypes")
public CampaignServiceInterfaceImpl() {
  binding = Mockito.mock(Binding.class);
  RequestInfoXPathSet requestInfoXPathSet = Mockito.mock(RequestInfoXPathSet.class);
  ResponseInfoXPathSet responseInfoXPathSet = Mockito.mock(ResponseInfoXPathSet.class);
  List<Handler> handlerList =
      Lists.<Handler>newArrayList(
          new JaxWsSoapContextHandler(requestInfoXPathSet, responseInfoXPathSet));
  when(binding.getHandlerChain()).thenReturn(handlerList);
}
 
Example #13
Source File: JaxWSHookIT.java    From uavstack with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("rawtypes")
public Dispatch createDispatch(Dispatch d, Service s, Object[] args) {

    Binding binding = ((BindingProvider) d).getBinding();
    List<Handler> handlerChain = binding.getHandlerChain();
    handlerChain.add(this.handler);
    binding.setHandlerChain(handlerChain);

    final String wsdlLocation = getServiceURL(s);

    Dispatch tProxy = JDKProxyInvokeUtil.newProxyInstance(this.getClass().getClassLoader(),
            new Class[] { Dispatch.class },
            new JDKProxyInvokeHandler<Dispatch>(d, new DispatchProcessor(wsdlLocation.toString(), this.handler)));
    return tProxy;
}
 
Example #14
Source File: JaxWSHookIT.java    From uavstack with Apache License 2.0 5 votes vote down vote up
/**
 * this is for Client Stub Programming
 * 
 * @param t
 * @param s
 * @param args
 * @return
 */
@SuppressWarnings({ "unchecked", "rawtypes" })
public <T> T getPort(T t, Service s, Object[] args) {
    
    if (JDKProxyInvokeUtil.isJDKProxy(t)) {
        return t;
    }

    Class<T> clz = null;
    if (Class.class.isAssignableFrom(args[0].getClass())) {
        clz = (Class<T>) args[0];
    }
    else if (Class.class.isAssignableFrom(args[1].getClass())) {
        clz = (Class<T>) args[1];
    }

    if (clz == null) {
        return t;
    }

    Binding binding = ((BindingProvider) t).getBinding();
    List<Handler> handlerChain = binding.getHandlerChain();
    handlerChain.add(this.handler);
    binding.setHandlerChain(handlerChain);

    final String wsdlLocation = getServiceURL(s);

    T tProxy = JDKProxyInvokeUtil.newProxyInstance(clz.getClassLoader(), new Class[] { clz },
            new JDKProxyInvokeHandler<T>(t, new ClientStubProcessor(wsdlLocation.toString(), this.handler)));
    return tProxy;
}
 
Example #15
Source File: JaxWSCxfHookIT.java    From uavstack with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings({ "unchecked", "rawtypes" })
public <T> T create(T t,ClientFactoryBean clientFactoryBean) { 
    
    Binding binding = ((BindingProvider) t).getBinding();
    List<Handler> handlerChain = binding.getHandlerChain();
    handlerChain.add(this.handler);
    binding.setHandlerChain(handlerChain);
    
    String wsdlLocation = clientFactoryBean.getAddress();
    
    T tProxy = JDKProxyInvokeUtil.newProxyInstance(clientFactoryBean.getServiceClass().getClassLoader(),
            new Class[] { clientFactoryBean.getServiceClass() },
            new JDKProxyInvokeHandler<T>(t, new ClientStubProcessor(wsdlLocation.toString(), this.handler)));
    return tProxy;
}
 
Example #16
Source File: SOAPHandlerFaultInInterceptor.java    From cxf with Apache License 2.0 4 votes vote down vote up
public SOAPHandlerFaultInInterceptor(Binding binding) {
    super(binding, Phase.PRE_PROTOCOL_FRONTEND);
}
 
Example #17
Source File: LogicalHandlerOutInterceptor.java    From cxf with Apache License 2.0 4 votes vote down vote up
public LogicalHandlerOutInterceptor(Binding binding) {
    super(binding, Phase.PRE_MARSHAL);
    ending = new LogicalHandlerOutEndingInterceptor(binding);
}
 
Example #18
Source File: SOAPHandlerInterceptor.java    From cxf with Apache License 2.0 4 votes vote down vote up
public SOAPHandlerInterceptor(Binding binding) {
    super(binding, Phase.PRE_PROTOCOL_FRONTEND);
}
 
Example #19
Source File: SOAPHandlerFaultOutInterceptor.java    From cxf with Apache License 2.0 4 votes vote down vote up
public SOAPHandlerFaultOutInterceptor(Binding binding) {
    super(binding, Phase.PRE_PROTOCOL_FRONTEND);
}
 
Example #20
Source File: LogicalHandlerOutInterceptor.java    From cxf with Apache License 2.0 4 votes vote down vote up
LogicalHandlerOutEndingInterceptor(Binding binding) {
    super(binding, Phase.POST_MARSHAL);
}
 
Example #21
Source File: AbstractProtocolHandlerInterceptor.java    From cxf with Apache License 2.0 4 votes vote down vote up
protected AbstractProtocolHandlerInterceptor(Binding binding) {
    super(binding, Phase.USER_PROTOCOL);
}
 
Example #22
Source File: JaxWsEndpointImpl.java    From cxf with Apache License 2.0 4 votes vote down vote up
public Binding getJaxwsBinding() {
    return jaxwsBinding;
}
 
Example #23
Source File: DispatchImpl.java    From cxf with Apache License 2.0 4 votes vote down vote up
public Binding getBinding() {
    return binding;
}
 
Example #24
Source File: AbstractProtocolHandlerInterceptorTest.java    From cxf with Apache License 2.0 4 votes vote down vote up
IIOPHandlerInterceptor(Binding binding) {
    super(binding);
}
 
Example #25
Source File: CxfEndpoint.java    From tomee with Apache License 2.0 4 votes vote down vote up
public Binding getBinding() {
    return ((JaxWsEndpointImpl) getEndpoint()).getJaxwsBinding();
}
 
Example #26
Source File: EjbInterceptor.java    From tomee with Apache License 2.0 4 votes vote down vote up
@AroundInvoke
public Object intercept(InvocationContext context) throws Exception {
    Endpoint endpoint = this.exchange.get(Endpoint.class);
    Service service = endpoint.getService();
    Binding binding = ((JaxWsEndpointImpl) endpoint).getJaxwsBinding();

    this.exchange.put(InvocationContext.class, context);

    if (binding.getHandlerChain() == null || binding.getHandlerChain().isEmpty()) {
        // no handlers so let's just directly invoke the bean
        log.debug("No handlers found.");

        EjbMethodInvoker invoker = (EjbMethodInvoker) service.getInvoker();
        return invoker.directEjbInvoke(this.exchange, this.method, this.params);

    } else {
        // have handlers so have to run handlers now and redo data binding
        // as handlers can change the soap message
        log.debug("Handlers found.");

        Message inMessage = exchange.getInMessage();
        PhaseInterceptorChain chain = new PhaseInterceptorChain(bus.getExtension(PhaseManager.class).getInPhases());

        chain.setFaultObserver(endpoint.getOutFaultObserver());

        /*
         * Since we have to re-do data binding and the XMLStreamReader
         * contents are already consumed by prior data binding step
         * we have to reinitialize the XMLStreamReader from the SOAPMessage
         * created by SAAJInInterceptor.
         */
        if (inMessage instanceof SoapMessage) {
            try {
                reserialize((SoapMessage) inMessage);
            } catch (Exception e) {
                throw new ServerRuntimeException("Failed to reserialize soap message", e);
            }
        } else {
            // TODO: how to handle XML/HTTP binding?
        }

        this.exchange.setOutMessage(null);

        // install default interceptors
        chain.add(new ServiceInvokerInterceptor());
        //chain.add(new OutgoingChainInterceptor()); // it is already in the enclosing chain, if we add it there we are in the tx so we write the message in the tx!

        // See http://cwiki.apache.org/CXF20DOC/interceptors.html
        // install Holder and Wrapper interceptors
        chain.add(new WrapperClassInInterceptor());
        chain.add(new HolderInInterceptor());

        // install interceptors for handler processing
        chain.add(new MustUnderstandInterceptor());
        chain.add(new LogicalHandlerInInterceptor(binding));
        chain.add(new SOAPHandlerInterceptor(binding));

        // install data binding interceptors - todo: check we need it
        copyDataBindingInterceptors(chain, inMessage.getInterceptorChain());

        InterceptorChain oldChain = inMessage.getInterceptorChain();
        inMessage.setInterceptorChain(chain);
        try {
            chain.doIntercept(inMessage);
        } finally {
            inMessage.setInterceptorChain(oldChain);
        }

        // TODO: the result should be deserialized from SOAPMessage
        Object result = getResult();

        return result;
    }
}
 
Example #27
Source File: CampaignServiceInterfaceImpl.java    From googleads-java-lib with Apache License 2.0 4 votes vote down vote up
/**
 * @see javax.xml.ws.BindingProvider#getBinding()
 */
@Override
public Binding getBinding() {
  return binding;
}
 
Example #28
Source File: LogicalHandlerInInterceptor.java    From cxf with Apache License 2.0 4 votes vote down vote up
public LogicalHandlerInInterceptor(Binding binding) {
    super(binding, Phase.PRE_PROTOCOL_FRONTEND);
    addAfter(SOAPHandlerInterceptor.class.getName());
}
 
Example #29
Source File: LogicalHandlerFaultInInterceptor.java    From cxf with Apache License 2.0 4 votes vote down vote up
public LogicalHandlerFaultInInterceptor(Binding binding) {
    super(binding, Phase.PRE_PROTOCOL_FRONTEND);
    addAfter(SOAPHandlerFaultInInterceptor.class.getName());
}
 
Example #30
Source File: LogicalHandlerFaultOutInterceptor.java    From cxf with Apache License 2.0 4 votes vote down vote up
LogicalHandlerFaultOutEndingInterceptor(Binding binding) {
    super(binding, Phase.POST_MARSHAL);
}