You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ni...@apache.org on 2010/02/09 03:05:38 UTC
svn commit: r907881 - in /camel/trunk/components/camel-soap/src:
main/java/org/apache/camel/converter/soap/
main/java/org/apache/camel/converter/soap/name/
test/java/org/apache/camel/converter/soap/name/
Author: ningjiang
Date: Tue Feb 9 02:05:37 2010
New Revision: 907881
URL: http://svn.apache.org/viewvc?rev=907881&view=rev
Log:
CAMEL-2396 applied patch with thanks to Christian
Modified:
camel/trunk/components/camel-soap/src/main/java/org/apache/camel/converter/soap/SoapJaxbDataFormat.java
camel/trunk/components/camel-soap/src/main/java/org/apache/camel/converter/soap/name/ElementNameStrategy.java
camel/trunk/components/camel-soap/src/main/java/org/apache/camel/converter/soap/name/ExceptionNameStrategy.java
camel/trunk/components/camel-soap/src/main/java/org/apache/camel/converter/soap/name/QNameStrategy.java
camel/trunk/components/camel-soap/src/main/java/org/apache/camel/converter/soap/name/ServiceInterfaceStrategy.java
camel/trunk/components/camel-soap/src/main/java/org/apache/camel/converter/soap/name/TypeNameStrategy.java
camel/trunk/components/camel-soap/src/test/java/org/apache/camel/converter/soap/name/ExceptionNameStrategyTest.java
camel/trunk/components/camel-soap/src/test/java/org/apache/camel/converter/soap/name/QNameStrategyTest.java
camel/trunk/components/camel-soap/src/test/java/org/apache/camel/converter/soap/name/ServiceInterfaceStrategyTest.java
camel/trunk/components/camel-soap/src/test/java/org/apache/camel/converter/soap/name/TypeNameStrategyTest.java
Modified: camel/trunk/components/camel-soap/src/main/java/org/apache/camel/converter/soap/SoapJaxbDataFormat.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-soap/src/main/java/org/apache/camel/converter/soap/SoapJaxbDataFormat.java?rev=907881&r1=907880&r2=907881&view=diff
==============================================================================
--- camel/trunk/components/camel-soap/src/main/java/org/apache/camel/converter/soap/SoapJaxbDataFormat.java (original)
+++ camel/trunk/components/camel-soap/src/main/java/org/apache/camel/converter/soap/SoapJaxbDataFormat.java Tue Feb 9 02:05:37 2010
@@ -34,7 +34,6 @@
import org.apache.camel.converter.soap.name.ElementNameStrategy;
import org.apache.camel.converter.soap.name.ExceptionNameStrategy;
import org.apache.camel.converter.soap.name.TypeNameStrategy;
-import org.apache.camel.spi.ClassResolver;
import org.xmlsoap.schemas.soap.envelope.Body;
import org.xmlsoap.schemas.soap.envelope.Detail;
import org.xmlsoap.schemas.soap.envelope.Envelope;
@@ -96,7 +95,6 @@
String soapAction = (String) exchange.getProperty(Exchange.SOAP_ACTION);
Body body = new Body();
- ClassResolver classResolver = exchange.getContext().getClassResolver();
Throwable exception = exchange.getProperty(Exchange.EXCEPTION_CAUGHT, Throwable.class);
if (exception == null) {
@@ -104,9 +102,9 @@
}
final JAXBElement<?> content;
if (exception != null) {
- content = createFaultFromException(exception, soapAction, classResolver);
+ content = createFaultFromException(exception, soapAction);
} else {
- content = createBodyContentFromObject(inputObject, soapAction, classResolver);
+ content = createBodyContentFromObject(inputObject, soapAction);
}
body.getAny().add(content);
Envelope envelope = new Envelope();
@@ -128,8 +126,7 @@
* @return JAXBElement for the body content
*/
@SuppressWarnings("unchecked")
- private JAXBElement<?> createBodyContentFromObject(final Object inputObject, String soapAction,
- ClassResolver classResolver) {
+ private JAXBElement<?> createBodyContentFromObject(final Object inputObject, String soapAction) {
Object graph;
if (inputObject instanceof BeanInvocation) {
BeanInvocation bi = (BeanInvocation) inputObject;
@@ -141,7 +138,7 @@
} else {
graph = inputObject;
}
- QName name = elementNameStrategy.findQNameForSoapActionOrType(soapAction, graph.getClass(), classResolver);
+ QName name = elementNameStrategy.findQNameForSoapActionOrType(soapAction, graph.getClass());
return new JAXBElement(name, graph.getClass(), graph);
}
@@ -152,14 +149,11 @@
*
* @param exception
* @param soapAction
- * @param classResolver
* @return SOAP fault from given Throwable
*/
@SuppressWarnings("unchecked")
- private JAXBElement<Fault> createFaultFromException(final Throwable exception, String soapAction,
- ClassResolver classResolver) {
- QName name = new ExceptionNameStrategy().findQNameForSoapActionOrType(soapAction, exception.getClass(),
- classResolver);
+ private JAXBElement<Fault> createFaultFromException(final Throwable exception, String soapAction) {
+ QName name = new ExceptionNameStrategy().findQNameForSoapActionOrType(soapAction, exception.getClass());
Object faultObject = null;
try {
Method method = exception.getClass().getMethod("getFaultInfo");
Modified: camel/trunk/components/camel-soap/src/main/java/org/apache/camel/converter/soap/name/ElementNameStrategy.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-soap/src/main/java/org/apache/camel/converter/soap/name/ElementNameStrategy.java?rev=907881&r1=907880&r2=907881&view=diff
==============================================================================
--- camel/trunk/components/camel-soap/src/main/java/org/apache/camel/converter/soap/name/ElementNameStrategy.java (original)
+++ camel/trunk/components/camel-soap/src/main/java/org/apache/camel/converter/soap/name/ElementNameStrategy.java Tue Feb 9 02:05:37 2010
@@ -18,8 +18,6 @@
import javax.xml.namespace.QName;
-import org.apache.camel.spi.ClassResolver;
-
/**
* Strategy interface for determining the element name for a SOAP body or fault
*/
@@ -30,8 +28,7 @@
*
* @param soapAction
* @param type
- * @param classResolver
* @return resolved element name
*/
- QName findQNameForSoapActionOrType(String soapAction, Class<?> type, ClassResolver classResolver);
+ QName findQNameForSoapActionOrType(String soapAction, Class<?> type);
}
Modified: camel/trunk/components/camel-soap/src/main/java/org/apache/camel/converter/soap/name/ExceptionNameStrategy.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-soap/src/main/java/org/apache/camel/converter/soap/name/ExceptionNameStrategy.java?rev=907881&r1=907880&r2=907881&view=diff
==============================================================================
--- camel/trunk/components/camel-soap/src/main/java/org/apache/camel/converter/soap/name/ExceptionNameStrategy.java (original)
+++ camel/trunk/components/camel-soap/src/main/java/org/apache/camel/converter/soap/name/ExceptionNameStrategy.java Tue Feb 9 02:05:37 2010
@@ -19,8 +19,6 @@
import javax.xml.namespace.QName;
import javax.xml.ws.WebFault;
-import org.apache.camel.spi.ClassResolver;
-
/**
* Determine element name for an exception
*/
@@ -29,7 +27,7 @@
/**
* @return QName from exception class by evaluating the WebFault annotataion
*/
- public QName findQNameForSoapActionOrType(String soapAction, Class<?> type, ClassResolver classResolver) {
+ public QName findQNameForSoapActionOrType(String soapAction, Class<?> type) {
WebFault webFault = type.getAnnotation(WebFault.class);
if (webFault == null || webFault.targetNamespace() == null) {
throw new RuntimeException("The type " + type.getName() + " needs to have an WebFault annotation with name and targetNamespace");
Modified: camel/trunk/components/camel-soap/src/main/java/org/apache/camel/converter/soap/name/QNameStrategy.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-soap/src/main/java/org/apache/camel/converter/soap/name/QNameStrategy.java?rev=907881&r1=907880&r2=907881&view=diff
==============================================================================
--- camel/trunk/components/camel-soap/src/main/java/org/apache/camel/converter/soap/name/QNameStrategy.java (original)
+++ camel/trunk/components/camel-soap/src/main/java/org/apache/camel/converter/soap/name/QNameStrategy.java Tue Feb 9 02:05:37 2010
@@ -18,8 +18,6 @@
import javax.xml.namespace.QName;
-import org.apache.camel.spi.ClassResolver;
-
/**
* Simply ElementNameStrategy that returns one preset QName
*/
@@ -38,7 +36,7 @@
/**
* @return preset element name
*/
- public QName findQNameForSoapActionOrType(String soapAction, Class<?> type, ClassResolver classResolver) {
+ public QName findQNameForSoapActionOrType(String soapAction, Class<?> type) {
return elementName;
}
Modified: camel/trunk/components/camel-soap/src/main/java/org/apache/camel/converter/soap/name/ServiceInterfaceStrategy.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-soap/src/main/java/org/apache/camel/converter/soap/name/ServiceInterfaceStrategy.java?rev=907881&r1=907880&r2=907881&view=diff
==============================================================================
--- camel/trunk/components/camel-soap/src/main/java/org/apache/camel/converter/soap/name/ServiceInterfaceStrategy.java (original)
+++ camel/trunk/components/camel-soap/src/main/java/org/apache/camel/converter/soap/name/ServiceInterfaceStrategy.java Tue Feb 9 02:05:37 2010
@@ -29,7 +29,6 @@
import javax.xml.ws.ResponseWrapper;
import org.apache.camel.RuntimeCamelException;
-import org.apache.camel.spi.ClassResolver;
/**
* Offers a finder for a webservice interface to determine the QName of a
@@ -128,7 +127,7 @@
* @return matching QName throws RuntimeException if no matching QName was
* found
*/
- public QName findQNameForSoapActionOrType(String soapAction, Class<?> type, ClassResolver classResolver) {
+ public QName findQNameForSoapActionOrType(String soapAction, Class<?> type) {
MethodInfo info = soapActionToMethodInfo.get(soapAction);
if (info != null) {
if (isClient) {
@@ -145,7 +144,7 @@
}
if (qName == null) {
try {
- qName = fallBackStrategy.findQNameForSoapActionOrType(soapAction, type, classResolver);
+ qName = fallBackStrategy.findQNameForSoapActionOrType(soapAction, type);
} catch (Exception e) {
String msg = "No method found that matches the given SoapAction " + soapAction + " or that has an "
+ (isClient ? "input" : "output") + " of type " + type.getName();
Modified: camel/trunk/components/camel-soap/src/main/java/org/apache/camel/converter/soap/name/TypeNameStrategy.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-soap/src/main/java/org/apache/camel/converter/soap/name/TypeNameStrategy.java?rev=907881&r1=907880&r2=907881&view=diff
==============================================================================
--- camel/trunk/components/camel-soap/src/main/java/org/apache/camel/converter/soap/name/TypeNameStrategy.java (original)
+++ camel/trunk/components/camel-soap/src/main/java/org/apache/camel/converter/soap/name/TypeNameStrategy.java Tue Feb 9 02:05:37 2010
@@ -20,8 +20,6 @@
import javax.xml.bind.annotation.XmlType;
import javax.xml.namespace.QName;
-import org.apache.camel.spi.ClassResolver;
-
/**
* Strategy to determine the marshalled element name by looking at the annotations of the
* class to be marshalled
@@ -32,19 +30,16 @@
* @return determine element name by using the XmlType.name() of the type to be
* marshalled and the XmlSchema.namespace() of the package-info
*/
- public QName findQNameForSoapActionOrType(String soapAction, Class<?> type, ClassResolver classResolver) {
+ public QName findQNameForSoapActionOrType(String soapAction, Class<?> type) {
XmlType xmlType = type.getAnnotation(XmlType.class);
if (xmlType == null || xmlType.name() == null) {
throw new RuntimeException("The type " + type.getName() + " needs to have an XmlType annotation with name");
}
String nameSpace = xmlType.namespace();
if ("##default".equals(nameSpace)) {
- try {
- Class<?> packageInfo = classResolver.resolveMandatoryClass(type.getPackage().getName() + ".package-info");
- XmlSchema xmlSchema = packageInfo.getAnnotation(XmlSchema.class);
+ XmlSchema xmlSchema = type.getPackage().getAnnotation(XmlSchema.class);
+ if (xmlSchema != null) {
nameSpace = xmlSchema.namespace();
- } catch (ClassNotFoundException e) {
- throw new RuntimeException("package info not found for package " + type.getPackage().getName(), e);
}
}
return new QName(nameSpace, xmlType.name());
Modified: camel/trunk/components/camel-soap/src/test/java/org/apache/camel/converter/soap/name/ExceptionNameStrategyTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-soap/src/test/java/org/apache/camel/converter/soap/name/ExceptionNameStrategyTest.java?rev=907881&r1=907880&r2=907881&view=diff
==============================================================================
--- camel/trunk/components/camel-soap/src/test/java/org/apache/camel/converter/soap/name/ExceptionNameStrategyTest.java (original)
+++ camel/trunk/components/camel-soap/src/test/java/org/apache/camel/converter/soap/name/ExceptionNameStrategyTest.java Tue Feb 9 02:05:37 2010
@@ -22,7 +22,6 @@
import com.example.customerservice.NoSuchCustomerException;
-import org.apache.camel.impl.DefaultClassResolver;
import org.junit.Test;
public class ExceptionNameStrategyTest {
@@ -30,15 +29,12 @@
@Test
public void testServiceInterfaceStrategyWithServer() {
ExceptionNameStrategy strategy = new ExceptionNameStrategy();
- DefaultClassResolver resolver = new DefaultClassResolver();
- QName elName = strategy.findQNameForSoapActionOrType("",
- NoSuchCustomerException.class, resolver);
- Assert.assertEquals("http://customerservice.example.com/", elName
- .getNamespaceURI());
+ QName elName = strategy.findQNameForSoapActionOrType("", NoSuchCustomerException.class);
+ Assert.assertEquals("http://customerservice.example.com/", elName.getNamespaceURI());
Assert.assertEquals("NoSuchCustomer", elName.getLocalPart());
-
+
try {
- elName = strategy.findQNameForSoapActionOrType("", Class.class, resolver);
+ elName = strategy.findQNameForSoapActionOrType("", Class.class);
Assert.fail();
} catch (Exception e) {
// expected here
Modified: camel/trunk/components/camel-soap/src/test/java/org/apache/camel/converter/soap/name/QNameStrategyTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-soap/src/test/java/org/apache/camel/converter/soap/name/QNameStrategyTest.java?rev=907881&r1=907880&r2=907881&view=diff
==============================================================================
--- camel/trunk/components/camel-soap/src/test/java/org/apache/camel/converter/soap/name/QNameStrategyTest.java (original)
+++ camel/trunk/components/camel-soap/src/test/java/org/apache/camel/converter/soap/name/QNameStrategyTest.java Tue Feb 9 02:05:37 2010
@@ -22,8 +22,6 @@
import com.example.customerservice.GetCustomersByName;
-import org.apache.camel.impl.DefaultClassResolver;
-import org.apache.camel.spi.ClassResolver;
import org.junit.Test;
/**
@@ -39,9 +37,8 @@
public void testQName() {
QName elementName = new QName("http://my.name.org", "myElement");
QNameStrategy strategy = new QNameStrategy(elementName);
- ClassResolver resolver = new DefaultClassResolver();
- QName actualElementName = strategy.findQNameForSoapActionOrType(null, GetCustomersByName.class, resolver);
+ QName actualElementName = strategy.findQNameForSoapActionOrType(null, GetCustomersByName.class);
Assert.assertEquals(elementName, actualElementName);
}
}
Modified: camel/trunk/components/camel-soap/src/test/java/org/apache/camel/converter/soap/name/ServiceInterfaceStrategyTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-soap/src/test/java/org/apache/camel/converter/soap/name/ServiceInterfaceStrategyTest.java?rev=907881&r1=907880&r2=907881&view=diff
==============================================================================
--- camel/trunk/components/camel-soap/src/test/java/org/apache/camel/converter/soap/name/ServiceInterfaceStrategyTest.java (original)
+++ camel/trunk/components/camel-soap/src/test/java/org/apache/camel/converter/soap/name/ServiceInterfaceStrategyTest.java Tue Feb 9 02:05:37 2010
@@ -25,7 +25,6 @@
import com.example.customerservice.GetCustomersByNameResponse;
import org.apache.camel.RuntimeCamelException;
-import org.apache.camel.impl.DefaultClassResolver;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.junit.Test;
@@ -36,17 +35,16 @@
@Test
public void testServiceInterfaceStrategyWithClient() {
ServiceInterfaceStrategy strategy = new ServiceInterfaceStrategy(CustomerService.class, true);
- DefaultClassResolver resolver = new DefaultClassResolver();
- QName elName = strategy.findQNameForSoapActionOrType("", GetCustomersByName.class, resolver);
+ QName elName = strategy.findQNameForSoapActionOrType("", GetCustomersByName.class);
Assert.assertEquals("http://customerservice.example.com/", elName.getNamespaceURI());
Assert.assertEquals("getCustomersByName", elName.getLocalPart());
- QName elName2 = strategy.findQNameForSoapActionOrType("getCustomersByName", GetCustomersByName.class, resolver);
+ QName elName2 = strategy.findQNameForSoapActionOrType("getCustomersByName", GetCustomersByName.class);
Assert.assertEquals("http://customerservice.example.com/", elName2.getNamespaceURI());
Assert.assertEquals("getCustomersByName", elName2.getLocalPart());
try {
- elName = strategy.findQNameForSoapActionOrType("test", Class.class, resolver);
+ elName = strategy.findQNameForSoapActionOrType("test", Class.class);
Assert.fail();
} catch (RuntimeCamelException e) {
LOG.debug("Caught expected message: " + e.getMessage());
@@ -56,17 +54,16 @@
@Test
public void testServiceInterfaceStrategyWithServer() {
ServiceInterfaceStrategy strategy = new ServiceInterfaceStrategy(CustomerService.class, false);
- DefaultClassResolver resolver = new DefaultClassResolver();
- QName elName = strategy.findQNameForSoapActionOrType("", GetCustomersByNameResponse.class, resolver);
+ QName elName = strategy.findQNameForSoapActionOrType("", GetCustomersByNameResponse.class);
Assert.assertEquals("http://customerservice.example.com/", elName.getNamespaceURI());
Assert.assertEquals("getCustomersByNameResponse", elName.getLocalPart());
- QName elName2 = strategy.findQNameForSoapActionOrType("getCustomersByName", GetCustomersByName.class, resolver);
+ QName elName2 = strategy.findQNameForSoapActionOrType("getCustomersByName", GetCustomersByName.class);
Assert.assertEquals("http://customerservice.example.com/", elName2.getNamespaceURI());
Assert.assertEquals("getCustomersByNameResponse", elName2.getLocalPart());
try {
- elName = strategy.findQNameForSoapActionOrType("test", Class.class, resolver);
+ elName = strategy.findQNameForSoapActionOrType("test", Class.class);
Assert.fail();
} catch (RuntimeCamelException e) {
LOG.debug("Caught expected message: " + e.getMessage());
@@ -76,13 +73,12 @@
@Test
public void testServiceInterfaceStrategyWithRequestWrapperAndClient() {
ServiceInterfaceStrategy strategy = new ServiceInterfaceStrategy(com.example.customerservice2.CustomerService.class, true);
- DefaultClassResolver resolver = new DefaultClassResolver();
- QName elName = strategy.findQNameForSoapActionOrType("", com.example.customerservice2.GetCustomersByName.class, resolver);
+ QName elName = strategy.findQNameForSoapActionOrType("", com.example.customerservice2.GetCustomersByName.class);
Assert.assertEquals("http://customerservice2.example.com/", elName.getNamespaceURI());
Assert.assertEquals("getCustomersByName", elName.getLocalPart());
try {
- elName = strategy.findQNameForSoapActionOrType("test", Class.class, resolver);
+ elName = strategy.findQNameForSoapActionOrType("test", Class.class);
Assert.fail();
} catch (RuntimeCamelException e) {
LOG.debug("Caught expected message: " + e.getMessage());
Modified: camel/trunk/components/camel-soap/src/test/java/org/apache/camel/converter/soap/name/TypeNameStrategyTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-soap/src/test/java/org/apache/camel/converter/soap/name/TypeNameStrategyTest.java?rev=907881&r1=907880&r2=907881&view=diff
==============================================================================
--- camel/trunk/components/camel-soap/src/test/java/org/apache/camel/converter/soap/name/TypeNameStrategyTest.java (original)
+++ camel/trunk/components/camel-soap/src/test/java/org/apache/camel/converter/soap/name/TypeNameStrategyTest.java Tue Feb 9 02:05:37 2010
@@ -22,8 +22,6 @@
import com.example.customerservice.GetCustomersByName;
-import org.apache.camel.impl.DefaultClassResolver;
-import org.apache.camel.spi.ClassResolver;
import org.junit.Test;
public class TypeNameStrategyTest {
@@ -31,36 +29,31 @@
@Test
public void testTypeNameStrategy() {
TypeNameStrategy strategy = new TypeNameStrategy();
- ClassResolver resolver = new DefaultClassResolver();
- QName name = strategy.findQNameForSoapActionOrType("", GetCustomersByName.class, resolver);
+ QName name = strategy.findQNameForSoapActionOrType("", GetCustomersByName.class);
Assert.assertEquals("http://customerservice.example.com/", name.getNamespaceURI());
Assert.assertEquals("getCustomersByName", name.getLocalPart());
}
-
+
@Test
public void testNoAnnotation() {
TypeNameStrategy strategy = new TypeNameStrategy();
- ClassResolver resolver = new DefaultClassResolver();
try {
- strategy.findQNameForSoapActionOrType("", String.class, resolver);
+ strategy.findQNameForSoapActionOrType("", String.class);
Assert.fail();
} catch (RuntimeException e) {
// Expected here
}
}
-
+
@Test
public void testNoPackageInfo() {
TypeNameStrategy strategy = new TypeNameStrategy();
- ClassResolver resolver = new DefaultClassResolver();
- try {
- strategy.findQNameForSoapActionOrType("", AnnotatedClassWithoutNamespace.class, resolver);
- Assert.fail();
- } catch (RuntimeException e) {
- // Expected here as there is no package info and no namespace on class
- }
- QName name = strategy.findQNameForSoapActionOrType("", AnnotatedClassWithNamespace.class, resolver);
+ QName name = strategy.findQNameForSoapActionOrType("", AnnotatedClassWithoutNamespace.class);
Assert.assertEquals("test", name.getLocalPart());
- Assert.assertEquals("http://mynamespace", name.getNamespaceURI());
+ Assert.assertEquals("##default", name.getNamespaceURI());
+
+ QName name2 = strategy.findQNameForSoapActionOrType("", AnnotatedClassWithNamespace.class);
+ Assert.assertEquals("test", name2.getLocalPart());
+ Assert.assertEquals("http://mynamespace", name2.getNamespaceURI());
}
}