Author: sergeyb
Date: Mon Jun 14 16:49:43 2010
New Revision: 954552
URL: http://svn.apache.org/viewvc?rev=954552&view=rev
Log:
CXF-2846 : support for superclasses implementing or superinterfaces extending
JAXWS Provider
Added:
cxf/trunk/systests/jaxws/src/test/java/org/apache/cxf/systest/provider/AbstractSourcePayloadProvider.java
(with props)
cxf/trunk/systests/jaxws/src/test/java/org/apache/cxf/systest/provider/SourceProvider.java
(with props)
Modified:
cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/EndpointUtils.java
cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/handler/AnnotationHandlerChainBuilder.java
cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/support/JaxWsImplementorInfo.java
cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/support/JaxWsServiceFactoryBean.java
cxf/trunk/systests/jaxws/src/test/java/org/apache/cxf/systest/provider/HWSourcePayloadProvider.java
Modified:
cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/EndpointUtils.java
URL:
http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/EndpointUtils.java?rev=954552&r1=954551&r2=954552&view=diff
==============================================================================
---
cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/EndpointUtils.java
(original)
+++
cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/EndpointUtils.java
Mon Jun 14 16:49:43 2010
@@ -52,11 +52,18 @@ public final class EndpointUtils {
}
private static boolean hasWebServiceProviderAnnotation(Class<?> cls) {
- if (cls != null) {
- return cls.isAnnotationPresent(WebServiceProvider.class);
+ if (cls == null) {
+ return false;
}
-
- return false;
+ if (null != cls.getAnnotation(WebServiceProvider.class)) {
+ return true;
+ }
+ for (Class<?> inf : cls.getInterfaces()) {
+ if (null != inf.getAnnotation(WebServiceProvider.class)) {
+ return true;
+ }
+ }
+ return hasWebServiceProviderAnnotation(cls.getSuperclass());
}
public static boolean isValidImplementor(Object implementor) {
@@ -76,4 +83,6 @@ public final class EndpointUtils {
LOG.info("Implementor is not annotated with WebService annotation.");
return false;
}
+
+
}
Modified:
cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/handler/AnnotationHandlerChainBuilder.java
URL:
http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/handler/AnnotationHandlerChainBuilder.java?rev=954552&r1=954551&r2=954552&view=diff
==============================================================================
---
cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/handler/AnnotationHandlerChainBuilder.java
(original)
+++
cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/handler/AnnotationHandlerChainBuilder.java
Mon Jun 14 16:49:43 2010
@@ -288,7 +288,10 @@ public class AnnotationHandlerChainBuild
return clazz.getResource(name);
}
- private HandlerChainAnnotation findHandlerChainAnnotation(Class<?> clz,
boolean searchSEI) {
+ private HandlerChainAnnotation findHandlerChainAnnotation(Class<?> clz,
boolean searchSEI) {
+ if (clz == null) {
+ return null;
+ }
if (LOG.isLoggable(Level.FINE)) {
LOG.fine("Checking for HandlerChain annotation on " +
clz.getName());
}
@@ -325,6 +328,9 @@ public class AnnotationHandlerChainBuild
break;
}
}
+ if (hcAnn == null) {
+ hcAnn = findHandlerChainAnnotation(clz.getSuperclass(),
false);
+ }
}
} else {
hcAnn = new HandlerChainAnnotation(ann, clz);
Modified:
cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/support/JaxWsImplementorInfo.java
URL:
http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/support/JaxWsImplementorInfo.java?rev=954552&r1=954551&r2=954552&view=diff
==============================================================================
---
cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/support/JaxWsImplementorInfo.java
(original)
+++
cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/support/JaxWsImplementorInfo.java
Mon Jun 14 16:49:43 2010
@@ -301,9 +301,26 @@ public class JaxWsImplementorInfo {
}
}
}
- wsProviderAnnotation =
implementorClass.getAnnotation(WebServiceProvider.class);
+
+ wsProviderAnnotation =
getWebServiceProviderAnnotation(implementorClass);
}
+ private static WebServiceProvider getWebServiceProviderAnnotation(Class<?>
cls) {
+ if (cls == null) {
+ return null;
+ }
+ WebServiceProvider ann = cls.getAnnotation(WebServiceProvider.class);
+ if (null != ann) {
+ return ann;
+ }
+ for (Class<?> inf : cls.getInterfaces()) {
+ if (null != inf.getAnnotation(WebServiceProvider.class)) {
+ return inf.getAnnotation(WebServiceProvider.class);
+ }
+ }
+ return getWebServiceProviderAnnotation(cls.getSuperclass());
+ }
+
public boolean isWebServiceProvider() {
return Provider.class.isAssignableFrom(implementorClass);
}
@@ -321,22 +338,28 @@ public class JaxWsImplementorInfo {
}
public Class<?> getProviderParameterType() {
- // The Provider Implementor inherits out of Provider<T>
- Class<?> c = implementorClass;
+ return doGetProviderParameterType(implementorClass);
+ }
+
+ private static Class<?> doGetProviderParameterType(Class<?> c) {
while (c != null) {
Type intfTypes[] = c.getGenericInterfaces();
for (Type t : intfTypes) {
Class<?> clazz = JAXBEncoderDecoder.getClassFromType(t);
- if (Provider.class == clazz) {
- Type paramTypes[] =
((ParameterizedType)t).getActualTypeArguments();
- return JAXBEncoderDecoder.getClassFromType(paramTypes[0]);
+ if (Provider.class.isAssignableFrom(clazz)) {
+ if (Provider.class == clazz) {
+ Type paramTypes[] =
((ParameterizedType)t).getActualTypeArguments();
+ return
JAXBEncoderDecoder.getClassFromType(paramTypes[0]);
+ } else {
+ return doGetProviderParameterType(clazz);
+ }
}
}
c = c.getSuperclass();
}
return null;
}
-
+
public String getBindingType() {
BindingType bType = implementorClass.getAnnotation(BindingType.class);
if (bType != null) {
Modified:
cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/support/JaxWsServiceFactoryBean.java
URL:
http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/support/JaxWsServiceFactoryBean.java?rev=954552&r1=954551&r2=954552&view=diff
==============================================================================
---
cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/support/JaxWsServiceFactoryBean.java
(original)
+++
cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/support/JaxWsServiceFactoryBean.java
Mon Jun 14 16:49:43 2010
@@ -41,6 +41,7 @@ import javax.xml.ws.Action;
import javax.xml.ws.AsyncHandler;
import javax.xml.ws.BindingType;
import javax.xml.ws.FaultAction;
+import javax.xml.ws.Provider;
import javax.xml.ws.Service;
import javax.xml.ws.WebFault;
import javax.xml.ws.WebServiceFeature;
@@ -269,10 +270,12 @@ public class JaxWsServiceFactoryBean ext
}
protected void initializeWSDLOperationsForProvider() {
- Type[] genericInterfaces = getServiceClass().getGenericInterfaces();
- ParameterizedType pt = (ParameterizedType)genericInterfaces[0];
- Class c = (Class)pt.getActualTypeArguments()[0];
-
+ Class c = getProviderParameterType(getServiceClass());
+ if (c == null) {
+ throw new ServiceConstructionException(getServiceClass().getName()
+ "is not a valid Provider",
+ LOG);
+ }
+
if (getEndpointInfo() == null
&& isFromWsdl()) {
//most likely, they specified a WSDL, but for some reason
@@ -367,6 +370,24 @@ public class JaxWsServiceFactoryBean ext
}
+ protected Class<?> getProviderParameterType(Class<?> cls) {
+ if (cls == null) {
+ return null;
+ }
+ Type[] genericInterfaces = cls.getGenericInterfaces();
+ for (Type type : genericInterfaces) {
+ if (type instanceof ParameterizedType) {
+ Class<?> rawCls =
(Class<?>)((ParameterizedType)type).getRawType();
+ if (Provider.class == rawCls) {
+ return
(Class<?>)((ParameterizedType)type).getActualTypeArguments()[0];
+ }
+ } else if (type instanceof Class &&
Provider.class.isAssignableFrom((Class)type)) {
+ return getProviderParameterType((Class)type);
+ }
+ }
+ return getProviderParameterType(cls.getSuperclass());
+ }
+
void initializeWrapping(OperationInfo o, Method selected) {
Class responseWrapper = getResponseWrapper(selected);
if (responseWrapper != null) {
Added:
cxf/trunk/systests/jaxws/src/test/java/org/apache/cxf/systest/provider/AbstractSourcePayloadProvider.java
URL:
http://svn.apache.org/viewvc/cxf/trunk/systests/jaxws/src/test/java/org/apache/cxf/systest/provider/AbstractSourcePayloadProvider.java?rev=954552&view=auto
==============================================================================
---
cxf/trunk/systests/jaxws/src/test/java/org/apache/cxf/systest/provider/AbstractSourcePayloadProvider.java
(added)
+++
cxf/trunk/systests/jaxws/src/test/java/org/apache/cxf/systest/provider/AbstractSourcePayloadProvider.java
Mon Jun 14 16:49:43 2010
@@ -0,0 +1,136 @@
+/**
+ * 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.provider;
+import java.io.InputStream;
+import java.io.StringWriter;
+import java.io.Writer;
+
+import javax.annotation.Resource;
+import javax.jws.HandlerChain;
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLStreamReader;
+import javax.xml.transform.OutputKeys;
+import javax.xml.transform.Source;
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerException;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.dom.DOMSource;
+import javax.xml.transform.sax.SAXSource;
+import javax.xml.transform.stream.StreamResult;
+import javax.xml.transform.stream.StreamSource;
+import javax.xml.ws.ServiceMode;
+import javax.xml.ws.WebServiceContext;
+import javax.xml.ws.WebServiceProvider;
+import javax.xml.ws.handler.MessageContext;
+
+import org.xml.sax.InputSource;
+import org.xml.sax.XMLReader;
+import org.xml.sax.helpers.XMLReaderFactory;
+
+import org.apache.cxf.helpers.XMLUtils;
+import org.apache.cxf.staxutils.StaxSource;
+import org.apache.cxf.staxutils.StaxUtils;
+
+//The following wsdl file is used.
+//wsdlLocation =
"/trunk/testutils/src/main/resources/wsdl/hello_world_rpc_lit.wsdl"
+...@webserviceprovider(portName = "SoapPortProviderRPCLit3", serviceName =
"SOAPServiceProviderRPCLit",
+ targetNamespace = "http://apache.org/hello_world_rpclit",
+ wsdlLocation = "/wsdl/hello_world_rpc_lit.wsdl")
+...@servicemode (value = javax.xml.ws.Service.Mode.PAYLOAD)
+...@handlerchain(file = "./handlers_invocation.xml", name = "TestHandlerChain")
+public abstract class AbstractSourcePayloadProvider implements SourceProvider {
+ boolean doneStax;
+ @Resource
+ WebServiceContext ctx;
+
+ public AbstractSourcePayloadProvider() {
+ }
+
+
+ public Source invoke(Source request) {
+ QName qn =
(QName)ctx.getMessageContext().get(MessageContext.WSDL_OPERATION);
+ if (qn == null) {
+ throw new RuntimeException("No Operation Name");
+ }
+
+ try {
+ System.out.println(request.getClass().getName());
+ String input = getSourceAsString(request);
+ System.out.println(input);
+
+ if (input.indexOf("ServerLogicalHandler") >= 0) {
+ return map(request.getClass());
+ }
+
+ } catch (Exception e) {
+ System.out.println("Received an exception while parsing the
source");
+ e.printStackTrace();
+ }
+ return null;
+ }
+
+ private Source map(Class<? extends Source> class1)
+ throws Exception {
+
+ InputStream greetMeInputStream = getClass()
+ .getResourceAsStream("resources/GreetMeRpcLiteralRespBody.xml");
+ if (DOMSource.class.equals(class1)) {
+ return new DOMSource(XMLUtils.parse(greetMeInputStream));
+ } else if (StaxSource.class.equals(class1)) {
+ if (doneStax) {
+ XMLReader reader = XMLReaderFactory.createXMLReader();
+ return new SAXSource(reader, new
InputSource(greetMeInputStream));
+ } else {
+ doneStax = true;
+ return new
StaxSource(StaxUtils.createXMLStreamReader(greetMeInputStream));
+ }
+ } else if (StreamSource.class.equals(class1)) {
+ StreamSource source = new StreamSource();
+ source.setInputStream(greetMeInputStream);
+ return source;
+ }
+ //java 6 javax.xml.transform.stax.StAXSource
+ XMLStreamReader reader =
StaxUtils.createXMLStreamReader(greetMeInputStream);
+ return
class1.getConstructor(XMLStreamReader.class).newInstance(reader);
+ }
+
+ public static String getSourceAsString(Source s) throws Exception {
+ try {
+ Transformer transformer =
TransformerFactory.newInstance().newTransformer();
+ transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION,
"yes");
+ transformer.setOutputProperty(OutputKeys.METHOD, "xml");
+ Writer out = new StringWriter();
+ StreamResult streamResult = new StreamResult();
+ streamResult.setWriter(out);
+ transformer.transform(s, streamResult);
+ return streamResult.getWriter().toString();
+
+ } catch (TransformerException te) {
+ if
("javax.xml.transform.stax.StAXSource".equals(s.getClass().getName())) {
+ //on java6, we will get this class if "stax" is configured
+ //for the preferred type. However, older xalans don't know
about it
+ //we'll manually do it
+ XMLStreamReader r =
(XMLStreamReader)s.getClass().getMethod("getXMLStreamReader").invoke(s);
+ return
XMLUtils.toString(StaxUtils.read(r).getDocumentElement());
+ }
+ throw te;
+ }
+ }
+}
Propchange:
cxf/trunk/systests/jaxws/src/test/java/org/apache/cxf/systest/provider/AbstractSourcePayloadProvider.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
cxf/trunk/systests/jaxws/src/test/java/org/apache/cxf/systest/provider/AbstractSourcePayloadProvider.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Modified:
cxf/trunk/systests/jaxws/src/test/java/org/apache/cxf/systest/provider/HWSourcePayloadProvider.java
URL:
http://svn.apache.org/viewvc/cxf/trunk/systests/jaxws/src/test/java/org/apache/cxf/systest/provider/HWSourcePayloadProvider.java?rev=954552&r1=954551&r2=954552&view=diff
==============================================================================
---
cxf/trunk/systests/jaxws/src/test/java/org/apache/cxf/systest/provider/HWSourcePayloadProvider.java
(original)
+++
cxf/trunk/systests/jaxws/src/test/java/org/apache/cxf/systest/provider/HWSourcePayloadProvider.java
Mon Jun 14 16:49:43 2010
@@ -18,120 +18,13 @@
*/
package org.apache.cxf.systest.provider;
-import java.io.InputStream;
-import java.io.StringWriter;
-import java.io.Writer;
-import javax.annotation.Resource;
-import javax.jws.HandlerChain;
-import javax.xml.namespace.QName;
-import javax.xml.stream.XMLStreamReader;
-import javax.xml.transform.OutputKeys;
-import javax.xml.transform.Source;
-import javax.xml.transform.Transformer;
-import javax.xml.transform.TransformerException;
-import javax.xml.transform.TransformerFactory;
-import javax.xml.transform.dom.DOMSource;
-import javax.xml.transform.sax.SAXSource;
-import javax.xml.transform.stream.StreamResult;
-import javax.xml.transform.stream.StreamSource;
-import javax.xml.ws.Provider;
-import javax.xml.ws.ServiceMode;
-import javax.xml.ws.WebServiceContext;
-import javax.xml.ws.WebServiceProvider;
-import javax.xml.ws.handler.MessageContext;
-
-import org.xml.sax.InputSource;
-import org.xml.sax.XMLReader;
-import org.xml.sax.helpers.XMLReaderFactory;
-
-import org.apache.cxf.helpers.XMLUtils;
-import org.apache.cxf.staxutils.StaxSource;
-import org.apache.cxf.staxutils.StaxUtils;
-
-//The following wsdl file is used.
-//wsdlLocation =
"/trunk/testutils/src/main/resources/wsdl/hello_world_rpc_lit.wsdl"
-...@webserviceprovider(portName = "SoapPortProviderRPCLit3", serviceName =
"SOAPServiceProviderRPCLit",
- targetNamespace = "http://apache.org/hello_world_rpclit",
- wsdlLocation = "/wsdl/hello_world_rpc_lit.wsdl")
-...@servicemode (value = javax.xml.ws.Service.Mode.PAYLOAD)
-...@handlerchain(file = "./handlers_invocation.xml", name = "TestHandlerChain")
-public class HWSourcePayloadProvider implements Provider<Source> {
- boolean doneStax;
- @Resource
- WebServiceContext ctx;
-
- public HWSourcePayloadProvider() {
-
+public class HWSourcePayloadProvider extends AbstractSourcePayloadProvider
+ implements Comparable<HWSourcePayloadProvider> {
+
+ @Override
+ public int compareTo(HWSourcePayloadProvider p) {
+ return p == this ? 0 : -1;
}
- public Source invoke(Source request) {
- QName qn =
(QName)ctx.getMessageContext().get(MessageContext.WSDL_OPERATION);
- if (qn == null) {
- throw new RuntimeException("No Operation Name");
- }
-
- try {
- System.out.println(request.getClass().getName());
- String input = getSourceAsString(request);
- System.out.println(input);
-
- if (input.indexOf("ServerLogicalHandler") >= 0) {
- return map(request.getClass());
- }
-
- } catch (Exception e) {
- System.out.println("Received an exception while parsing the
source");
- e.printStackTrace();
- }
- return null;
- }
-
- private Source map(Class<? extends Source> class1)
- throws Exception {
-
- InputStream greetMeInputStream = getClass()
- .getResourceAsStream("resources/GreetMeRpcLiteralRespBody.xml");
- if (DOMSource.class.equals(class1)) {
- return new DOMSource(XMLUtils.parse(greetMeInputStream));
- } else if (StaxSource.class.equals(class1)) {
- if (doneStax) {
- XMLReader reader = XMLReaderFactory.createXMLReader();
- return new SAXSource(reader, new
InputSource(greetMeInputStream));
- } else {
- doneStax = true;
- return new
StaxSource(StaxUtils.createXMLStreamReader(greetMeInputStream));
- }
- } else if (StreamSource.class.equals(class1)) {
- StreamSource source = new StreamSource();
- source.setInputStream(greetMeInputStream);
- return source;
- }
- //java 6 javax.xml.transform.stax.StAXSource
- XMLStreamReader reader =
StaxUtils.createXMLStreamReader(greetMeInputStream);
- return
class1.getConstructor(XMLStreamReader.class).newInstance(reader);
- }
-
- public static String getSourceAsString(Source s) throws Exception {
- try {
- Transformer transformer =
TransformerFactory.newInstance().newTransformer();
- transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION,
"yes");
- transformer.setOutputProperty(OutputKeys.METHOD, "xml");
- Writer out = new StringWriter();
- StreamResult streamResult = new StreamResult();
- streamResult.setWriter(out);
- transformer.transform(s, streamResult);
- return streamResult.getWriter().toString();
-
- } catch (TransformerException te) {
- if
("javax.xml.transform.stax.StAXSource".equals(s.getClass().getName())) {
- //on java6, we will get this class if "stax" is configured
- //for the preferred type. However, older xalans don't know
about it
- //we'll manually do it
- XMLStreamReader r =
(XMLStreamReader)s.getClass().getMethod("getXMLStreamReader").invoke(s);
- return
XMLUtils.toString(StaxUtils.read(r).getDocumentElement());
- }
- throw te;
- }
- }
}
Added:
cxf/trunk/systests/jaxws/src/test/java/org/apache/cxf/systest/provider/SourceProvider.java
URL:
http://svn.apache.org/viewvc/cxf/trunk/systests/jaxws/src/test/java/org/apache/cxf/systest/provider/SourceProvider.java?rev=954552&view=auto
==============================================================================
---
cxf/trunk/systests/jaxws/src/test/java/org/apache/cxf/systest/provider/SourceProvider.java
(added)
+++
cxf/trunk/systests/jaxws/src/test/java/org/apache/cxf/systest/provider/SourceProvider.java
Mon Jun 14 16:49:43 2010
@@ -0,0 +1,26 @@
+/**
+ * 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.provider;
+
+import javax.xml.transform.Source;
+import javax.xml.ws.Provider;
+
+public interface SourceProvider extends Provider<Source> {
+
+}
Propchange:
cxf/trunk/systests/jaxws/src/test/java/org/apache/cxf/systest/provider/SourceProvider.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
cxf/trunk/systests/jaxws/src/test/java/org/apache/cxf/systest/provider/SourceProvider.java
------------------------------------------------------------------------------
svn:keywords = Rev Date