You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by dk...@apache.org on 2007/11/02 04:14:32 UTC
svn commit: r591208 - in /incubator/cxf/branches/2.0.x-fixes: ./
rt/core/src/main/java/org/apache/cxf/interceptor/
rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/
rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/io/
rt/frontend/simple/src/m...
Author: dkulp
Date: Thu Nov 1 20:14:31 2007
New Revision: 591208
URL: http://svn.apache.org/viewvc?rev=591208&view=rev
Log:
Merged revisions 591185 via svnmerge from
https://svn.apache.org/repos/asf/incubator/cxf/trunk
........
r591185 | dkulp | 2007-11-01 21:22:24 -0400 (Thu, 01 Nov 2007) | 2 lines
[CXF-1136] Allow JAXB databinding to map Exceptions
........
Modified:
incubator/cxf/branches/2.0.x-fixes/ (props changed)
incubator/cxf/branches/2.0.x-fixes/rt/core/src/main/java/org/apache/cxf/interceptor/ClientFaultConverter.java
incubator/cxf/branches/2.0.x-fixes/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBContextInitializer.java
incubator/cxf/branches/2.0.x-fixes/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBEncoderDecoder.java
incubator/cxf/branches/2.0.x-fixes/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBSchemaInitializer.java
incubator/cxf/branches/2.0.x-fixes/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/io/DataWriterImpl.java
incubator/cxf/branches/2.0.x-fixes/rt/frontend/simple/src/main/java/org/apache/cxf/service/factory/ReflectionServiceFactoryBean.java
incubator/cxf/branches/2.0.x-fixes/rt/ws/addr/src/main/java/org/apache/cxf/ws/addressing/ContextUtils.java
incubator/cxf/branches/2.0.x-fixes/rt/ws/addr/src/main/java/org/apache/cxf/ws/addressing/VersionTransformer.java
incubator/cxf/branches/2.0.x-fixes/systests/src/test/java/org/apache/cxf/systest/jaxws/ClientServerMiscTest.java
incubator/cxf/branches/2.0.x-fixes/systests/src/test/java/org/apache/cxf/systest/jaxws/DocLitWrappedCodeFirstServiceImpl.java
incubator/cxf/branches/2.0.x-fixes/systests/src/test/java/org/apache/cxf/systest/jaxws/ServerMisc.java
incubator/cxf/branches/2.0.x-fixes/tools/javato/ws/src/test/java/org/apache/cxf/tools/java2wsdl/processor/expected/calculator.wsdl
incubator/cxf/branches/2.0.x-fixes/tools/javato/ws/src/test/java/org/apache/cxf/tools/java2wsdl/processor/expected/db.wsdl
Propchange: incubator/cxf/branches/2.0.x-fixes/
------------------------------------------------------------------------------
Binary property 'svnmerge-integrated' - no diff available.
Modified: incubator/cxf/branches/2.0.x-fixes/rt/core/src/main/java/org/apache/cxf/interceptor/ClientFaultConverter.java
URL: http://svn.apache.org/viewvc/incubator/cxf/branches/2.0.x-fixes/rt/core/src/main/java/org/apache/cxf/interceptor/ClientFaultConverter.java?rev=591208&r1=591207&r2=591208&view=diff
==============================================================================
--- incubator/cxf/branches/2.0.x-fixes/rt/core/src/main/java/org/apache/cxf/interceptor/ClientFaultConverter.java (original)
+++ incubator/cxf/branches/2.0.x-fixes/rt/core/src/main/java/org/apache/cxf/interceptor/ClientFaultConverter.java Thu Nov 1 20:14:31 2007
@@ -19,6 +19,7 @@
package org.apache.cxf.interceptor;
import java.lang.reflect.Constructor;
+import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
@@ -153,6 +154,16 @@
LogUtils.log(LOG, Level.INFO, "EXCEPTION_WHILE_CREATING_EXCEPTION", e1, e1.getMessage());
}
} else if (e != null) {
+ if (fault.getMessage() != null) {
+ Field f;
+ try {
+ f = Throwable.class.getDeclaredField("detailMessage");
+ f.setAccessible(true);
+ f.set(e, fault.getMessage());
+ } catch (Exception e1) {
+ //ignore
+ }
+ }
msg.setContent(Exception.class, e);
}
Modified: incubator/cxf/branches/2.0.x-fixes/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBContextInitializer.java
URL: http://svn.apache.org/viewvc/incubator/cxf/branches/2.0.x-fixes/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBContextInitializer.java?rev=591208&r1=591207&r2=591208&view=diff
==============================================================================
--- incubator/cxf/branches/2.0.x-fixes/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBContextInitializer.java (original)
+++ incubator/cxf/branches/2.0.x-fixes/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBContextInitializer.java Thu Nov 1 20:14:31 2007
@@ -62,6 +62,11 @@
return;
}
+ if (Exception.class.isAssignableFrom(clazz)) {
+ //exceptions are handled special, make sure we mark it
+ part.setProperty(JAXBDataBinding.class.getName() + ".CUSTOM_EXCEPTION",
+ Boolean.TRUE);
+ }
boolean isFromWrapper = part.getMessageInfo().getOperation().isUnwrapped();
if (isFromWrapper
&& clazz.isArray()
@@ -144,9 +149,10 @@
if (cls.isArray() && cls.getComponentType().isPrimitive()) {
return;
}
- if (Exception.class.isAssignableFrom(cls)) {
- for (Field f : cls.getDeclaredFields()) {
- addClass(f.getType());
+ if (Throwable.class.isAssignableFrom(cls)) {
+ if (!Throwable.class.equals(cls)
+ && !Exception.class.equals(cls)) {
+ walkReferences(cls);
}
addClass(String.class);
} else {
@@ -209,7 +215,7 @@
}
if (accessType != XmlAccessType.FIELD) { // only look for methods if we are instructed to
- Method methods[] = cls.getMethods();
+ Method methods[] = cls.getDeclaredMethods();
for (Method m : methods) {
if (isMethodAccepted(m, accessType)) {
addType(m.getGenericReturnType());
@@ -224,11 +230,15 @@
/**
* Checks is the field is accepted as a JAXB property.
*/
- private boolean isFieldAccepted(Field field, XmlAccessType accessType) {
+ static boolean isFieldAccepted(Field field, XmlAccessType accessType) {
// We only accept non static fields which are not marked @XmlTransient
if (Modifier.isStatic(field.getModifiers()) || field.isAnnotationPresent(XmlTransient.class)) {
return false;
}
+ if (accessType == XmlAccessType.PUBLIC_MEMBER
+ && !Modifier.isPublic(field.getModifiers())) {
+ return false;
+ }
if (accessType == XmlAccessType.NONE) {
return checkJaxbAnnotation(field.getAnnotations());
@@ -240,14 +250,18 @@
/**
* Checks is the method is accepted as a JAXB property getter.
*/
- private boolean isMethodAccepted(Method method, XmlAccessType accessType) {
+ static boolean isMethodAccepted(Method method, XmlAccessType accessType) {
// We only accept non static property getters which are not marked @XmlTransient
- if (Modifier.isStatic(method.getModifiers()) || method.isAnnotationPresent(XmlTransient.class)) {
+ if (Modifier.isStatic(method.getModifiers())
+ || method.isAnnotationPresent(XmlTransient.class)
+ || !Modifier.isPublic(method.getModifiers())) {
return false;
}
// must not have parameters and return type must not be void
- if (method.getReturnType() == Void.class || method.getParameterTypes().length != 0) {
+ if (method.getReturnType() == Void.class
+ || method.getParameterTypes().length != 0
+ || method.getDeclaringClass().equals(Throwable.class)) {
return false;
}
@@ -256,6 +270,17 @@
if (!isPropGetter) {
return false;
}
+ int beginIndex = 3;
+ if (method.getName().startsWith("is")) {
+ beginIndex = 2;
+ }
+ try {
+ method.getDeclaringClass().getMethod("set" + method.getName().substring(beginIndex),
+ new Class[] {method.getReturnType()});
+ } catch (Exception e) {
+ //getter, but no setter
+ return false;
+ }
if (accessType == XmlAccessType.NONE) {
return checkJaxbAnnotation(method.getAnnotations());
@@ -269,7 +294,7 @@
* @param annotations the array of annotations from the class member
* @return true if JAXB annotations are present, false otherwise
*/
- private boolean checkJaxbAnnotation(Annotation[] annotations) {
+ private static boolean checkJaxbAnnotation(Annotation[] annotations) {
// must check if there are any jaxb annotations
Package jaxbAnnotationsPackage = XmlElement.class.getPackage();
for (Annotation annotation : annotations) {
Modified: incubator/cxf/branches/2.0.x-fixes/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBEncoderDecoder.java
URL: http://svn.apache.org/viewvc/incubator/cxf/branches/2.0.x-fixes/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBEncoderDecoder.java?rev=591208&r1=591207&r2=591208&view=diff
==============================================================================
--- incubator/cxf/branches/2.0.x-fixes/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBEncoderDecoder.java (original)
+++ incubator/cxf/branches/2.0.x-fixes/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBEncoderDecoder.java Thu Nov 1 20:14:31 2007
@@ -19,9 +19,13 @@
package org.apache.cxf.jaxb;
+
import java.io.OutputStream;
import java.lang.reflect.Array;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Field;
import java.lang.reflect.GenericArrayType;
+import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
@@ -36,12 +40,15 @@
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;
import javax.xml.bind.Unmarshaller;
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.adapters.HexBinaryAdapter;
import javax.xml.bind.attachment.AttachmentMarshaller;
import javax.xml.bind.attachment.AttachmentUnmarshaller;
import javax.xml.namespace.QName;
import javax.xml.stream.XMLEventReader;
import javax.xml.stream.XMLEventWriter;
+import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamReader;
import javax.xml.stream.XMLStreamWriter;
import javax.xml.validation.Schema;
@@ -55,6 +62,7 @@
import org.apache.cxf.interceptor.Fault;
import org.apache.cxf.service.model.MessagePartInfo;
import org.apache.cxf.staxutils.StaxUtils;
+import org.apache.cxf.staxutils.W3CDOMStreamWriter;
import org.apache.ws.commons.schema.XmlSchemaElement;
import org.apache.ws.commons.schema.XmlSchemaSimpleType;
import org.apache.ws.commons.schema.XmlSchemaSimpleTypeList;
@@ -182,6 +190,138 @@
}
}
}
+ @SuppressWarnings("unchecked")
+ public static void marshallException(JAXBContext context,
+ Schema schema,
+ Exception elValue,
+ MessagePartInfo part,
+ Object source,
+ AttachmentMarshaller am) {
+ XMLStreamWriter writer = getStreamWriter(source);
+ QName qn = part.getElementQName();
+ try {
+ writer.writeStartElement(qn.getNamespaceURI(), qn.getLocalPart());
+ Class<?> cls = part.getTypeClass();
+ XmlAccessorType accessorType = cls.getAnnotation(XmlAccessorType.class);
+ if (accessorType == null && cls.getPackage() != null) {
+ accessorType = cls.getPackage().getAnnotation(XmlAccessorType.class);
+ }
+ XmlAccessType accessType = accessorType != null
+ ? accessorType.value() : XmlAccessType.PUBLIC_MEMBER;
+ String namespace = part.getElementQName().getNamespaceURI();
+ Marshaller u = createMarshaller(context, cls);
+ try {
+ // The Marshaller.JAXB_FRAGMENT will tell the Marshaller not to
+ // generate the xml declaration.
+ u.setProperty(Marshaller.JAXB_FRAGMENT, true);
+ u.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, false);
+ } catch (javax.xml.bind.PropertyException e) {
+ // intentionally empty.
+ }
+
+
+ for (Field f : cls.getDeclaredFields()) {
+ if (JAXBContextInitializer.isFieldAccepted(f, accessType)) {
+ QName fname = new QName(namespace, f.getName());
+ f.setAccessible(true);
+ writeObject(u, writer, new JAXBElement(fname, String.class, f.get(elValue)));
+ }
+ }
+ for (Method m : cls.getMethods()) {
+ if (JAXBContextInitializer.isMethodAccepted(m, accessType)) {
+ int idx = m.getName().startsWith("get") ? 3 : 2;
+ String name = m.getName().substring(idx);
+ name = Character.toLowerCase(name.charAt(0)) + name.substring(1);
+ QName mname = new QName(namespace, name);
+ writeObject(u, writer, new JAXBElement(mname, String.class, m.invoke(elValue)));
+ }
+ }
+
+ writer.writeEndElement();
+ writer.flush();
+ } catch (Exception e) {
+ throw new Fault(new Message("MARSHAL_ERROR", BUNDLE, e.getMessage()), e);
+ }
+ }
+ @SuppressWarnings("unchecked")
+ public static Exception unmarshallException(JAXBContext context,
+ Schema schema,
+ Object source,
+ MessagePartInfo part,
+ AttachmentUnmarshaller au) {
+ XMLStreamReader reader;
+ if (source instanceof XMLStreamReader) {
+ reader = (XMLStreamReader)source;
+ } else if (source instanceof Element) {
+ reader = StaxUtils.createXMLStreamReader((Element)source);
+ try {
+ //advance into the node
+ reader.nextTag();
+ } catch (XMLStreamException e) {
+ //ignore
+ }
+ } else {
+ throw new Fault(new Message("UNKNOWN_SOURCE", BUNDLE, source.getClass().getName()));
+ }
+ try {
+ QName qn = part.getElementQName();
+ if (!qn.equals(reader.getName())) {
+ throw new Fault(new Message("ELEMENT_NAME_MISMATCH", BUNDLE, qn, reader.getName()));
+ }
+
+ Class<?> cls = part.getTypeClass();
+ Object obj = null;
+ try {
+ Constructor cons = cls.getConstructor();
+ obj = cons.newInstance();
+ } catch (NoSuchMethodException nse) {
+ Constructor cons = cls.getConstructor(new Class[] {String.class});
+ obj = cons.newInstance(new Object[1]);
+ }
+
+ XmlAccessorType accessorType = cls.getAnnotation(XmlAccessorType.class);
+ if (accessorType == null && cls.getPackage() != null) {
+ accessorType = cls.getPackage().getAnnotation(XmlAccessorType.class);
+ }
+ XmlAccessType accessType = accessorType != null
+ ? accessorType.value() : XmlAccessType.PUBLIC_MEMBER;
+ Unmarshaller u = createUnmarshaller(context, cls);
+ try {
+ // The Marshaller.JAXB_FRAGMENT will tell the Marshaller not to
+ // generate the xml declaration.
+ u.setProperty(Marshaller.JAXB_FRAGMENT, true);
+ u.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, false);
+ } catch (javax.xml.bind.PropertyException e) {
+ // intentionally empty.
+ }
+ reader.nextTag();
+ while (reader.getEventType() == XMLStreamReader.START_ELEMENT) {
+ QName q = reader.getName();
+ try {
+ Field f = cls.getField(q.getLocalPart());
+ if (JAXBContextInitializer.isFieldAccepted(f, accessType)) {
+ f.setAccessible(true);
+ f.set(obj, u.unmarshal(reader, f.getType()));
+ }
+ } catch (NoSuchFieldException ex) {
+ String s = Character.toUpperCase(q.getLocalPart().charAt(0))
+ + q.getLocalPart().substring(1);
+ Method m = null;
+ try {
+ m = cls.getMethod("get" + s);
+ } catch (NoSuchMethodException mex) {
+ m = cls.getMethod("is" + s);
+ }
+ Method m2 = cls.getMethod("set" + s, m.getReturnType());
+ Object o = getElementValue(u.unmarshal(reader, m.getReturnType()));
+ m2.invoke(obj, o);
+ }
+ }
+ return (Exception)obj;
+ } catch (Exception e) {
+ throw new Fault(new Message("MARSHAL_ERROR", BUNDLE, e.getMessage()), e);
+ }
+ }
private static void writeObject(Marshaller u, Object source, Object mObj) throws Fault, JAXBException {
if (source instanceof XMLStreamWriter) {
@@ -196,6 +336,16 @@
throw new Fault(new Message("UNKNOWN_SOURCE", BUNDLE, source.getClass().getName()));
}
}
+ private static XMLStreamWriter getStreamWriter(Object source) throws Fault {
+ if (source instanceof XMLStreamWriter) {
+ return (XMLStreamWriter)source;
+ } else if (source instanceof OutputStream) {
+ return StaxUtils.createXMLStreamWriter((OutputStream)source);
+ } else if (source instanceof Node) {
+ return new W3CDOMStreamWriter((Element)source);
+ }
+ throw new Fault(new Message("UNKNOWN_SOURCE", BUNDLE, source.getClass().getName()));
+ }
public static void marshall(JAXBContext context, Schema schema, Object elValue, Object source) {
marshall(context, schema, elValue, null, source, null);
@@ -255,6 +405,14 @@
AttachmentUnmarshaller au,
boolean unwrap) {
Class<?> clazz = part != null ? (Class) part.getTypeClass() : null;
+ if (clazz != null
+ && Exception.class.isAssignableFrom(clazz)
+ && part != null
+ && Boolean.TRUE.equals(part.getProperty(JAXBDataBinding.class.getName()
+ + ".CUSTOM_EXCEPTION"))) {
+ return unmarshallException(context, schema, source, part, au);
+ }
+
QName elName = part != null ? part.getConcreteName() : null;
if (clazz != null
&& clazz.isArray()
Modified: incubator/cxf/branches/2.0.x-fixes/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBSchemaInitializer.java
URL: http://svn.apache.org/viewvc/incubator/cxf/branches/2.0.x-fixes/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBSchemaInitializer.java?rev=591208&r1=591207&r2=591208&view=diff
==============================================================================
--- incubator/cxf/branches/2.0.x-fixes/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBSchemaInitializer.java (original)
+++ incubator/cxf/branches/2.0.x-fixes/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBSchemaInitializer.java Thu Nov 1 20:14:31 2007
@@ -20,10 +20,12 @@
package org.apache.cxf.jaxb;
import java.lang.reflect.Field;
-import java.lang.reflect.Modifier;
+import java.lang.reflect.Method;
import java.util.Iterator;
import java.util.logging.Logger;
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.namespace.QName;
import com.sun.xml.bind.v2.runtime.JAXBContextImpl;
@@ -224,11 +226,77 @@
QName typeName = itr.next();
el.setSchemaTypeName(typeName);
}
- }
+ } else if (part.getXmlSchema() == null) {
+ try {
+ cls.getConstructor(new Class[] {String.class});
+ } catch (Exception e) {
+ try {
+ cls.getConstructor(new Class[0]);
+ } catch (Exception e2) {
+ //no String or default constructor, we cannot use it
+ return;
+ }
+ }
+
+ //not mappable in JAXBContext directly, we'll have to do it manually :-(
+ SchemaInfo schemaInfo = serviceInfo.getSchema(part.getElementQName().getNamespaceURI());
+ if (schemaInfo == null
+ || isExistSchemaElement(schemaInfo.getSchema(), part.getElementQName())) {
+ return;
+ }
+
+ XmlSchemaElement el = new XmlSchemaElement();
+ el.setQName(part.getElementQName());
+ el.setName(part.getElementQName().getLocalPart());
+
+ schemaInfo.getSchema().getItems().add(el);
+ schemaInfo.getSchema().getElements().add(el.getQName(), el);
+
+ part.setXmlSchema(el);
+
+ XmlSchemaComplexType ct = new XmlSchemaComplexType(schemaInfo.getSchema());
+ el.setSchemaType(ct);
+ XmlSchemaSequence seq = new XmlSchemaSequence();
+ ct.setParticle(seq);
+
+ Method methods[] = cls.getMethods();
+ for (Method m : methods) {
+ if (m.getName().startsWith("get")
+ || m.getName().startsWith("is")) {
+ int beginIdx = m.getName().startsWith("get") ? 3 : 2;
+ try {
+ m.getDeclaringClass().getMethod("set" + m.getName().substring(beginIdx),
+ m.getReturnType());
+
+ JaxBeanInfo<?> beanInfo = context.getBeanInfo(m.getReturnType());
+ if (beanInfo != null) {
+ el = new XmlSchemaElement();
+ el.setName(m.getName().substring(beginIdx));
+
+ String ns = schemaInfo.getSchema().getElementFormDefault()
+ .getValue().equals(XmlSchemaForm.UNQUALIFIED)
+ ? "" : part.getElementQName().getLocalPart();
+ el.setQName(new QName(ns, m.getName().substring(beginIdx)));
+
+ Iterator<QName> itr = beanInfo.getTypeNames().iterator();
+ if (!itr.hasNext()) {
+ return;
+ }
+ QName typeName = itr.next();
+ el.setSchemaTypeName(typeName);
+ }
+
+ seq.getItems().add(el);
+ } catch (Exception e) {
+ //not mappable
+ }
+ }
+ }
+ }
}
- private void buildExceptionType(MessagePartInfo part, Class cls) {
+ private void buildExceptionType(MessagePartInfo part, Class<?> cls) {
SchemaInfo schemaInfo = null;
for (SchemaInfo s : serviceInfo.getSchemas()) {
if (s.getNamespaceURI().equals(part.getElementQName().getNamespaceURI())) {
@@ -268,7 +336,8 @@
el.setName(part.getElementQName().getLocalPart());
schema.getItems().add(el);
schema.getElements().add(el.getQName(), el);
-
+ part.setXmlSchema(el);
+
schema.getItems().add(ct);
schema.addType(ct);
el.setSchemaTypeName(part.getElementQName());
@@ -276,56 +345,61 @@
XmlSchemaSequence seq = new XmlSchemaSequence();
ct.setParticle(seq);
String namespace = part.getElementQName().getNamespaceURI();
- for (Field f : cls.getDeclaredFields()) {
- // This code takes all the fields that are public and not static.
- // It is arguable that it should be looking at get/is properties and all those
- // bean-like things.
- int modifiers = f.getModifiers();
- if (!Modifier.isPublic(modifiers) || Modifier.isStatic(modifiers)) {
- continue;
- }
-
- JaxBeanInfo<?> beanInfo = context.getBeanInfo(f.getType());
- if (beanInfo != null) {
- el = new XmlSchemaElement();
- el.setName(f.getName());
- el.setQName(new QName(namespace, f.getName()));
-
- el.setMinOccurs(1);
- el.setMaxOccurs(1);
- el.setNillable(true);
+
+ XmlAccessorType accessorType = cls.getAnnotation(XmlAccessorType.class);
+ if (accessorType == null && cls.getPackage() != null) {
+ accessorType = cls.getPackage().getAnnotation(XmlAccessorType.class);
+ }
+ XmlAccessType accessType = accessorType != null ? accessorType.value() : XmlAccessType.PUBLIC_MEMBER;
- if (beanInfo.isElement()) {
- QName name = new QName(beanInfo.getElementNamespaceURI(null),
- beanInfo.getElementLocalName(null));
- XmlSchemaElement el2 = schemas.getElementByQName(name);
- el.setRefName(el2.getRefName());
- } else {
- Iterator<QName> itr = beanInfo.getTypeNames().iterator();
- if (!itr.hasNext()) {
- continue;
- }
- QName typeName = itr.next();
- el.setSchemaTypeName(typeName);
- }
-
- seq.getItems().add(el);
+
+ for (Field f : cls.getDeclaredFields()) {
+ if (JAXBContextInitializer.isFieldAccepted(f, accessType)) {
+ //map field
+ JaxBeanInfo<?> beanInfo = context.getBeanInfo(f.getType());
+ if (beanInfo != null) {
+ addElement(seq, beanInfo, new QName(namespace, f.getName()));
+ }
+ }
+ }
+ for (Method m : cls.getMethods()) {
+ if (JAXBContextInitializer.isMethodAccepted(m, accessType)) {
+ //map field
+ JaxBeanInfo<?> beanInfo = context.getBeanInfo(m.getReturnType());
+ if (beanInfo != null) {
+ int idx = m.getName().startsWith("get") ? 3 : 2;
+ String name = m.getName().substring(idx);
+ name = Character.toLowerCase(name.charAt(0)) + name.substring(1);
+ addElement(seq, beanInfo, new QName(namespace, name));
+ }
}
}
- JaxBeanInfo<?> beanInfo = context.getBeanInfo(String.class);
- el = new XmlSchemaElement();
- el.setName("message");
- el.setQName(new QName(namespace, "message"));
+ part.setProperty(JAXBDataBinding.class.getName() + ".CUSTOM_EXCEPTION", Boolean.TRUE);
+ }
+
+ public void addElement(XmlSchemaSequence seq, JaxBeanInfo<?> beanInfo, QName name) {
+ XmlSchemaElement el = new XmlSchemaElement();
+ el.setName(name.getLocalPart());
+ el.setQName(name);
el.setMinOccurs(1);
el.setMaxOccurs(1);
el.setNillable(true);
if (beanInfo.isElement()) {
- el.setRefName(beanInfo.getTypeName(null));
+ QName ename = new QName(beanInfo.getElementNamespaceURI(null),
+ beanInfo.getElementLocalName(null));
+ XmlSchemaElement el2 = schemas.getElementByQName(ename);
+ el.setRefName(el2.getRefName());
} else {
- el.setSchemaTypeName(beanInfo.getTypeName(null));
+ Iterator<QName> itr = beanInfo.getTypeNames().iterator();
+ if (!itr.hasNext()) {
+ return;
+ }
+ QName typeName = itr.next();
+ el.setSchemaTypeName(typeName);
}
+
seq.getItems().add(el);
}
Modified: incubator/cxf/branches/2.0.x-fixes/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/io/DataWriterImpl.java
URL: http://svn.apache.org/viewvc/incubator/cxf/branches/2.0.x-fixes/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/io/DataWriterImpl.java?rev=591208&r1=591207&r2=591208&view=diff
==============================================================================
--- incubator/cxf/branches/2.0.x-fixes/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/io/DataWriterImpl.java (original)
+++ incubator/cxf/branches/2.0.x-fixes/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/io/DataWriterImpl.java Thu Nov 1 20:14:31 2007
@@ -23,6 +23,7 @@
import org.apache.cxf.databinding.DataWriter;
import org.apache.cxf.jaxb.JAXBDataBase;
+import org.apache.cxf.jaxb.JAXBDataBinding;
import org.apache.cxf.jaxb.JAXBEncoderDecoder;
import org.apache.cxf.service.model.MessagePartInfo;
import org.apache.ws.commons.schema.XmlSchemaElement;
@@ -39,8 +40,17 @@
public void write(Object obj, MessagePartInfo part, T output) {
if (obj != null
|| !(part.getXmlSchema() instanceof XmlSchemaElement)) {
- JAXBEncoderDecoder.marshall(getJAXBContext(), getSchema(), obj, part, output,
+
+ if (obj instanceof Exception
+ && part != null
+ && Boolean.TRUE.equals(part.getProperty(JAXBDataBinding.class.getName()
+ + ".CUSTOM_EXCEPTION"))) {
+ JAXBEncoderDecoder.marshallException(getJAXBContext(), getSchema(), (Exception)obj,
+ part, output, getAttachmentMarshaller());
+ } else {
+ JAXBEncoderDecoder.marshall(getJAXBContext(), getSchema(), obj, part, output,
getAttachmentMarshaller());
+ }
} else if (obj == null && needToRender(obj, part)) {
JAXBEncoderDecoder.marshallNullElement(getJAXBContext(), getSchema(), output, part);
}
Modified: incubator/cxf/branches/2.0.x-fixes/rt/frontend/simple/src/main/java/org/apache/cxf/service/factory/ReflectionServiceFactoryBean.java
URL: http://svn.apache.org/viewvc/incubator/cxf/branches/2.0.x-fixes/rt/frontend/simple/src/main/java/org/apache/cxf/service/factory/ReflectionServiceFactoryBean.java?rev=591208&r1=591207&r2=591208&view=diff
==============================================================================
--- incubator/cxf/branches/2.0.x-fixes/rt/frontend/simple/src/main/java/org/apache/cxf/service/factory/ReflectionServiceFactoryBean.java (original)
+++ incubator/cxf/branches/2.0.x-fixes/rt/frontend/simple/src/main/java/org/apache/cxf/service/factory/ReflectionServiceFactoryBean.java Thu Nov 1 20:14:31 2007
@@ -307,10 +307,23 @@
if (!isWrapped(m) && !isRPC(m) && opInfo.getOutput() != null) {
createBareMessage(serviceInfo, opInfo, true);
}
-
+
+ if (opInfo.hasFaults()) {
+ //check to make sure the faults are elements
+ for (FaultInfo fault : opInfo.getFaults()) {
+ QName qn = (QName)fault.getProperty("elementName");
+ MessagePartInfo part = fault.getMessagePart(0);
+ if (!part.isElement()) {
+ part.setElement(true);
+ part.setElementQName(qn);
+ checkForElement(serviceInfo, part);
+ }
+ }
+ }
}
}
+
protected void initializeServiceModel() {
String wsdlurl = getWsdlURL();
@@ -537,18 +550,6 @@
mpi.setElementQName(qn);
checkForElement(serviceInfo, mpi);
- }
- }
- }
- if (op.hasFaults()) {
- //check to make sure the faults are elements
- for (FaultInfo fault : op.getFaults()) {
- QName qn = (QName)fault.getProperty("elementName");
- MessagePartInfo part = fault.getMessagePart(0);
- if (!part.isElement()) {
- part.setElement(true);
- part.setElementQName(qn);
- checkForElement(serviceInfo, part);
}
}
}
Modified: incubator/cxf/branches/2.0.x-fixes/rt/ws/addr/src/main/java/org/apache/cxf/ws/addressing/ContextUtils.java
URL: http://svn.apache.org/viewvc/incubator/cxf/branches/2.0.x-fixes/rt/ws/addr/src/main/java/org/apache/cxf/ws/addressing/ContextUtils.java?rev=591208&r1=591207&r2=591208&view=diff
==============================================================================
--- incubator/cxf/branches/2.0.x-fixes/rt/ws/addr/src/main/java/org/apache/cxf/ws/addressing/ContextUtils.java (original)
+++ incubator/cxf/branches/2.0.x-fixes/rt/ws/addr/src/main/java/org/apache/cxf/ws/addressing/ContextUtils.java Thu Nov 1 20:14:31 2007
@@ -40,7 +40,6 @@
import org.apache.cxf.Bus;
import org.apache.cxf.binding.soap.model.SoapOperationInfo;
import org.apache.cxf.common.logging.LogUtils;
-import org.apache.cxf.common.util.PackageUtils;
import org.apache.cxf.common.util.TwoStageMap;
import org.apache.cxf.endpoint.ConduitSelector;
import org.apache.cxf.endpoint.Endpoint;
@@ -78,8 +77,6 @@
public static final ObjectFactory WSA_OBJECT_FACTORY = new ObjectFactory();
- private static final String WS_ADDRESSING_PACKAGE =
- PackageUtils.getPackageName(EndpointReferenceType.class);
private static final EndpointReferenceType NONE_ENDPOINT_REFERENCE =
EndpointReferenceUtils.getEndpointReference(Names.WSA_NONE_ADDRESS);
private static final String HTTP_URI_SCHEME = "http:";
@@ -598,7 +595,7 @@
public static JAXBContext getJAXBContext() throws JAXBException {
synchronized (ContextUtils.class) {
if (jaxbContext == null) {
- jaxbContext = JAXBContext.newInstance(WS_ADDRESSING_PACKAGE);
+ jaxbContext = JAXBContext.newInstance(WSA_OBJECT_FACTORY.getClass());
}
}
return jaxbContext;
Modified: incubator/cxf/branches/2.0.x-fixes/rt/ws/addr/src/main/java/org/apache/cxf/ws/addressing/VersionTransformer.java
URL: http://svn.apache.org/viewvc/incubator/cxf/branches/2.0.x-fixes/rt/ws/addr/src/main/java/org/apache/cxf/ws/addressing/VersionTransformer.java?rev=591208&r1=591207&r2=591208&view=diff
==============================================================================
--- incubator/cxf/branches/2.0.x-fixes/rt/ws/addr/src/main/java/org/apache/cxf/ws/addressing/VersionTransformer.java (original)
+++ incubator/cxf/branches/2.0.x-fixes/rt/ws/addr/src/main/java/org/apache/cxf/ws/addressing/VersionTransformer.java Thu Nov 1 20:14:31 2007
@@ -30,7 +30,6 @@
// importation convention: if the same class name is used for
// 2005/08 and 2004/08, then the former version is imported
// and the latter is fully qualified when used
-import org.apache.cxf.common.util.PackageUtils;
import org.apache.cxf.ws.addressing.v200408.AttributedQName;
import org.apache.cxf.ws.addressing.v200408.AttributedURI;
import org.apache.cxf.ws.addressing.v200408.ObjectFactory;
@@ -322,8 +321,6 @@
WSA_NAMESPACE_NAME + "/role/none";
public static final ObjectFactory WSA_OBJECT_FACTORY =
new ObjectFactory();
- public static final String WS_ADDRESSING_PACKAGE =
- PackageUtils.getPackageName(AttributedURI.class);
public static final Class<org.apache.cxf.ws.addressing.v200408.EndpointReferenceType>
EPR_TYPE =
org.apache.cxf.ws.addressing.v200408.EndpointReferenceType.class;
@@ -343,7 +340,7 @@
synchronized (Names200408.class) {
if (jaxbContext == null) {
jaxbContext =
- JAXBContext.newInstance(WS_ADDRESSING_PACKAGE);
+ JAXBContext.newInstance(org.apache.cxf.ws.addressing.v200408.ObjectFactory.class);
}
}
return jaxbContext;
Modified: incubator/cxf/branches/2.0.x-fixes/systests/src/test/java/org/apache/cxf/systest/jaxws/ClientServerMiscTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/branches/2.0.x-fixes/systests/src/test/java/org/apache/cxf/systest/jaxws/ClientServerMiscTest.java?rev=591208&r1=591207&r2=591208&view=diff
==============================================================================
--- incubator/cxf/branches/2.0.x-fixes/systests/src/test/java/org/apache/cxf/systest/jaxws/ClientServerMiscTest.java (original)
+++ incubator/cxf/branches/2.0.x-fixes/systests/src/test/java/org/apache/cxf/systest/jaxws/ClientServerMiscTest.java Thu Nov 1 20:14:31 2007
@@ -335,6 +335,15 @@
} catch (ServiceTestFault ex) {
assertNull(ex.getFaultInfo());
}
+ // CXF-1136 testcase
+ try {
+ port.throwException(-2);
+ fail("Expected exception not found");
+ } catch (CustomException ex) {
+ assertEquals("CE: -2", ex.getMessage());
+ assertEquals("A Value", ex.getA());
+ assertEquals("B Value", ex.getB());
+ }
}
Modified: incubator/cxf/branches/2.0.x-fixes/systests/src/test/java/org/apache/cxf/systest/jaxws/DocLitWrappedCodeFirstServiceImpl.java
URL: http://svn.apache.org/viewvc/incubator/cxf/branches/2.0.x-fixes/systests/src/test/java/org/apache/cxf/systest/jaxws/DocLitWrappedCodeFirstServiceImpl.java?rev=591208&r1=591207&r2=591208&view=diff
==============================================================================
--- incubator/cxf/branches/2.0.x-fixes/systests/src/test/java/org/apache/cxf/systest/jaxws/DocLitWrappedCodeFirstServiceImpl.java (original)
+++ incubator/cxf/branches/2.0.x-fixes/systests/src/test/java/org/apache/cxf/systest/jaxws/DocLitWrappedCodeFirstServiceImpl.java Thu Nov 1 20:14:31 2007
@@ -122,8 +122,12 @@
switch (i) {
case -1:
throw new ServiceTestFault("Hello!");
- case -2:
- throw new CustomException("CE: " + i);
+ case -2: {
+ CustomException cex = new CustomException("CE: " + i);
+ cex.setA("A Value");
+ cex.setB("B Value");
+ throw cex;
+ }
default:
throw new ServiceTestFault(new ServiceTestFault.ServiceTestDetails(i));
}
Modified: incubator/cxf/branches/2.0.x-fixes/systests/src/test/java/org/apache/cxf/systest/jaxws/ServerMisc.java
URL: http://svn.apache.org/viewvc/incubator/cxf/branches/2.0.x-fixes/systests/src/test/java/org/apache/cxf/systest/jaxws/ServerMisc.java?rev=591208&r1=591207&r2=591208&view=diff
==============================================================================
--- incubator/cxf/branches/2.0.x-fixes/systests/src/test/java/org/apache/cxf/systest/jaxws/ServerMisc.java (original)
+++ incubator/cxf/branches/2.0.x-fixes/systests/src/test/java/org/apache/cxf/systest/jaxws/ServerMisc.java Thu Nov 1 20:14:31 2007
@@ -38,14 +38,14 @@
"http://localhost:9003/DocLitBareCodeFirstService/";
protected void run() {
+ Object implementor4 = new DocLitWrappedCodeFirstServiceImpl();
+ Endpoint.publish(DOCLIT_CODEFIRST_URL, implementor4);
+
Object implementor7 = new DocLitBareCodeFirstServiceImpl();
Endpoint.publish(DOCLITBARE_CODEFIRST_URL, implementor7);
Object implementor6 = new InterfaceInheritTestImpl();
Endpoint.publish(DOCLIT_CODEFIRST_BASE_URL, implementor6);
-
- Object implementor4 = new DocLitWrappedCodeFirstServiceImpl();
- Endpoint.publish(DOCLIT_CODEFIRST_URL, implementor4);
Object implementor1 = new AnonymousComplexTypeImpl();
String address = "http://localhost:9000/anonymous_complex_typeSOAP";
Modified: incubator/cxf/branches/2.0.x-fixes/tools/javato/ws/src/test/java/org/apache/cxf/tools/java2wsdl/processor/expected/calculator.wsdl
URL: http://svn.apache.org/viewvc/incubator/cxf/branches/2.0.x-fixes/tools/javato/ws/src/test/java/org/apache/cxf/tools/java2wsdl/processor/expected/calculator.wsdl?rev=591208&r1=591207&r2=591208&view=diff
==============================================================================
--- incubator/cxf/branches/2.0.x-fixes/tools/javato/ws/src/test/java/org/apache/cxf/tools/java2wsdl/processor/expected/calculator.wsdl (original)
+++ incubator/cxf/branches/2.0.x-fixes/tools/javato/ws/src/test/java/org/apache/cxf/tools/java2wsdl/processor/expected/calculator.wsdl Thu Nov 1 20:14:31 2007
@@ -22,9 +22,7 @@
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:tns="http://docwrapped.classnoanno.fortest.tools.cxf.apache.org/" attributeFormDefault="unqualified" elementFormDefault="qualified" targetNamespace="http://docwrapped.classnoanno.fortest.tools.cxf.apache.org/">
<xsd:element name="AddException" type="tns:AddException"/>
<xsd:complexType name="AddException">
-<xsd:sequence>
-<xsd:element name="message" nillable="true" type="xsd:string"/>
-</xsd:sequence>
+<xsd:sequence/>
</xsd:complexType>
<xsd:element name="add" type="tns:add"/>
<xsd:complexType name="add">
Modified: incubator/cxf/branches/2.0.x-fixes/tools/javato/ws/src/test/java/org/apache/cxf/tools/java2wsdl/processor/expected/db.wsdl
URL: http://svn.apache.org/viewvc/incubator/cxf/branches/2.0.x-fixes/tools/javato/ws/src/test/java/org/apache/cxf/tools/java2wsdl/processor/expected/db.wsdl?rev=591208&r1=591207&r2=591208&view=diff
==============================================================================
--- incubator/cxf/branches/2.0.x-fixes/tools/javato/ws/src/test/java/org/apache/cxf/tools/java2wsdl/processor/expected/db.wsdl (original)
+++ incubator/cxf/branches/2.0.x-fixes/tools/javato/ws/src/test/java/org/apache/cxf/tools/java2wsdl/processor/expected/db.wsdl Thu Nov 1 20:14:31 2007
@@ -32,9 +32,7 @@
</xs:complexType>
<xs:element name="DBServiceFault" type="DBServiceFault"/>
<xs:complexType name="DBServiceFault">
-<xs:sequence>
-<xs:element name="message" nillable="true" type="xs:string"/>
-</xs:sequence>
+<xs:sequence/>
</xs:complexType>
<xs:element name="operation0" type="operation0"/>
<xs:complexType name="operation0">