cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j...@apache.org
Subject svn commit: r492939 - in /incubator/cxf/trunk: rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/ rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/handler/ rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/handler/ systests/src/test/java/org/...
Date Fri, 05 Jan 2007 08:23:49 GMT
Author: jliu
Date: Fri Jan  5 00:23:48 2007
New Revision: 492939

URL: http://svn.apache.org/viewvc?view=rev&rev=492939
Log:
CXF-336: support adding client side JAX-WS handlers through HandlerResolver.

Added:
    incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/handler/PortInfoImpl.java
  (with props)
Modified:
    incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/ServiceImpl.java
    incubator/cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/handler/HandlerChainInvokerTest.java
    incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/handlers/HandlerInvocationTest.java

Modified: incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/ServiceImpl.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/ServiceImpl.java?view=diff&rev=492939&r1=492938&r2=492939
==============================================================================
--- incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/ServiceImpl.java
(original)
+++ incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/ServiceImpl.java
Fri Jan  5 00:23:48 2007
@@ -26,6 +26,7 @@
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Iterator;
+import java.util.List;
 import java.util.Map;
 import java.util.ResourceBundle;
 import java.util.concurrent.Executor;
@@ -39,6 +40,7 @@
 import javax.xml.ws.Dispatch;
 import javax.xml.ws.Service.Mode;
 import javax.xml.ws.WebServiceException;
+import javax.xml.ws.handler.Handler;
 import javax.xml.ws.handler.HandlerResolver;
 import javax.xml.ws.http.HTTPBinding;
 import javax.xml.ws.spi.ServiceDelegate;
@@ -56,6 +58,7 @@
 import org.apache.cxf.jaxb.JAXBDataBinding;
 import org.apache.cxf.jaxws.binding.soap.JaxWsSoapBindingInfoFactoryBean;
 import org.apache.cxf.jaxws.handler.HandlerResolverImpl;
+import org.apache.cxf.jaxws.handler.PortInfoImpl;
 import org.apache.cxf.jaxws.support.DummyImpl;
 import org.apache.cxf.jaxws.support.JaxWsEndpointImpl;
 import org.apache.cxf.jaxws.support.JaxWsServiceFactoryBean;
@@ -81,7 +84,7 @@
 
     private HandlerResolver handlerResolver;
     private final Collection<QName> ports = new HashSet<QName>();
-    private Map<QName, PortInfo> portInfos = new HashMap<QName, PortInfo>();
+    private Map<QName, PortInfoImpl> portInfos = new HashMap<QName, PortInfoImpl>();
     private Executor executor;
     private QName serviceName;
 //    private Class<?> clazz;
@@ -96,7 +99,8 @@
     }
 
     public void addPort(QName portName, String bindingId, String address) {
-        PortInfo portInfo = new PortInfo(bindingId, address);
+        PortInfoImpl portInfo = new PortInfoImpl(bindingId, portName, serviceName);
+        portInfo.setAddress(address);
         portInfos.put(portName, portInfo);
     }
 
@@ -107,7 +111,7 @@
         if (portName == null) {
             ei = si.getEndpoints().iterator().next();
         } else {
-            PortInfo portInfo = getPortInfo(portName);
+            PortInfoImpl portInfo = getPortInfo(portName);
             if (null != portInfo) {
                 try {
                     ei = createEndpointInfo(sf, portName, portInfo);
@@ -253,8 +257,8 @@
                 pn = new QName(service.getName().getNamespaceURI(), ei.getName().getLocalPart());
             }
         } else {
-            // first chech the endpointInfo from portInfos
-            PortInfo portInfo = portInfos.get(portName);
+            // first check the endpointInfo from portInfos
+            PortInfoImpl portInfo = portInfos.get(portName);
             if (null != portInfo) {
                 try {
                     ei = createEndpointInfo(serviceFactory, portName, portInfo);
@@ -284,6 +288,9 @@
         Client client = new ClientImpl(bus, jaxwsEndpoint);
 
         InvocationHandler ih = new JaxWsClientProxy(client, jaxwsEndpoint.getJaxwsBinding());
+        
+        List<Handler> hc = ((JaxWsClientProxy)ih).getBinding().getHandlerChain();
+        hc.addAll(handlerResolver.getHandlerChain(portInfos.get(pn)));
 
         // configuration stuff
         // createHandlerChainForBinding(serviceEndpointInterface, portName,
@@ -301,7 +308,7 @@
 
     private EndpointInfo createEndpointInfo(AbstractServiceFactoryBean serviceFactory, 
                                             QName portName,
-                                            PortInfo portInfo) throws BusException {
+                                            PortInfoImpl portInfo) throws BusException {
         EndpointInfo ei = null;
         String address = portInfo.getAddress();
 
@@ -309,12 +316,12 @@
         DestinationFactory df = dfm.getDestinationFactoryForUri(portInfo.getAddress());
 
         String transportId = df.getTransportIds().get(0);
-        String bindingUri = portInfo.getBindingUri();
+        String bindingID = portInfo.getBindingID();
 
         // TODO: Replace with discovery mechanism, now it just the hardcode        
         AbstractBindingInfoFactoryBean bindingFactory = null;
-        if (bindingUri.equals(XMLConstants.NS_XML_FORMAT) 
-            || bindingUri.equals(HTTPBinding.HTTP_BINDING)) {
+        if (bindingID.equals(XMLConstants.NS_XML_FORMAT) 
+            || bindingID.equals(HTTPBinding.HTTP_BINDING)) {
             bindingFactory = new XMLBindingInfoFactoryBean();
         } else { // we set the default binding to be soap binding
             JaxWsSoapBindingInfoFactoryBean soapBindingFactory = new JaxWsSoapBindingInfoFactoryBean();
@@ -345,11 +352,11 @@
         }
     }
 
-    private PortInfo getPortInfo(QName portName) {
+    private PortInfoImpl getPortInfo(QName portName) {
         // TODO if the portName null ?
         return portInfos.get(portName);
     }
-
+/*
     static class PortInfo {
         private String bindingUri;
         private String address;
@@ -375,5 +382,5 @@
             this.bindingUri = bindingUri;
         }
     }
-
+*/
 }

Added: incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/handler/PortInfoImpl.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/handler/PortInfoImpl.java?view=auto&rev=492939
==============================================================================
--- incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/handler/PortInfoImpl.java
(added)
+++ incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/handler/PortInfoImpl.java
Fri Jan  5 00:23:48 2007
@@ -0,0 +1,57 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.cxf.jaxws.handler;
+
+import javax.xml.namespace.QName;
+
+import javax.xml.ws.handler.PortInfo;
+
+public class PortInfoImpl implements PortInfo {
+    private String bindingID;
+    private QName portName;
+    private QName serviceName;
+    private String address;
+
+    public PortInfoImpl(String bindingID, QName portName, QName serviceName) {
+        this.bindingID = bindingID;
+        this.portName = portName;
+        this.serviceName = serviceName;
+    }
+
+    public String getBindingID() {
+        return bindingID;
+    }
+
+    public QName getPortName() {
+        return portName;
+    }
+
+    public QName getServiceName() {
+        return serviceName;
+    }
+
+    public String getAddress() {
+        return address;
+    }
+
+    public void setAddress(String address) {
+        this.address = address;
+    }
+}

Propchange: incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/handler/PortInfoImpl.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/handler/PortInfoImpl.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Modified: incubator/cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/handler/HandlerChainInvokerTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/handler/HandlerChainInvokerTest.java?view=diff&rev=492939&r1=492938&r2=492939
==============================================================================
--- incubator/cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/handler/HandlerChainInvokerTest.java
(original)
+++ incubator/cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/handler/HandlerChainInvokerTest.java
Fri Jan  5 00:23:48 2007
@@ -50,7 +50,6 @@
     
     TestLogicalHandler[] logicalHandlers = new TestLogicalHandler[HANDLER_COUNT];
     TestProtocolHandler[] protocolHandlers = new TestProtocolHandler[HANDLER_COUNT];
-    //TestStreamHandler[] streamHandlers = new TestStreamHandler[HANDLER_COUNT]; 
 
     public void setUp() {
         AbstractHandlerBase.clear(); 
@@ -64,10 +63,7 @@
             protocolHandlers[i] = new TestProtocolHandler();
             handlers.add(protocolHandlers[i]);
         }
-  /*      for (int i = 0; i < protocolHandlers.length; i++) {
-            streamHandlers[i] = new TestStreamHandler();
-            handlers.add(streamHandlers[i]);
-        }*/
+
         invoker = new HandlerChainInvoker(handlers);
     }
     
@@ -75,10 +71,8 @@
         invoker = new HandlerChainInvoker(new ArrayList<Handler>());
         assertTrue(invoker.invokeLogicalHandlers(false, lmc));
         assertTrue(doInvokeProtocolHandlers(false));
-        //assertTrue(invoker.invokeStreamHandlers(smc));
     }
 
-    
     public void testHandlerPartitioning() { 
         
         assertEquals(HANDLER_COUNT, invoker.getLogicalHandlers().size());
@@ -86,18 +80,12 @@
             assertTrue(h instanceof LogicalHandler); 
         }
 
-//        assertEquals(HANDLER_COUNT, invoker.getStreamHandlers().size());
-/*        for (Handler h : invoker.getStreamHandlers()) {
-            assertTrue(h instanceof StreamHandler); 
-        }
-*/
         assertEquals(HANDLER_COUNT, invoker.getProtocolHandlers().size());
         for (Handler h : invoker.getProtocolHandlers()) {
             assertTrue(!(h instanceof LogicalHandler)); 
         }
 
     } 
-
     
     public void testInvokeHandlersOutbound() {
 
@@ -131,8 +119,6 @@
         assertEquals(4, invoker.getInvokedHandlers().size());
         assertTrue(invoker.isInbound());
 
-        //checkStreamHandlersInvoked(false, true); 
-
         assertFalse(invoker.isClosed()); 
         assertTrue(logicalHandlers[0].getInvokedOrder() > logicalHandlers[1].getInvokedOrder());
         assertTrue(logicalHandlers[1].getInvokedOrder() > protocolHandlers[0].getInvokedOrder());
@@ -300,7 +286,6 @@
 
         invoker.invokeLogicalHandlers(false, lmc); 
         doInvokeProtocolHandlers(false);
-//        invoker.invokeStreamHandlers(smc);
         assertEquals(4, invoker.getInvokedHandlers().size()); 
 
         invoker.mepComplete(message); 
@@ -309,8 +294,6 @@
         assertTrue("close not invoked on logicalHandlers", logicalHandlers[1].isCloseInvoked());

         assertTrue("close not invoked on protocolHandlers", protocolHandlers[0].isCloseInvoked());
         assertTrue("close not invoked on protocolHandlers", protocolHandlers[1].isCloseInvoked());
-//        assertTrue("close not invoked on streamHandlers", streamHandlers[0].isCloseInvoked());
-//        assertTrue("close not invoked on streamHandlers", streamHandlers[1].isCloseInvoked());
 
         assertTrue("incorrect invocation order of close", protocolHandlers[1].getInvokedOrder()

                    < protocolHandlers[0].getInvokedOrder());
@@ -383,22 +366,7 @@
         assertTrue(invoker.getInvokedHandlers().contains(protocolHandlers[0])); 
         assertTrue(invoker.getInvokedHandlers().contains(protocolHandlers[1])); 
     }
-/*    
-    protected void checkStreamHandlersInvoked(boolean outboundProperty, boolean requestorProperty)
{ 
-        
-        // InputStreamMessageContext istreamCtx = new TestInputStreamMessageContext(message);
   
-        invoker.invokeStreamHandlers(smc);
-                 
-        assertNotNull(message.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY));
-        assertEquals(outboundProperty, message.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY));
-        // assertNotNull(message.get(ObjectMessageContext.REQUESTOR_ROLE_PROPERTY));
-        // assertEquals(requestorProperty, message.get(ObjectMessageContext.REQUESTOR_ROLE_PROPERTY));
-        assertTrue("handler not invoked", streamHandlers[0].isHandleMessageInvoked());
-        assertTrue("handler not invoked", streamHandlers[1].isHandleMessageInvoked());
-        assertTrue(invoker.getInvokedHandlers().contains(streamHandlers[0])); 
-        assertTrue(invoker.getInvokedHandlers().contains(streamHandlers[1])); 
-    }
-*/    
+  
     private void doHandleFaultExceptionTest(RuntimeException e) { 
 
         // put invoker into fault state
@@ -418,11 +386,6 @@
         return invoker.invokeProtocolHandlers(requestor, pmc);
     }
     
-  /*  static class TestStreamHandler extends AbstractHandlerBase<StreamMessageContext>

-        implements StreamHandler {
-
-    }
-*/
     static class TestProtocolHandler extends AbstractHandlerBase<SOAPMessageContext>
{
         
     }
@@ -539,28 +502,5 @@
             sid = 0; 
         } 
     }
-    
-    /*
-    class TestInputStreamMessageContext extends MessageContextWrapper implements InputStreamMessageContext
{
-
-        TestInputStreamMessageContext(MessageContext wrapped) {
-            super(wrapped);
-        }
 
-        public InputStream getInputStream() {
-            return null;
-        }
-
-        public boolean isFault() {
-            return false;
-        }
-
-        public void setFault(boolean isFault) {
-        }
-
-        public void setInputStream(InputStream ins) {
-        }
-
-    }
-    */
 }

Modified: incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/handlers/HandlerInvocationTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/handlers/HandlerInvocationTest.java?view=diff&rev=492939&r1=492938&r2=492939
==============================================================================
--- incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/handlers/HandlerInvocationTest.java
(original)
+++ incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/handlers/HandlerInvocationTest.java
Fri Jan  5 00:23:48 2007
@@ -20,6 +20,7 @@
 
 import java.io.InputStream;
 import java.net.URL;
+import java.util.ArrayList;
 import java.util.Iterator;
 import java.util.List;
 import javax.xml.bind.JAXBContext;
@@ -33,8 +34,10 @@
 import javax.xml.ws.ProtocolException;
 import javax.xml.ws.Service;
 import javax.xml.ws.handler.Handler;
+import javax.xml.ws.handler.HandlerResolver;
 import javax.xml.ws.handler.LogicalMessageContext;
 import javax.xml.ws.handler.MessageContext;
+import javax.xml.ws.handler.PortInfo;
 
 import org.w3c.dom.Node;
 import org.w3c.dom.NodeList;
@@ -99,6 +102,22 @@
         assertEquals(1, handler2.getHandleMessageInvoked());
     }
     
+    public void testAddHandlerThroughHandlerResolverClientSide() {
+        TestHandler<LogicalMessageContext> handler1 = new TestHandler<LogicalMessageContext>(false);
+        TestHandler<LogicalMessageContext> handler2 = new TestHandler<LogicalMessageContext>(false);
+        
+        MyHandlerResolver myHandlerResolver = new MyHandlerResolver(handler1, handler2);
+         
+        service.setHandlerResolver(myHandlerResolver);
+        
+        HandlerTest handlerTestNew = service.getPort(portName, HandlerTest.class);
+
+        handlerTestNew.pingOneWay();
+
+        assertEquals(1, handler1.getHandleMessageInvoked());
+        assertEquals(1, handler2.getHandleMessageInvoked());
+    }
+    
     public void xtestLogicalHandlerTwoWay() throws Exception {
         TestHandler<LogicalMessageContext> handler1 = new TestHandler<LogicalMessageContext>(false);
         TestHandler<LogicalMessageContext> handler2 = new TestHandler<LogicalMessageContext>(false);
@@ -394,6 +413,20 @@
             stringList = pr.getHandlersInfo();
         }
         return stringList;
+    }
+    
+    public class MyHandlerResolver implements HandlerResolver {
+        List<Handler> chain = new ArrayList<Handler>();
+        
+        public MyHandlerResolver(Handler...handlers) {
+            for (Handler h : handlers) {
+                chain.add(h);
+            }
+        }
+        public List<Handler> getHandlerChain(PortInfo portInfo) {
+            return chain;
+        }
+            
     }
     
     /*



Mime
View raw message