Author: jliu
Date: Thu Jan 11 00:33:22 2007
New Revision: 495152
URL: http://svn.apache.org/viewvc?view=rev&rev=495152
Log:
CXF-336. Support adding handlers by annotations on the client side.
Added:
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/handlers/AddNumbersServiceWithAnnotation.java
(with props)
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/handlers/HandlerInvocationUsingAddNumbersTest.java
- copied, changed from r493898,
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/handlers/HandlerClientServerTest.java
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/handlers/handlers_smallnumbers.xml
(with props)
Removed:
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/handlers/HandlerClientServerTest.java
Modified:
incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/EndpointImpl.java
incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/ServiceImpl.java
incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/handler/HandlerResolverImpl.java
Modified:
incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/EndpointImpl.java
URL:
http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/EndpointImpl.java?view=diff&rev=495152&r1=495151&r2=495152
==============================================================================
---
incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/EndpointImpl.java
(original)
+++
incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/EndpointImpl.java
Thu Jan 11 00:33:22 2007
@@ -266,17 +266,13 @@
}
/**
- * Obtain handler chain from configuration first. If none is specified,
- * default to the chain configured in the code, i.e. in annotations.
+ * Obtain handler chain from annotations.
*
*/
private void configureHandlers() {
LOG.fine("loading handler chain for endpoint");
AnnotationHandlerChainBuilder builder = new
AnnotationHandlerChainBuilder();
- //TBD: get configuratoin from config file
- //List<Handler> chain = builder.buildHandlerChainFromConfiguration(hc);
-
//builder.setHandlerInitEnabled(configuration.getBoolean(ENABLE_HANDLER_INIT));
List<Handler> chain = null;
if (null == chain || chain.size() == 0) {
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=495152&r1=495151&r2=495152
==============================================================================
---
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
Thu Jan 11 00:33:22 2007
@@ -87,15 +87,16 @@
private Map<QName, PortInfoImpl> portInfos = new HashMap<QName,
PortInfoImpl>();
private Executor executor;
private QName serviceName;
-// private Class<?> clazz;
+ private Class<?> clazz;
public ServiceImpl(Bus b, URL url, QName name, Class<?> cls) {
bus = b;
wsdlURL = url;
this.serviceName = name;
-// clazz = cls;
+ clazz = cls;
+
+ handlerResolver = new HandlerResolverImpl(bus, name, clazz);
- handlerResolver = new HandlerResolverImpl(bus, name);
}
public void addPort(QName portName, String bindingId, String address) {
Modified:
incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/handler/HandlerResolverImpl.java
URL:
http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/handler/HandlerResolverImpl.java?view=diff&rev=495152&r1=495151&r2=495152
==============================================================================
---
incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/handler/HandlerResolverImpl.java
(original)
+++
incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/handler/HandlerResolverImpl.java
Thu Jan 11 00:33:22 2007
@@ -32,21 +32,18 @@
import org.apache.cxf.Bus;
public class HandlerResolverImpl implements HandlerResolver {
- public static final String PORT_CONFIGURATION_URI =
- "http://cxf.apache.org/bus/jaxws/port-config";
-
private final Map<PortInfo, List<Handler>> handlerMap = new
HashMap<PortInfo, List<Handler>>();
- //private Configuration busConfiguration;
- //private QName service;
- private ClassLoader serviceEndpointInterfaceClassLoader;
+
+ //private QName service;
+ private Class<?> annotationClass;
- public HandlerResolverImpl(Bus bus, QName serviceName) {
- //this.busConfiguration = pBusConfiguration;
+ public HandlerResolverImpl(Bus bus, QName serviceName, Class<?> clazz) {
//this.service = pService;
+ this.annotationClass = clazz;
}
public HandlerResolverImpl() {
- this(null, null);
+ this(null, null, null);
}
public List<Handler> getHandlerChain(PortInfo portInfo) {
@@ -61,34 +58,27 @@
private List<Handler> createHandlerChain(PortInfo portInfo) {
List<Handler> chain = null;
- /*
- Configuration portConfiguration = null;
- String id = portInfo.getPortName().getLocalPart();
- if (service != null) {
- id = service.toString() + "/" +
portInfo.getPortName().getLocalPart();
- }
- if (null != busConfiguration) {
- portConfiguration = busConfiguration
- .getChild(PORT_CONFIGURATION_URI, id);
- }
- if (null != portConfiguration) {
- HandlerChainBuilder builder = new HandlerChainBuilder();
- builder.setHandlerClassLoader(serviceEndpointInterfaceClassLoader);
- HandlerChainType hc =
(HandlerChainType)portConfiguration.getObject("handlerChain");
- chain = builder.buildHandlerChainFromConfiguration(hc);
- }
- */
+
if (null == chain) {
chain = new ArrayList<Handler>();
}
+ if (annotationClass != null) {
+ chain.addAll(getHandlersFromAnnotation(annotationClass));
+ }
return chain;
}
- public ClassLoader getServiceEndpointInterfaceClassLoader() {
- return serviceEndpointInterfaceClassLoader;
- }
+ /**
+ * Obtain handler chain from annotations.
+ *
+ * @param obj A endpoint implementation class or a SEI, or a generated
+ * service class.
+ */
+ private List<Handler> getHandlersFromAnnotation(Class<?> clazz) {
+ AnnotationHandlerChainBuilder builder = new
AnnotationHandlerChainBuilder();
- public void setServiceEndpointInterfaceClassLoader(ClassLoader
classLoader) {
- this.serviceEndpointInterfaceClassLoader = classLoader;
+ List<Handler> chain = builder.buildHandlerChainFromClass(clazz);
+
+ return chain;
}
}
Added:
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/handlers/AddNumbersServiceWithAnnotation.java
URL:
http://svn.apache.org/viewvc/incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/handlers/AddNumbersServiceWithAnnotation.java?view=auto&rev=495152
==============================================================================
---
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/handlers/AddNumbersServiceWithAnnotation.java
(added)
+++
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/handlers/AddNumbersServiceWithAnnotation.java
Thu Jan 11 00:33:22 2007
@@ -0,0 +1,76 @@
+/**
+ * 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.systest.handlers;
+
+import java.net.MalformedURLException;
+import java.net.URL;
+
+import javax.jws.HandlerChain;
+import javax.xml.namespace.QName;
+import javax.xml.ws.Service;
+import javax.xml.ws.WebEndpoint;
+import javax.xml.ws.WebServiceClient;
+import org.apache.handlers.AddNumbers;
+/**
+ * This class was generated by the CXF 2.0-incubator-RC-SNAPSHOT
+ * Mon Jan 08 09:43:05 CST 2007
+ * Generated source version: 2.0-incubator-RC-SNAPSHOT
+ *
+ */
+
[EMAIL PROTECTED](name = "AddNumbersService",
+ targetNamespace = "http://apache.org/handlers",
+ wsdlLocation =
"file:/D:/svn/cxf/trunk/testutils/src/main/resources/wsdl/addNumbers.wsdl")
[EMAIL PROTECTED](file = "./handlers_smallnumbers.xml", name =
"TestHandlerChain")
+public class AddNumbersServiceWithAnnotation extends Service {
+
+ private static final URL WSDL_LOCATION;
+ private static final QName SERVICE = new
QName("http://apache.org/handlers", "AddNumbersService");
+ private static final QName ADDNUMBERS_PORT = new
QName("http://apache.org/handlers", "AddNumbersPort");
+
+ static {
+ URL url = null;
+ try {
+ url = new
URL("file:/D:/svn/cxf/trunk/testutils/src/main/resources/wsdl/addNumbers.wsdl");
+ } catch (MalformedURLException e) {
+ e.printStackTrace();
+ }
+ WSDL_LOCATION = url;
+ }
+
+ public AddNumbersServiceWithAnnotation(URL wsdlLocation, QName
serviceName) {
+ super(wsdlLocation, serviceName);
+ }
+
+ public AddNumbersServiceWithAnnotation() {
+ super(WSDL_LOCATION, SERVICE);
+ }
+
+ /**
+ *
+ * @return
+ * returns AddNumbersPort
+ */
+ @WebEndpoint(name = "AddNumbersPort")
+ public AddNumbers getAddNumbersPort() {
+ return (AddNumbers)super.getPort(ADDNUMBERS_PORT, AddNumbers.class);
+ }
+
+}
Propchange:
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/handlers/AddNumbersServiceWithAnnotation.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/handlers/AddNumbersServiceWithAnnotation.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Copied:
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/handlers/HandlerInvocationUsingAddNumbersTest.java
(from r493898,
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/handlers/HandlerClientServerTest.java)
URL:
http://svn.apache.org/viewvc/incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/handlers/HandlerInvocationUsingAddNumbersTest.java?view=diff&rev=495152&p1=incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/handlers/HandlerClientServerTest.java&r1=493898&p2=incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/handlers/HandlerInvocationUsingAddNumbersTest.java&r2=495152
==============================================================================
---
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/handlers/HandlerClientServerTest.java
(original)
+++
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/handlers/HandlerInvocationUsingAddNumbersTest.java
Thu Jan 11 00:33:22 2007
@@ -20,7 +20,6 @@
package org.apache.cxf.systest.handlers;
import java.net.URL;
-import java.util.ArrayList;
import java.util.List;
import javax.xml.bind.JAXBContext;
@@ -43,14 +42,13 @@
import org.apache.handlers.types.ObjectFactory;
-public class HandlerClientServerTest extends ClientServerTestBase {
+public class HandlerInvocationUsingAddNumbersTest extends ClientServerTestBase
{
static QName serviceName = new QName("http://apache.org/handlers",
"AddNumbersService");
-
static QName portName = new QName("http://apache.org/handlers",
"AddNumbersPort");
public static Test suite() throws Exception {
- TestSuite suite = new TestSuite(HandlerClientServerTest.class);
+ TestSuite suite = new
TestSuite(HandlerInvocationUsingAddNumbersTest.class);
return new ClientServerSetupBase(suite) {
public void startServers() throws Exception {
assertTrue("server did not launch correctly",
launchServer(HandlerServer.class));
@@ -58,17 +56,26 @@
};
}
- public void testInvokeLogicalHandler() throws Exception {
+ public void testAddHandlerProgrammaticallyClientSide() throws Exception {
URL wsdl = getClass().getResource("/wsdl/addNumbers.wsdl");
AddNumbersService service = new AddNumbersService(wsdl, serviceName);
AddNumbers port = (AddNumbers)service.getPort(portName,
AddNumbers.class);
- //Add client side handlers programmatically
SmallNumberHandler sh = new SmallNumberHandler();
- List<Handler> newHandlerChain = new ArrayList<Handler>();
- newHandlerChain.add(sh);
- ((BindingProvider)port).getBinding().setHandlerChain(newHandlerChain);
+ addHandlersProgrammatically((BindingProvider)port, sh);
+
+ int result = port.addNumbers(10, 20);
+ assertEquals(200, result);
+ int result1 = port.addNumbers(5, 6);
+ assertEquals(11, result1);
+ }
+
+ public void testAddHandlerByAnnotationClientSide() throws Exception {
+ URL wsdl = getClass().getResource("/wsdl/addNumbers.wsdl");
+
+ AddNumbersServiceWithAnnotation service = new
AddNumbersServiceWithAnnotation(wsdl, serviceName);
+ AddNumbers port = (AddNumbers)service.getPort(portName,
AddNumbers.class);
int result = port.addNumbers(10, 20);
assertEquals(200, result);
@@ -86,11 +93,8 @@
JAXBContext jc = JAXBContext.newInstance("org.apache.handlers.types");
Dispatch<Object> disp = service.createDispatch(portName, jc,
Service.Mode.PAYLOAD);
- //Add client side handlers programmatically
SmallNumberHandler sh = new SmallNumberHandler();
- List<Handler> newHandlerChain = new ArrayList<Handler>();
- newHandlerChain.add(sh);
- ((BindingProvider)disp).getBinding().setHandlerChain(newHandlerChain);
+ addHandlersProgrammatically(disp, sh);
org.apache.handlers.types.AddNumbers req = new
org.apache.handlers.types.AddNumbers();
req.setArg0(10);
@@ -102,6 +106,14 @@
assertNotNull(response);
AddNumbersResponse value = (AddNumbersResponse)response.getValue();
assertEquals(200, value.getReturn());
+ }
+
+ private void addHandlersProgrammatically(BindingProvider bp,
Handler...handlers) {
+ List<Handler> handlerChain = bp.getBinding().getHandlerChain();
+ assertNotNull(handlerChain);
+ for (Handler h : handlers) {
+ handlerChain.add(h);
+ }
}
}
Added:
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/handlers/handlers_smallnumbers.xml
URL:
http://svn.apache.org/viewvc/incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/handlers/handlers_smallnumbers.xml?view=auto&rev=495152
==============================================================================
---
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/handlers/handlers_smallnumbers.xml
(added)
+++
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/handlers/handlers_smallnumbers.xml
Thu Jan 11 00:33:22 2007
@@ -0,0 +1,35 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.
+-->
+<handler-chains xmlns="http://java.sun.com/xml/ns/javaee"
+xmlns:cfg="http://cxf.apache.org/configuration/cfg"
+xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
+xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+xsi:schemaLocation="http://java.sun.com/xml/ns/javaee">
+ <handler-chain>
+ <handler>
+ <handler-name>ph1</handler-name>
+
<handler-class>org.apache.cxf.systest.handlers.SmallNumberHandler</handler-class>
+ <init-param>
+ <param-name>token</param-name>
+ <param-value>String</param-value>
+ </init-param>
+ </handler>
+ </handler-chain>
+</handler-chains>
Propchange:
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/handlers/handlers_smallnumbers.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/handlers/handlers_smallnumbers.xml
------------------------------------------------------------------------------
svn:keywords = Rev Date
Propchange:
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/handlers/handlers_smallnumbers.xml
------------------------------------------------------------------------------
svn:mime-type = text/xml