Search in sources :

Example 36 with Handler

use of javax.xml.ws.handler.Handler in project cxf by apache.

the class SOAPHandlerInterceptorTest method testGetUnderstoodHeadersReturnsNull.

@Test
public void testGetUnderstoodHeadersReturnsNull() {
    @SuppressWarnings("rawtypes") List<Handler> list = new ArrayList<>();
    list.add(new SOAPHandler<SOAPMessageContext>() {

        public boolean handleMessage(SOAPMessageContext smc) {
            return true;
        }

        public boolean handleFault(SOAPMessageContext smc) {
            return true;
        }

        public Set<QName> getHeaders() {
            return null;
        }

        public void close(MessageContext messageContext) {
        }
    });
    HandlerChainInvoker invoker = new HandlerChainInvoker(list);
    IMocksControl control = createNiceControl();
    Binding binding = control.createMock(Binding.class);
    expect(binding.getHandlerChain()).andReturn(list).anyTimes();
    SoapMessage message = control.createMock(SoapMessage.class);
    Exchange exchange = control.createMock(Exchange.class);
    expect(message.getExchange()).andReturn(exchange).anyTimes();
    expect(message.keySet()).andReturn(new HashSet<>());
    expect(exchange.get(HandlerChainInvoker.class)).andReturn(invoker);
    control.replay();
    SOAPHandlerInterceptor li = new SOAPHandlerInterceptor(binding);
    Set<QName> understood = li.getUnderstoodHeaders();
    assertNotNull(understood);
    assertTrue(understood.isEmpty());
}
Also used : Binding(javax.xml.ws.Binding) Set(java.util.Set) HashSet(java.util.HashSet) QName(javax.xml.namespace.QName) ArrayList(java.util.ArrayList) SOAPHandler(javax.xml.ws.handler.soap.SOAPHandler) Handler(javax.xml.ws.handler.Handler) SoapMessage(org.apache.cxf.binding.soap.SoapMessage) IMocksControl(org.easymock.IMocksControl) Exchange(org.apache.cxf.message.Exchange) HandlerChainInvoker(org.apache.cxf.jaxws.handler.HandlerChainInvoker) SOAPMessageContext(javax.xml.ws.handler.soap.SOAPMessageContext) MessageContext(javax.xml.ws.handler.MessageContext) SOAPMessageContext(javax.xml.ws.handler.soap.SOAPMessageContext) Test(org.junit.Test)

Example 37 with Handler

use of javax.xml.ws.handler.Handler in project cxf by apache.

the class Client method main.

public static void main(String[] args) throws Exception {
    if (args.length == 0) {
        System.err.println("please provide wsdl");
        System.exit(0);
    }
    File wsdl = new File(args[0]);
    AddNumbersService service = new AddNumbersService(wsdl.toURI().toURL(), serviceName);
    AddNumbers port = (AddNumbers) service.getPort(portName, AddNumbers.class);
    // Add client side handlers programmatically
    SmallNumberHandler sh = new SmallNumberHandler();
    List<Handler> newHandlerChain = new ArrayList<>();
    newHandlerChain.add(sh);
    ((BindingProvider) port).getBinding().setHandlerChain(newHandlerChain);
    try {
        int number1 = 10;
        int number2 = 20;
        System.out.printf("Invoking addNumbers(%d, %d)\n", number1, number2);
        int result = port.addNumbers(number1, number2);
        System.out.printf("The result of adding %d and %d is %d.\n\n", number1, number2, result);
        number1 = 3;
        number2 = 5;
        System.out.printf("Invoking addNumbers(%d, %d)\n", number1, number2);
        result = port.addNumbers(number1, number2);
        System.out.printf("The result of adding %d and %d is %d.\n\n", number1, number2, result);
        number1 = -10;
        System.out.printf("Invoking addNumbers(%d, %d)\n", number1, number2);
        result = port.addNumbers(number1, number2);
        System.out.printf("The result of adding %d and %d is %d.\n", number1, number2, result);
    } catch (AddNumbersFault ex) {
        System.out.printf("Caught AddNumbersFault: %s\n", ex.getFaultInfo().getMessage());
    }
    System.exit(0);
}
Also used : SmallNumberHandler(demo.handlers.common.SmallNumberHandler) AddNumbersService(org.apache.handlers.AddNumbersService) AddNumbers(org.apache.handlers.AddNumbers) ArrayList(java.util.ArrayList) Handler(javax.xml.ws.handler.Handler) SmallNumberHandler(demo.handlers.common.SmallNumberHandler) File(java.io.File) AddNumbersFault(org.apache.handlers.AddNumbersFault)

Example 38 with Handler

use of javax.xml.ws.handler.Handler in project cxf by apache.

the class HandlerChainBuilderTest method testBuilderCallsInitWithNoInitParamValues.

@Test
public void testBuilderCallsInitWithNoInitParamValues() {
    List<PortComponentHandlerType> hc = createHandlerChainType();
    hc.remove(3);
    hc.remove(2);
    hc.remove(1);
    PortComponentHandlerType h = hc.get(0);
    List<ParamValueType> params = h.getInitParam();
    ParamValueType p = new ParamValueType();
    CString pName = new CString();
    pName.setValue("foo");
    p.setParamName(pName);
    params.add(p);
    List<Handler> chain = builder.buildHandlerChainFromConfiguration(hc);
    assertEquals(1, chain.size());
    TestLogicalHandler tlh = (TestLogicalHandler) chain.get(0);
    assertTrue(tlh.initCalled);
    Map cfg = tlh.config;
    assertNotNull(tlh.config);
    assertEquals(1, cfg.keySet().size());
}
Also used : ParamValueType(org.apache.cxf.jaxws.handler.types.ParamValueType) LogicalHandler(javax.xml.ws.handler.LogicalHandler) Handler(javax.xml.ws.handler.Handler) PortComponentHandlerType(org.apache.cxf.jaxws.handler.types.PortComponentHandlerType) Map(java.util.Map) CString(org.apache.cxf.jaxws.handler.types.CString) Test(org.junit.Test)

Example 39 with Handler

use of javax.xml.ws.handler.Handler in project cxf by apache.

the class JavaxAnnotationHandlerChainBuilderTest method testFindHandlerChainAnnotationPerPortServiceBindingNegative.

@Test
public void testFindHandlerChainAnnotationPerPortServiceBindingNegative() {
    JavaxHandlerTestImpl handlerTestImpl = new JavaxHandlerTestImpl();
    AnnotationHandlerChainBuilder chainBuilder = new AnnotationHandlerChainBuilder();
    QName portQName = new QName("namespacedoesntsupportyet", "SoapPortUnknown");
    QName serviceQName = new QName("namespacedoesntsupportyet", "SoapServiceUnknown");
    String bindingID = "BindingUnknow";
    @SuppressWarnings("rawtypes") List<Handler> handlers = chainBuilder.buildHandlerChainFromClass(handlerTestImpl.getClass(), portQName, serviceQName, bindingID);
    assertNotNull(handlers);
    assertEquals(3, handlers.size());
}
Also used : QName(javax.xml.namespace.QName) Handler(javax.xml.ws.handler.Handler) LogicalHandler(javax.xml.ws.handler.LogicalHandler) Test(org.junit.Test)

Example 40 with Handler

use of javax.xml.ws.handler.Handler in project cxf by apache.

the class JavaxAnnotationHandlerChainBuilderTest method testFindHandlerChainAnnotationPerPortServiceBinding.

@Test
public void testFindHandlerChainAnnotationPerPortServiceBinding() {
    JavaxHandlerTestImpl handlerTestImpl = new JavaxHandlerTestImpl();
    AnnotationHandlerChainBuilder chainBuilder = new AnnotationHandlerChainBuilder();
    QName portQName = new QName("namespacedoesntsupportyet", "SoapPort1");
    QName serviceQName = new QName("namespacedoesntsupportyet", "SoapService1");
    String bindingID = "http://schemas.xmlsoap.org/wsdl/soap/http";
    @SuppressWarnings("rawtypes") List<Handler> handlers = chainBuilder.buildHandlerChainFromClass(handlerTestImpl.getClass(), portQName, serviceQName, bindingID);
    assertNotNull(handlers);
    assertEquals(5, handlers.size());
}
Also used : QName(javax.xml.namespace.QName) Handler(javax.xml.ws.handler.Handler) LogicalHandler(javax.xml.ws.handler.LogicalHandler) Test(org.junit.Test)

Aggregations

Handler (javax.xml.ws.handler.Handler)100 QName (javax.xml.namespace.QName)47 ArrayList (java.util.ArrayList)46 BindingProvider (javax.xml.ws.BindingProvider)36 URL (java.net.URL)32 Service (javax.xml.ws.Service)29 Test (org.junit.Test)29 LogicalHandler (javax.xml.ws.handler.LogicalHandler)24 Binding (javax.xml.ws.Binding)11 WebServiceException (javax.xml.ws.WebServiceException)11 MessageContext (javax.xml.ws.handler.MessageContext)9 SOAPHandler (javax.xml.ws.handler.soap.SOAPHandler)9 Exchange (org.apache.cxf.message.Exchange)9 IOException (java.io.IOException)8 SOAPMessageContext (javax.xml.ws.handler.soap.SOAPMessageContext)7 HandlerChainInvoker (org.apache.cxf.jaxws.handler.HandlerChainInvoker)7 DataHandler (javax.activation.DataHandler)6 InitialContext (javax.naming.InitialContext)6 Source (javax.xml.transform.Source)6 DOMSource (javax.xml.transform.dom.DOMSource)6