Search in sources :

Example 96 with Handler

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

the class JakartaAnnotationHandlerChainBuilderTest method testFindHandlerChainAnnotationPerPortServiceBindingNegative.

@Test
public void testFindHandlerChainAnnotationPerPortServiceBindingNegative() {
    JakartaHandlerTestImpl handlerTestImpl = new JakartaHandlerTestImpl();
    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 97 with Handler

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

the class LogicalHandlerInterceptorTest method testInterceptSuccess.

@Test
public void testInterceptSuccess() {
    List<LogicalHandler<?>> list = new ArrayList<>();
    list.add(new LogicalHandler<LogicalMessageContext>() {

        public void close(MessageContext arg0) {
        }

        public boolean handleFault(LogicalMessageContext arg0) {
            return true;
        }

        public boolean handleMessage(LogicalMessageContext arg0) {
            return true;
        }
    });
    @SuppressWarnings("rawtypes") List<Handler> hList = CastUtils.cast(list);
    expect(binding.getHandlerChain()).andReturn(hList).anyTimes();
    expect(invoker.getLogicalHandlers()).andReturn(list);
    expect(message.getExchange()).andReturn(exchange).anyTimes();
    expect(message.get(Message.REQUESTOR_ROLE)).andReturn(Boolean.TRUE).anyTimes();
    expect(message.keySet()).andReturn(new TreeSet<String>()).anyTimes();
    expect(exchange.get(HandlerChainInvoker.class)).andReturn(invoker);
    expect(exchange.getOutMessage()).andReturn(message);
    expect(invoker.invokeLogicalHandlers(eq(true), isA(LogicalMessageContext.class))).andReturn(true);
    control.replay();
    LogicalHandlerInInterceptor li = new LogicalHandlerInInterceptor(binding);
    assertEquals("unexpected phase", "pre-protocol-frontend", li.getPhase());
    li.handleMessage(message);
    control.verify();
}
Also used : LogicalMessageContext(javax.xml.ws.handler.LogicalMessageContext) TreeSet(java.util.TreeSet) LogicalHandler(javax.xml.ws.handler.LogicalHandler) ArrayList(java.util.ArrayList) LogicalHandler(javax.xml.ws.handler.LogicalHandler) Handler(javax.xml.ws.handler.Handler) LogicalHandlerInInterceptor(org.apache.cxf.jaxws.handler.logical.LogicalHandlerInInterceptor) LogicalMessageContext(javax.xml.ws.handler.LogicalMessageContext) MessageContext(javax.xml.ws.handler.MessageContext) Test(org.junit.Test)

Example 98 with Handler

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

the class LogicalHandlerInterceptorTest method xtestReturnFalseClientSide.

// JAX-WS spec: If handler returns false, for a request-response MEP, if the message
// direction is reversed during processing of a request message then the message
// becomes a response message.
// NOTE: commented out as this has been covered by other tests.
@Test
@org.junit.Ignore
public void xtestReturnFalseClientSide() throws Exception {
    @SuppressWarnings("rawtypes") List<Handler> list = new ArrayList<>();
    list.add(new LogicalHandler<LogicalMessageContext>() {

        public void close(MessageContext arg0) {
        }

        public boolean handleFault(LogicalMessageContext messageContext) {
            return true;
        }

        public boolean handleMessage(LogicalMessageContext messageContext) {
            LogicalMessage msg = messageContext.getMessage();
            AddNumbersResponse resp = new AddNumbersResponse();
            resp.setReturn(11);
            msg.setPayload(resp, null);
            return false;
        }
    });
    HandlerChainInvoker invoker1 = new HandlerChainInvoker(list);
    IMocksControl control1 = createNiceControl();
    Binding binding1 = control1.createMock(Binding.class);
    @SuppressWarnings("rawtypes") List<Handler> hList = CastUtils.cast(list);
    expect(binding1.getHandlerChain()).andReturn(hList).anyTimes();
    Exchange exchange1 = control1.createMock(Exchange.class);
    expect(exchange1.get(HandlerChainInvoker.class)).andReturn(invoker1).anyTimes();
    Message outMessage = new MessageImpl();
    outMessage.setExchange(exchange1);
    InterceptorChain chain = control1.createMock(InterceptorChain.class);
    outMessage.setInterceptorChain(chain);
    chain.abort();
    EasyMock.expectLastCall();
    MessageObserver observer = control1.createMock(MessageObserver.class);
    expect(exchange1.get(MessageObserver.class)).andReturn(observer).anyTimes();
    observer.onMessage(isA(Message.class));
    EasyMock.expectLastCall();
    control1.replay();
    LogicalHandlerInInterceptor li = new LogicalHandlerInInterceptor(binding1);
    li.handleMessage(outMessage);
    control1.verify();
}
Also used : Binding(javax.xml.ws.Binding) LogicalMessageContext(javax.xml.ws.handler.LogicalMessageContext) MessageObserver(org.apache.cxf.transport.MessageObserver) LogicalMessage(javax.xml.ws.LogicalMessage) Message(org.apache.cxf.message.Message) ArrayList(java.util.ArrayList) LogicalHandler(javax.xml.ws.handler.LogicalHandler) Handler(javax.xml.ws.handler.Handler) AddNumbersResponse(org.apache.handlers.types.AddNumbersResponse) IMocksControl(org.easymock.IMocksControl) Exchange(org.apache.cxf.message.Exchange) InterceptorChain(org.apache.cxf.interceptor.InterceptorChain) LogicalHandlerInInterceptor(org.apache.cxf.jaxws.handler.logical.LogicalHandlerInInterceptor) LogicalMessageContext(javax.xml.ws.handler.LogicalMessageContext) MessageContext(javax.xml.ws.handler.MessageContext) LogicalMessage(javax.xml.ws.LogicalMessage) MessageImpl(org.apache.cxf.message.MessageImpl) Test(org.junit.Test)

Example 99 with Handler

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

the class HandlerInvocationUsingAddNumbersTest method testHandlerInjectingResource.

@Test
public void testHandlerInjectingResource() throws Exception {
    // When CXF is deployed in a servlet container, ServletContextResourceResolver is used to resolve
    // Servlet context resources.
    Bus bus = BusFactory.getDefaultBus();
    ResourceManager resourceManager = bus.getExtension(ResourceManager.class);
    assertNotNull(resourceManager);
    resourceManager.addResourceResolver(new TestResourceResolver());
    URL wsdl = getClass().getResource("/wsdl/addNumbers.wsdl");
    AddNumbersServiceWithAnnotation service = new AddNumbersServiceWithAnnotation(wsdl, serviceName);
    AddNumbers port = service.getPort(portName, AddNumbers.class);
    setAddress(port, addNumbersAddress);
    @SuppressWarnings("rawtypes") List<Handler> handlerChain = ((BindingProvider) port).getBinding().getHandlerChain();
    SmallNumberHandler h = (SmallNumberHandler) handlerChain.get(0);
    assertEquals("injectedValue", h.getInjectedString());
}
Also used : Bus(org.apache.cxf.Bus) AddNumbers(org.apache.handlers.AddNumbers) Handler(javax.xml.ws.handler.Handler) ResourceManager(org.apache.cxf.resource.ResourceManager) URL(java.net.URL) Test(org.junit.Test)

Example 100 with Handler

use of javax.xml.ws.handler.Handler in project quickstart by wildfly.

the class WSATSimpleServletClient method doGet.

@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    /*
         * Add client handler chain
         */
    BindingProvider bindingProvider = (BindingProvider) client;
    @SuppressWarnings("rawtypes") List<Handler> handlers = new ArrayList<>(1);
    handlers.add(new JaxWSHeaderContextProcessor());
    bindingProvider.getBinding().setHandlerChain(handlers);
    /*
         * Lookup the DNS name of the server from the environment and set the endpoint address on the client.
         */
    String openshift = System.getenv("OPENSHIFT_APP_DNS");
    if (openshift != null) {
        bindingProvider.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, "http://" + openshift + "/RestaurantServiceAT");
    }
    resp.setContentType("text/html");
    PrintWriter out = resp.getWriter();
    out.write("<h1>Quickstart: This example demonstrates the deployment of a WS-AT (WS-AtomicTransaction) enabled JAX-WS Web service bundled in a war archive for deployment to *Red Hat JBoss Enterprise Application Platform*.</h1>");
    System.out.println("[CLIENT] Creating a new WS-AT User Transaction");
    UserTransaction ut = UserTransactionFactory.userTransaction();
    try {
        System.out.println("[CLIENT] Beginning Atomic Transaction (All calls to Web services that support WS-AT wil be included in this transaction)");
        ut.begin();
        System.out.println("[CLIENT] invoking makeBooking() on WS");
        client.makeBooking();
        System.out.println("[CLIENT] committing Atomic Transaction (This will cause the AT to complete successfully)");
        ut.commit();
        out.write("<p><b>Transaction succeeded!</b></p>");
    } catch (Exception e) {
        e.printStackTrace();
        out.write("<p><b>Transaction failed with the following error:</b></p>");
        out.write("<p><blockquote>");
        out.write(e.toString());
        out.write("</blockquote></p>");
    } finally {
        rollbackIfActive(ut);
        client.reset();
        out.write("<p><i>Go to your JBoss EAP Server console or log to see the detailed result of the transaction.</i></p>");
    }
}
Also used : UserTransaction(com.arjuna.mw.wst11.UserTransaction) JaxWSHeaderContextProcessor(com.arjuna.mw.wst11.client.JaxWSHeaderContextProcessor) ArrayList(java.util.ArrayList) Handler(javax.xml.ws.handler.Handler) BindingProvider(javax.xml.ws.BindingProvider) ServletException(javax.servlet.ServletException) IOException(java.io.IOException) PrintWriter(java.io.PrintWriter)

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