summaryrefslogtreecommitdiffstats
path: root/sca-java-2.x/trunk/modules/interface-java-jaxws/src/main/java/org
diff options
context:
space:
mode:
authorslaws <slaws@13f79535-47bb-0310-9956-ffa450edef68>2012-01-19 14:33:20 +0000
committerslaws <slaws@13f79535-47bb-0310-9956-ffa450edef68>2012-01-19 14:33:20 +0000
commit8624fc0322f368b2a59a61597e7f50e16e76ed94 (patch)
treedc9bec1760d9e8f1c6dad63acfea07de65092dee /sca-java-2.x/trunk/modules/interface-java-jaxws/src/main/java/org
parent0a86a47979a0bf3eeacb75d45d56b5abe3150bbf (diff)
TUSCANY-3283 - these are similar changes to those made in 1.x to correct WSDL gen in various areas including, generating unannotated types into the service interface namespace, making wrapper parameters generally non-nillable, using JAXB to generate wrapper XSD (which fixes other failures where our code doesn't support various JAXB annotations), correcting the namespace of generated exceptions and the way that the generated classes are cached. Fixing the WSDL requires other fixes, for example, a new databinding to force ServiceReference to map to anyType (so that we don't try and process these interfaces with JAXB) and a fix to correct the order of response holders. T
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@1233402 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'sca-java-2.x/trunk/modules/interface-java-jaxws/src/main/java/org')
-rw-r--r--sca-java-2.x/trunk/modules/interface-java-jaxws/src/main/java/org/apache/tuscany/sca/interfacedef/java/jaxws/BaseBeanGenerator.java12
-rw-r--r--sca-java-2.x/trunk/modules/interface-java-jaxws/src/main/java/org/apache/tuscany/sca/interfacedef/java/jaxws/FaultBeanGenerator.java72
-rw-r--r--sca-java-2.x/trunk/modules/interface-java-jaxws/src/main/java/org/apache/tuscany/sca/interfacedef/java/jaxws/GeneratedDataTypeImpl.java13
-rw-r--r--sca-java-2.x/trunk/modules/interface-java-jaxws/src/main/java/org/apache/tuscany/sca/interfacedef/java/jaxws/JAXWSFaultExceptionMapper.java5
-rw-r--r--sca-java-2.x/trunk/modules/interface-java-jaxws/src/main/java/org/apache/tuscany/sca/interfacedef/java/jaxws/WrapperBeanGenerator.java4
5 files changed, 77 insertions, 29 deletions
diff --git a/sca-java-2.x/trunk/modules/interface-java-jaxws/src/main/java/org/apache/tuscany/sca/interfacedef/java/jaxws/BaseBeanGenerator.java b/sca-java-2.x/trunk/modules/interface-java-jaxws/src/main/java/org/apache/tuscany/sca/interfacedef/java/jaxws/BaseBeanGenerator.java
index 05a5dc89de..ca39ec0e62 100644
--- a/sca-java-2.x/trunk/modules/interface-java-jaxws/src/main/java/org/apache/tuscany/sca/interfacedef/java/jaxws/BaseBeanGenerator.java
+++ b/sca-java-2.x/trunk/modules/interface-java-jaxws/src/main/java/org/apache/tuscany/sca/interfacedef/java/jaxws/BaseBeanGenerator.java
@@ -48,6 +48,7 @@ import org.objectweb.asm.Opcodes;
public abstract class BaseBeanGenerator implements Opcodes {
private static final Map<String, String> COLLECTION_CLASSES = new HashMap<String, String>();
+
static {
COLLECTION_CLASSES.put("Ljava/util/Collection;", "java/util/ArrayList");
COLLECTION_CLASSES.put("Ljava/util/List;", "java/util/ArrayList");
@@ -55,7 +56,11 @@ public abstract class BaseBeanGenerator implements Opcodes {
COLLECTION_CLASSES.put("Ljava/util/Queue;", "java/util/LinkedList");
}
private final static Class[] KNOWN_JAXB_ANNOTATIONS =
- {XmlAttachmentRef.class, XmlMimeType.class, XmlJavaTypeAdapter.class, XmlList.class};
+ {XmlAttachmentRef.class,
+ XmlMimeType.class,
+ XmlJavaTypeAdapter.class,
+ XmlList.class};
+
private static final Map<String, String> JAVA_KEYWORDS = new HashMap<String, String>();
static {
@@ -140,7 +145,7 @@ public abstract class BaseBeanGenerator implements Opcodes {
// Annotate the class
annotateClass(cw, name, namespace, propOrder);
- // Decalre the default constructor
+ // Declare the default constructor
declareConstructor(cw, classSignature);
if (properties != null) {
for (BeanProperty p : properties) {
@@ -228,8 +233,11 @@ public abstract class BaseBeanGenerator implements Opcodes {
av0 = fv.visitAnnotation("Ljavax/xml/bind/annotation/XmlElement;", true);
av0.visit("name", propName);
av0.visit("namespace", "");
+ // TUSCANY-3283 - force not nillable if it isn't
if (isNillable) {
av0.visit("nillable", Boolean.TRUE);
+ } else {
+ av0.visit("nillable", Boolean.FALSE);
}
// FIXME:
// av0.visit("required", Boolean.FALSE);
diff --git a/sca-java-2.x/trunk/modules/interface-java-jaxws/src/main/java/org/apache/tuscany/sca/interfacedef/java/jaxws/FaultBeanGenerator.java b/sca-java-2.x/trunk/modules/interface-java-jaxws/src/main/java/org/apache/tuscany/sca/interfacedef/java/jaxws/FaultBeanGenerator.java
index 117253cebb..2e82428f7e 100644
--- a/sca-java-2.x/trunk/modules/interface-java-jaxws/src/main/java/org/apache/tuscany/sca/interfacedef/java/jaxws/FaultBeanGenerator.java
+++ b/sca-java-2.x/trunk/modules/interface-java-jaxws/src/main/java/org/apache/tuscany/sca/interfacedef/java/jaxws/FaultBeanGenerator.java
@@ -34,6 +34,8 @@ import java.util.List;
import javax.xml.namespace.QName;
import javax.xml.ws.WebFault;
+import org.apache.tuscany.sca.interfacedef.Operation;
+import org.apache.tuscany.sca.interfacedef.java.JavaInterface;
import org.apache.tuscany.sca.interfacedef.java.impl.JavaInterfaceUtil;
import org.objectweb.asm.ClassWriter;
@@ -72,9 +74,7 @@ public class FaultBeanGenerator extends BaseBeanGenerator {
return props.toArray(new BeanProperty[0]);
}
- public byte[] generate(Class<? extends Throwable> exceptionClass) {
- String className = getFaultBeanName(exceptionClass);
-
+ public byte[] generate(Class<? extends Throwable> exceptionClass, Operation operation) {
// The reflection code here allows for toleration of older versions of ASM.
ClassWriter cw;
try {
@@ -91,35 +91,52 @@ public class FaultBeanGenerator extends BaseBeanGenerator {
}
-
-
+ // TUSCANY-3283 - all generated classes (including exception) should go in the namespace
+ // of the interface not the namespace of the originating exception.
+ // consequently we need to create a matching package name for the schema
+ QName element = getElementName(exceptionClass, operation);
+ String name = element.getLocalPart();
+ String namespace = element.getNamespaceURI();
+
+ String className = getFaultBeanName(exceptionClass, operation);
String classDescriptor = className.replace('.', '/');
String classSignature = "L" + classDescriptor + ";";
- QName element = getElementName(exceptionClass);
- String namespace = element.getNamespaceURI();
- String name = element.getLocalPart();
+
return defineClass(cw, classDescriptor, classSignature, namespace, name, getProperties(exceptionClass));
}
- public Class<?> generate(Class<? extends Throwable> exceptionClass, GeneratedClassLoader cl) {
+ public Class<?> generate(Class<? extends Throwable> exceptionClass, GeneratedClassLoader cl, Operation operation) {
synchronized (exceptionClass) {
- Class<?> faultBeanClass = generatedClasses.get(exceptionClass);
+ QName element = getElementName(exceptionClass, operation);
+ Class<?> faultBeanClass = generatedClasses.get(element);
if (faultBeanClass == null) {
- String className = getFaultBeanName(exceptionClass);
+
+ // TUSCANY-3283 - all generated classes (including exception) should go in the namespace
+ // of the interface not the namespace of the originating exception.
+ // consequently we need to create a matching package name for the schema
+ String name = element.getLocalPart();
+ String namespace = element.getNamespaceURI();
+
+ String className = getFaultBeanName(exceptionClass, operation);
String classDescriptor = className.replace('.', '/');
String classSignature = "L" + classDescriptor + ";";
- QName element = getElementName(exceptionClass);
- String namespace = element.getNamespaceURI();
- String name = element.getLocalPart();
- faultBeanClass =
- generate(classDescriptor, classSignature, namespace, name, getProperties(exceptionClass), cl);
- generatedClasses.put(exceptionClass, faultBeanClass);
+
+ faultBeanClass = generate(classDescriptor, classSignature, namespace, name, getProperties(exceptionClass), cl);
+ generatedClasses.put(element, faultBeanClass);
}
return faultBeanClass;
}
}
- private static String getFaultBeanName(Class<?> exceptionClass) {
+ private static String getFaultBeanName(Class<?> exceptionClass, Operation operation) {
+ // TUSCANY-3283 - all generated classes (including exception) should go in the namespace
+ // of the interface not the namespace of the originating exception.
+ // consequently we need to create a matching package name for the schema
+ String interfacePkg = null;
+ if (operation != null && operation.getInterface() instanceof JavaInterface){
+ interfacePkg = ((JavaInterface)operation.getInterface()).getJavaClass().getPackage().getName();
+ }
+
String faultBeanName = null;
WebFault webFault = exceptionClass.getAnnotation(WebFault.class);
if (webFault != null) {
@@ -131,7 +148,12 @@ public class FaultBeanGenerator extends BaseBeanGenerator {
String name = exceptionClass.getName();
int index = name.lastIndexOf('.');
- String pkg = name.substring(0, index);
+ String pkg = null;
+ if (interfacePkg != null){
+ pkg = interfacePkg;
+ } else {
+ pkg = name.substring(0, index);
+ }
String clsName = name.substring(index + 1);
// FIXME: [rfeng] This is a workaround to avoid "Prohibited package name: java.lang.jaxws"
@@ -142,9 +164,17 @@ public class FaultBeanGenerator extends BaseBeanGenerator {
return faultBeanName;
}
- public static QName getElementName(Class<? extends Throwable> exceptionClass) {
+ public static QName getElementName(Class<? extends Throwable> exceptionClass, Operation operation) {
WebFault webFault = exceptionClass.getAnnotation(WebFault.class);
+
+ // TUSCANY-3283 - all generated classes (including exception) should go in the namespace
+ // of the interface not the namespace of the originating exception.
+ // consequently we need to create a matching package name for the schema
String namespace = null;
+ if (operation != null && operation.getInterface() instanceof JavaInterface){
+ namespace = ((JavaInterface)operation.getInterface()).getQName().getNamespaceURI();
+ }
+
String name = null;
if (webFault != null) {
namespace = webFault.targetNamespace();
@@ -162,6 +192,6 @@ public class FaultBeanGenerator extends BaseBeanGenerator {
public static Class<?> generateFaultBeanClass(Class<? extends Throwable> exceptionClass) {
FaultBeanGenerator generator = new FaultBeanGenerator();
GeneratedClassLoader cl = new GeneratedClassLoader(exceptionClass.getClassLoader());
- return generator.generate(exceptionClass, cl);
+ return generator.generate(exceptionClass, cl, null);
}
}
diff --git a/sca-java-2.x/trunk/modules/interface-java-jaxws/src/main/java/org/apache/tuscany/sca/interfacedef/java/jaxws/GeneratedDataTypeImpl.java b/sca-java-2.x/trunk/modules/interface-java-jaxws/src/main/java/org/apache/tuscany/sca/interfacedef/java/jaxws/GeneratedDataTypeImpl.java
index c3f568ef48..2fbf374ac9 100644
--- a/sca-java-2.x/trunk/modules/interface-java-jaxws/src/main/java/org/apache/tuscany/sca/interfacedef/java/jaxws/GeneratedDataTypeImpl.java
+++ b/sca-java-2.x/trunk/modules/interface-java-jaxws/src/main/java/org/apache/tuscany/sca/interfacedef/java/jaxws/GeneratedDataTypeImpl.java
@@ -29,6 +29,8 @@ import javax.xml.namespace.QName;
import org.apache.tuscany.sca.databinding.jaxb.JAXBDataBinding;
import org.apache.tuscany.sca.databinding.jaxb.XMLAdapterExtensionPoint;
import org.apache.tuscany.sca.interfacedef.DataType;
+import org.apache.tuscany.sca.interfacedef.Operation;
+import org.apache.tuscany.sca.interfacedef.java.JavaInterface;
import org.apache.tuscany.sca.interfacedef.util.XMLType;
/**
@@ -48,16 +50,21 @@ public class GeneratedDataTypeImpl implements DataType<XMLType> {
private String wrapperName;
private boolean request;
private GeneratedClassLoader classLoader;
+ private Operation operation;
private Class<? extends Throwable> exceptionClass;
- public GeneratedDataTypeImpl(XMLAdapterExtensionPoint xmlAdapters, Class<? extends Throwable> exceptionClass, GeneratedClassLoader cl) {
+ public GeneratedDataTypeImpl(XMLAdapterExtensionPoint xmlAdapters,
+ Class<? extends Throwable> exceptionClass,
+ GeneratedClassLoader cl,
+ Operation operation) {
super();
this.exceptionClass = exceptionClass;
this.classLoader = cl;
- QName name = FaultBeanGenerator.getElementName(exceptionClass);
+ QName name = FaultBeanGenerator.getElementName(exceptionClass, operation);
this.logical = new XMLType(name, name);
this.xmlAdapters = xmlAdapters;
+ this.operation = operation;
}
public GeneratedDataTypeImpl(XMLAdapterExtensionPoint xmlAdapters,
@@ -103,7 +110,7 @@ public class GeneratedDataTypeImpl implements DataType<XMLType> {
} else if (exceptionClass != null) {
FaultBeanGenerator faultBeanGenerator = new FaultBeanGenerator();
faultBeanGenerator.setXmlAdapters(xmlAdapters);
- physical = faultBeanGenerator.generate(exceptionClass, classLoader);
+ physical = faultBeanGenerator.generate(exceptionClass, classLoader, operation);
}
}
return physical;
diff --git a/sca-java-2.x/trunk/modules/interface-java-jaxws/src/main/java/org/apache/tuscany/sca/interfacedef/java/jaxws/JAXWSFaultExceptionMapper.java b/sca-java-2.x/trunk/modules/interface-java-jaxws/src/main/java/org/apache/tuscany/sca/interfacedef/java/jaxws/JAXWSFaultExceptionMapper.java
index fcf7006f16..166f1d6b6d 100644
--- a/sca-java-2.x/trunk/modules/interface-java-jaxws/src/main/java/org/apache/tuscany/sca/interfacedef/java/jaxws/JAXWSFaultExceptionMapper.java
+++ b/sca-java-2.x/trunk/modules/interface-java-jaxws/src/main/java/org/apache/tuscany/sca/interfacedef/java/jaxws/JAXWSFaultExceptionMapper.java
@@ -290,7 +290,7 @@ public class JAXWSFaultExceptionMapper implements FaultExceptionMapper {
@SuppressWarnings("unchecked")
public boolean introspectFaultDataType(DataType<DataType> exceptionType, final Operation operation, final boolean generatingFaultBean) {
- QName faultName = null;
+
boolean result = false;
final Class<?> cls = exceptionType.getPhysical();
@@ -298,6 +298,7 @@ public class JAXWSFaultExceptionMapper implements FaultExceptionMapper {
return true;
}
DataType faultType = (DataType)exceptionType.getLogical();
+ QName faultName = ((XMLType)faultType.getLogical()).getElementName();
Class<?> faultBean = null;
final WebFault fault = cls.getAnnotation(WebFault.class);
if (fault != null) {
@@ -346,7 +347,7 @@ public class JAXWSFaultExceptionMapper implements FaultExceptionMapper {
operation == null ? t.getClassLoader() : ((JavaInterface)operation.getInterface())
.getJavaClass().getClassLoader();
GeneratedClassLoader cl = new GeneratedClassLoader(parent);
- GeneratedDataTypeImpl dt = new GeneratedDataTypeImpl(xmlAdapterExtensionPoint, t, cl);
+ GeneratedDataTypeImpl dt = new GeneratedDataTypeImpl(xmlAdapterExtensionPoint, t, cl, operation);
return dt;
} else {
return new DataTypeImpl<XMLType>(cls, new XMLType(qname, qname));
diff --git a/sca-java-2.x/trunk/modules/interface-java-jaxws/src/main/java/org/apache/tuscany/sca/interfacedef/java/jaxws/WrapperBeanGenerator.java b/sca-java-2.x/trunk/modules/interface-java-jaxws/src/main/java/org/apache/tuscany/sca/interfacedef/java/jaxws/WrapperBeanGenerator.java
index 6a664b366e..42151464a4 100644
--- a/sca-java-2.x/trunk/modules/interface-java-jaxws/src/main/java/org/apache/tuscany/sca/interfacedef/java/jaxws/WrapperBeanGenerator.java
+++ b/sca-java-2.x/trunk/modules/interface-java-jaxws/src/main/java/org/apache/tuscany/sca/interfacedef/java/jaxws/WrapperBeanGenerator.java
@@ -205,7 +205,9 @@ public class WrapperBeanGenerator extends BaseBeanGenerator {
Type genericReturnType = asyncMethod? returnType : m.getGenericReturnType();
BeanProperty prop = new BeanProperty(propNS, propName, returnType, genericReturnType, true);
prop.getJaxbAnnotaions().addAll(jaxb);
- properties.add(prop);
+ // TUSCANY-3283 - As per JAXWS spec () the "return" value should come first in the
+ // list when there are holders.
+ properties.add(0, prop);
}
wrapperClass =
generate(wrapperClassDescriptor, wrapperClassSignature, wrapperNamespace, wrapperName, properties