JBossWS SVN: r17141 - stack/cxf/trunk/modules/addons/transports/http/httpserver/src/main/java/org/jboss/wsf/stack/cxf/addons/transports/httpserver.
by jbossws-commits@lists.jboss.org
Author: richard.opalka(a)jboss.com
Date: 2012-12-19 09:07:26 -0500 (Wed, 19 Dec 2012)
New Revision: 17141
Modified:
stack/cxf/trunk/modules/addons/transports/http/httpserver/src/main/java/org/jboss/wsf/stack/cxf/addons/transports/httpserver/HttpServerEngineFactory.java
Log:
fixing synchronization issues
Modified: stack/cxf/trunk/modules/addons/transports/http/httpserver/src/main/java/org/jboss/wsf/stack/cxf/addons/transports/httpserver/HttpServerEngineFactory.java
===================================================================
--- stack/cxf/trunk/modules/addons/transports/http/httpserver/src/main/java/org/jboss/wsf/stack/cxf/addons/transports/httpserver/HttpServerEngineFactory.java 2012-12-19 12:44:00 UTC (rev 17140)
+++ stack/cxf/trunk/modules/addons/transports/http/httpserver/src/main/java/org/jboss/wsf/stack/cxf/addons/transports/httpserver/HttpServerEngineFactory.java 2012-12-19 14:07:26 UTC (rev 17141)
@@ -79,7 +79,7 @@
{
return bus;
}
-
+
/**
* Retrieve a previously configured HttpServerEngine for the
* given port. If none exists, this call returns null.
@@ -97,10 +97,10 @@
public synchronized HttpServerEngine createHttpServerEngine(String host, int port, String protocol)
throws IOException
{
- LOG.fine("Creating HttpServer Engine for port " + port + ".");
HttpServerEngine ref = null;
synchronized(portMap)
{
+ LOG.fine("Creating HttpServer Engine for port " + port + ".");
ref = retrieveHttpServerEngine(port);
if (null == ref)
{
@@ -116,7 +116,7 @@
}
return ref;
}
-
+
/**
* This method removes the Server Engine from the port map and stops it.
*/
@@ -145,7 +145,7 @@
// do nothing here
}
- public void postShutdown()
+ public synchronized void postShutdown()
{
// shut down the httpserver in the portMap
// To avoid the CurrentModificationException,
12 years, 1 month
JBossWS SVN: r17140 - thirdparty/cxf/branches/cxf-2.2.12-patch02_JBPAPP-10129/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb.
by jbossws-commits@lists.jboss.org
Author: mmusaji
Date: 2012-12-19 07:44:00 -0500 (Wed, 19 Dec 2012)
New Revision: 17140
Added:
thirdparty/cxf/branches/cxf-2.2.12-patch02_JBPAPP-10129/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/Utils.java
Modified:
thirdparty/cxf/branches/cxf-2.2.12-patch02_JBPAPP-10129/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBContextInitializer.java
thirdparty/cxf/branches/cxf-2.2.12-patch02_JBPAPP-10129/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBEncoderDecoder.java
thirdparty/cxf/branches/cxf-2.2.12-patch02_JBPAPP-10129/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBSchemaInitializer.java
Log:
[JBPAPP-10129] Commit after applying changes from CXF-4591 including roll back patch
Modified: thirdparty/cxf/branches/cxf-2.2.12-patch02_JBPAPP-10129/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBContextInitializer.java
===================================================================
--- thirdparty/cxf/branches/cxf-2.2.12-patch02_JBPAPP-10129/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBContextInitializer.java 2012-12-19 11:10:25 UTC (rev 17139)
+++ thirdparty/cxf/branches/cxf-2.2.12-patch02_JBPAPP-10129/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBContextInitializer.java 2012-12-19 12:44:00 UTC (rev 17140)
@@ -33,7 +33,6 @@
import java.util.Set;
import javax.xml.bind.annotation.XmlAccessType;
-import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlSeeAlso;
@@ -197,7 +196,7 @@
if (anns != null) {
for (Annotation a : anns) {
if (XmlJavaTypeAdapter.class.isAssignableFrom(a.annotationType())) {
- Type t = getTypeFromXmlAdapter((XmlJavaTypeAdapter)a);
+ Type t = Utils.getTypeFromXmlAdapter((XmlJavaTypeAdapter)a);
if (t != null) {
addType(t);
}
@@ -206,7 +205,7 @@
}
XmlJavaTypeAdapter xjta = clazz.getAnnotation(XmlJavaTypeAdapter.class);
if (xjta != null) {
- Type t = getTypeFromXmlAdapter(xjta);
+ Type t = Utils.getTypeFromXmlAdapter(xjta);
if (t != null) {
addType(t);
}
@@ -293,7 +292,7 @@
}
XmlJavaTypeAdapter xjta = cls.getAnnotation(XmlJavaTypeAdapter.class);
if (xjta != null) {
- Type t = getTypeFromXmlAdapter(xjta);
+ Type t = Utils.getTypeFromXmlAdapter(xjta);
if (t != null) {
addType(t);
}
@@ -328,47 +327,6 @@
return adapter;
}
- static XmlJavaTypeAdapter getMethodXJTA(final Method m) {
- XmlJavaTypeAdapter adapter = m.getAnnotation(XmlJavaTypeAdapter.class);
- if (adapter == null) {
- adapter = m.getReturnType().getAnnotation(XmlJavaTypeAdapter.class);
- }
- if (adapter == null) {
- XmlJavaTypeAdapters adapters = m.getDeclaringClass().getPackage().getAnnotation(XmlJavaTypeAdapters.class);
- if (adapters != null) {
- for (XmlJavaTypeAdapter candidate : adapters.value()) {
- if (candidate != null && candidate.type().equals(m.getGenericReturnType())) {
- adapter = candidate;
- break;
- }
- }
- }
- }
- return adapter;
- }
-
- static Class<?> getTypeFromXmlAdapter(XmlJavaTypeAdapter xjta) {
- if (xjta != null) {
- Class<?> c2 = xjta.value();
- Type sp = c2.getGenericSuperclass();
- while (!XmlAdapter.class.equals(c2) && c2 != null) {
- sp = c2.getGenericSuperclass();
- c2 = c2.getSuperclass();
- }
- if (sp instanceof ParameterizedType) {
- return (Class<?>)((ParameterizedType)sp).getActualTypeArguments()[0];
- }
- }
- return null;
- }
-
- @SuppressWarnings("rawtypes")
- static XmlAdapter getXmlAdapter(XmlJavaTypeAdapter adapterAnnotation)
- throws InstantiationException, IllegalAccessException {
- return adapterAnnotation != null ? adapterAnnotation.value().newInstance() : null;
- }
-
-
private void walkReferences(Class<?> cls) {
if (cls == null) {
return;
@@ -383,11 +341,7 @@
//We'll grab the public field/method types and then add the ObjectFactory stuff
//as well as look for jaxb.index files in those packages.
- 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;
+ XmlAccessType accessType = Utils.getXmlAccessType(cls);
if (accessType != XmlAccessType.PROPERTY) { // only look for fields if we are instructed to
//fields are accessible even if not public, must look at the declared fields
@@ -477,7 +431,7 @@
* @param annotations the array of annotations from the class member
* @return true if JAXB annotations are present, false otherwise
*/
- private static boolean checkJaxbAnnotation(Annotation[] annotations) {
+ static boolean checkJaxbAnnotation(Annotation[] annotations) {
// must check if there are any jaxb annotations
Package jaxbAnnotationsPackage = XmlElement.class.getPackage();
for (Annotation annotation : annotations) {
Modified: thirdparty/cxf/branches/cxf-2.2.12-patch02_JBPAPP-10129/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBEncoderDecoder.java
===================================================================
--- thirdparty/cxf/branches/cxf-2.2.12-patch02_JBPAPP-10129/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBEncoderDecoder.java 2012-12-19 11:10:25 UTC (rev 17139)
+++ thirdparty/cxf/branches/cxf-2.2.12-patch02_JBPAPP-10129/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBEncoderDecoder.java 2012-12-19 12:44:00 UTC (rev 17140)
@@ -49,6 +49,7 @@
import javax.xml.bind.Unmarshaller;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.adapters.HexBinaryAdapter;
import javax.xml.bind.annotation.adapters.XmlAdapter;
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
@@ -67,7 +68,6 @@
import javax.xml.transform.stream.StreamResult;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
-
import org.apache.cxf.common.i18n.Message;
import org.apache.cxf.common.logging.LogUtils;
import org.apache.cxf.common.util.SOAPConstants;
@@ -337,12 +337,7 @@
try {
writer.writeStartElement("ns1", qn.getLocalPart(), qn.getNamespaceURI());
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;
+ XmlAccessType accessType = Utils.getXmlAccessType(cls);
String namespace = part.getElementQName().getNamespaceURI();
SchemaInfo sch = part.getMessageInfo().getOperation().getInterface()
@@ -355,33 +350,31 @@
LOG.warning("Schema associated with " + namespace + " is null");
}
- for (Field f : cls.getDeclaredFields()) {
- if (JAXBContextInitializer.isFieldAccepted(f, accessType)) {
+ for (Field f : Utils.getFields(cls, accessType)) {
+ XmlAttribute at = f.getAnnotation(XmlAttribute.class);
+ if (at == null) {
QName fname = new QName(namespace, f.getName());
f.setAccessible(true);
if (JAXBSchemaInitializer.isArray(f.getGenericType())) {
- writeArrayObject(marshaller, writer, fname, f.get(elValue));
+ writeArrayObject(marshaller, writer, fname, f.get(elValue));
} else {
- Object o = getFieldValue(f, elValue);
+ Object o = Utils.getFieldValue(f, elValue);
writeObject(marshaller, writer, new JAXBElement(fname, String.class, o));
}
}
}
- 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);
- if (JAXBSchemaInitializer.isArray(m.getGenericReturnType())) {
- writeArrayObject(marshaller, writer, mname, m.invoke(elValue));
- } else {
- Object o = getMethodValue(m, elValue);
- writeObject(marshaller, writer, new JAXBElement(mname, String.class, o));
+ for (Method m : Utils.getGetters(cls, 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);
+ if (JAXBSchemaInitializer.isArray(m.getGenericReturnType())) {
+ writeArrayObject(marshaller, writer, mname, m.invoke(elValue));
+ } else {
+ Object o = Utils.getMethodValue(m, elValue);
+ writeObject(marshaller, writer, new JAXBElement(mname, String.class, o));
}
- }
}
-
writer.writeEndElement();
writer.flush();
} catch (Exception e) {
@@ -450,56 +443,45 @@
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;
+ XmlAccessType accessType = Utils.getXmlAccessType(cls);
reader.nextTag();
while (reader.getEventType() == XMLStreamReader.START_ELEMENT) {
QName q = reader.getName();
- try {
- Field f = cls.getField(q.getLocalPart());
+ String fieldName = q.getLocalPart();
+ Field f = Utils.getField(cls, accessType, fieldName);
+ if (f != null) {
Type type = f.getGenericType();
- if (JAXBContextInitializer.isFieldAccepted(f, accessType)) {
- f.setAccessible(true);
- if (JAXBSchemaInitializer.isArray(type)) {
- Class<?> compType = JAXBSchemaInitializer
- .getArrayComponentType(type);
- List<Object> ret = unmarshallArray(u, reader,
- q,
- compType,
- createList(type));
- Object o = ret;
- if (!isList(type)) {
- if (compType.isPrimitive()) {
- o = java.lang.reflect.Array.newInstance(compType, ret.size());
- for (int x = 0; x < ret.size(); x++) {
- Array.set(o, x, ret.get(x));
- }
- } else {
- o = ret.toArray((Object[])Array.newInstance(compType, ret.size()));
- }
+ f.setAccessible(true);
+ if (JAXBSchemaInitializer.isArray(type)) {
+ Class<?> compType = JAXBSchemaInitializer.getArrayComponentType(type);
+ List<Object> ret = unmarshallArray(u, reader, q, compType, createList(type));
+ Object o = ret;
+ if (!isList(type)) {
+ if (compType.isPrimitive()) {
+ o = java.lang.reflect.Array.newInstance(compType, ret.size());
+ for (int x = 0; x < ret.size(); x++) {
+ Array.set(o, x, ret.get(x));
+ }
+ } else {
+ o = ret.toArray((Object[]) Array.newInstance(compType, ret.size()));
+ }
}
f.set(obj, o);
} else {
- Object o = getElementValue(u.unmarshal(reader, getFieldType(f)));
- setFieldValue(f, obj, o);
+ Object o = getElementValue(u.unmarshal(reader, Utils.getFieldType(f)));
+ Utils.setFieldValue(f, obj, o);
}
- }
- } catch (NoSuchFieldException ex) {
+
+ } else {
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 m = Utils.getMethod(cls, accessType, "get" + s);
+ if (m == null) {
+ m = Utils.getMethod(cls, accessType, "is" + s);
}
Type type = m.getGenericReturnType();
- Method m2 = cls.getMethod("set" + s, m.getReturnType());
+ Method m2 = Utils.getMethod(cls, accessType, "set" + s, m.getReturnType());
if (JAXBSchemaInitializer.isArray(type)) {
Class<?> compType = JAXBSchemaInitializer
.getArrayComponentType(type);
@@ -521,57 +503,18 @@
m2.invoke(obj, o);
} else {
- Object o = getElementValue(u.unmarshal(reader, getMethodReturnType(m)));
- setMethodValue(m, m2, obj, o);
+ Object o = getElementValue(u.unmarshal(reader, Utils.getMethodReturnType(m)));
+ Utils.setMethodValue(m, m2, obj, o);
}
}
- }
- return (Exception)obj;
+ }
+ return (Exception)obj;
} catch (Exception e) {
- throw new Fault(new Message("MARSHAL_ERROR", LOG, e.getMessage()), e);
+ throw new Fault(new Message("MARSHAL_ERROR", LOG, e.getMessage()), e);
}
- }
+ }
+
- private static Class<?> getFieldType(final Field f) {
- XmlJavaTypeAdapter adapter = JAXBContextInitializer.getFieldXJTA(f);
- Class<?> adapterType = JAXBContextInitializer.getTypeFromXmlAdapter(adapter);
- return adapterType != null ? adapterType : f.getType();
- }
-
- private static Class<?> getMethodReturnType(final Method m) {
- XmlJavaTypeAdapter adapter = JAXBContextInitializer.getMethodXJTA(m);
- Class<?> adapterType = JAXBContextInitializer.getTypeFromXmlAdapter(adapter);
- return adapterType != null ? adapterType : m.getReturnType();
- }
-
- @SuppressWarnings({ "rawtypes", "unchecked" })
- private static Object getFieldValue(Field f, Object target) throws Exception {
- XmlJavaTypeAdapter adapterAnnotation = JAXBContextInitializer.getFieldXJTA(f);
- XmlAdapter adapter = JAXBContextInitializer.getXmlAdapter(adapterAnnotation);
- return adapter != null ? adapter.marshal(f.get(target)) : f.get(target);
- }
-
- @SuppressWarnings({ "rawtypes", "unchecked" })
- private static Object getMethodValue(Method m, Object target) throws Exception {
- XmlJavaTypeAdapter adapterAnnotation = JAXBContextInitializer.getMethodXJTA(m);
- XmlAdapter adapter = JAXBContextInitializer.getXmlAdapter(adapterAnnotation);
- return adapter != null ? adapter.marshal(m.invoke(target)) : m.invoke(target);
- }
-
- @SuppressWarnings({ "rawtypes", "unchecked" })
- private static void setFieldValue(Field f, Object target, Object value) throws Exception {
- XmlJavaTypeAdapter xjta = JAXBContextInitializer.getFieldXJTA(f);
- XmlAdapter adapter = JAXBContextInitializer.getXmlAdapter(xjta);
- f.set(target, adapter != null ? adapter.unmarshal(value) : value);
- }
-
- @SuppressWarnings({ "rawtypes", "unchecked" })
- private static void setMethodValue(Method getter, Method setter, Object target, Object value) throws Exception {
- XmlJavaTypeAdapter xjta = JAXBContextInitializer.getMethodXJTA(getter);
- XmlAdapter adapter = JAXBContextInitializer.getXmlAdapter(xjta);
- setter.invoke(target, adapter != null ? adapter.unmarshal(value) : value);
- }
-
private static void writeObject(Marshaller u, Object source, Object mObj) throws Fault, JAXBException {
if (source instanceof XMLStreamWriter) {
u.marshal(mObj, (XMLStreamWriter)source);
Modified: thirdparty/cxf/branches/cxf-2.2.12-patch02_JBPAPP-10129/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBSchemaInitializer.java
===================================================================
--- thirdparty/cxf/branches/cxf-2.2.12-patch02_JBPAPP-10129/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBSchemaInitializer.java 2012-12-19 11:10:25 UTC (rev 17139)
+++ thirdparty/cxf/branches/cxf-2.2.12-patch02_JBPAPP-10129/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBSchemaInitializer.java 2012-12-19 12:44:00 UTC (rev 17140)
@@ -31,7 +31,6 @@
import javax.xml.bind.JAXBContext;
import javax.xml.bind.annotation.XmlAccessType;
-import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlList;
import javax.xml.bind.annotation.adapters.XmlAdapter;
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
@@ -517,51 +516,29 @@
ct.setParticle(seq);
String namespace = part.getElementQName().getNamespaceURI();
- 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;
-
-
- for (Field f : cls.getDeclaredFields()) {
- if (JAXBContextInitializer.isFieldAccepted(f, accessType)) {
- //map field
- Type type = getFieldType(f);
- JAXBBeanInfo beanInfo = getBeanInfo(type);
- if (beanInfo != null) {
- addElement(seq, beanInfo, new QName(namespace, f.getName()), isArray(type));
+ XmlAccessType accessType = Utils.getXmlAccessType(cls);
+ for (Field f : Utils.getFields(cls, accessType)) {
+ //map field
+ Type type = Utils.getFieldType(f);
+ JAXBBeanInfo beanInfo = getBeanInfo(type);
+ if (beanInfo != null) {
+ addElement(schema, seq, beanInfo, new QName(namespace, f.getName()), isArray(type));
}
- }
}
- for (Method m : cls.getMethods()) {
- if (JAXBContextInitializer.isMethodAccepted(m, accessType)) {
- //map method
- Type type = getMethodReturnType(m);
- JAXBBeanInfo beanInfo = getBeanInfo(type);
- 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), isArray(type));
+ for (Method m : Utils.getGetters(cls, accessType)) {
+ //map method
+ Type type = Utils.getMethodReturnType(m);
+ JAXBBeanInfo beanInfo = getBeanInfo(type);
+ 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(schema, seq, beanInfo, new QName(namespace, name), isArray(type));
}
- }
}
part.setProperty(JAXBDataBinding.class.getName() + ".CUSTOM_EXCEPTION", Boolean.TRUE);
}
- private static Type getFieldType(final Field f) {
- XmlJavaTypeAdapter adapter = JAXBContextInitializer.getFieldXJTA(f);
- Class<?> adapterType = JAXBContextInitializer.getTypeFromXmlAdapter(adapter);
- return adapterType != null ? adapterType : f.getGenericType();
- }
-
- private static Type getMethodReturnType(final Method m) {
- XmlJavaTypeAdapter adapter = JAXBContextInitializer.getMethodXJTA(m);
- Class<?> adapterType = JAXBContextInitializer.getTypeFromXmlAdapter(adapter);
- return adapterType != null ? adapterType : m.getGenericReturnType();
- }
-
static boolean isArray(Type cls) {
if (cls instanceof Class) {
return ((Class)cls).isArray();
@@ -573,7 +550,8 @@
return false;
}
- public void addElement(XmlSchemaSequence seq, JAXBBeanInfo beanInfo,
+ public void addElement(XmlSchema schema,
+ XmlSchemaSequence seq, JAXBBeanInfo beanInfo,
QName name, boolean isArray) {
XmlSchemaElement el = new XmlSchemaElement();
el.setName(name.getLocalPart());
Added: thirdparty/cxf/branches/cxf-2.2.12-patch02_JBPAPP-10129/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/Utils.java
===================================================================
--- thirdparty/cxf/branches/cxf-2.2.12-patch02_JBPAPP-10129/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/Utils.java (rev 0)
+++ thirdparty/cxf/branches/cxf-2.2.12-patch02_JBPAPP-10129/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/Utils.java 2012-12-19 12:44:00 UTC (rev 17140)
@@ -0,0 +1,297 @@
+/**
+ * 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.jaxb;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
+import java.lang.reflect.ParameterizedType;
+import java.lang.reflect.Type;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Set;
+
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlTransient;
+import javax.xml.bind.annotation.adapters.XmlAdapter;
+import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
+import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapters;
+
+/**
+ * JAXB reflection utilities.
+ */
+final class Utils {
+ private Utils() {
+ }
+
+ static XmlAccessType getXmlAccessType(Class<?> cls) {
+ XmlAccessorType accessorType = cls.getAnnotation(XmlAccessorType.class);
+ if (accessorType == null && cls.getPackage() != null) {
+ accessorType = cls.getPackage().getAnnotation(XmlAccessorType.class);
+ }
+ return accessorType != null
+ ? accessorType.value() : XmlAccessType.PUBLIC_MEMBER;
+ }
+
+ static Collection<Field> getFields(Class<?> cls, XmlAccessType accessType) {
+ return getFieldsInternal(cls, accessType);
+ }
+
+ private static Collection<Field> getFieldsInternal(Class<?> cls, XmlAccessType accessType) {
+ Set<Field> fields = new HashSet<Field>();
+ Class<?> superClass = cls.getSuperclass();
+ if (superClass != null && !superClass.equals(Object.class) && !superClass.equals(Throwable.class)) {
+ // process super class until java.lang.Object or java.lang.Throwable is not reached
+ fields.addAll(getFieldsInternal(superClass, accessType));
+ }
+ // process current class
+ for (Field field : cls.getDeclaredFields()) {
+ if (JAXBContextInitializer.isFieldAccepted(field, accessType)) {
+ fields.add(field);
+ }
+ }
+ return fields;
+ }
+
+ private static Collection<Method> getMethods(Class<?> cls, XmlAccessType accessType, boolean acceptSetters) {
+ return getMethodsInternal(cls, accessType, acceptSetters);
+ }
+
+ private static Collection<Method> getMethodsInternal(Class<?> cls, XmlAccessType accessType,
+ boolean acceptSetters) {
+ Set<Method> methods = new HashSet<Method>();
+ Class<?> superClass = cls.getSuperclass();
+ if (superClass != null && !superClass.equals(Object.class) && !superClass.equals(Throwable.class)) {
+ // process super class until java.lang.Object or java.lang.Throwable is not reached
+ methods.addAll(getMethodsInternal(superClass, accessType, acceptSetters));
+ }
+ // process current class
+ for (Method method : cls.getDeclaredMethods()) {
+ if (isMethodAccepted(method, accessType, acceptSetters)) {
+ methods.add(method);
+ }
+ }
+ return methods;
+ }
+
+ static Method getMethod(Class<?> cls, XmlAccessType accessType, String methodName,
+ Class<?>... paramTypes) {
+ for (Method m : getMethods(cls, accessType, true)) {
+ if (m.getName().equals(methodName) && Arrays.equals(m.getParameterTypes(), paramTypes)) {
+ return m;
+ }
+ }
+ return null;
+ }
+
+ static Field getField(Class<?> cls, XmlAccessType accessType, String fieldName) {
+ for (final Field f : getFields(cls, accessType)) {
+ if (f.getName().equals(fieldName)) {
+ return f;
+ }
+ }
+ return null;
+ }
+
+ static Collection<Method> getGetters(Class<?> cls, XmlAccessType accessType) {
+ return getMethods(cls, accessType, false);
+ }
+
+ static boolean isMethodAccepted(Method method, XmlAccessType accessType, boolean acceptSetters) {
+ // ignore bridge, static, @XmlTransient methods plus methods declared in Throwable
+ if (method.isBridge()
+ || Modifier.isStatic(method.getModifiers())
+ || method.isAnnotationPresent(XmlTransient.class)
+ || method.getDeclaringClass().equals(Throwable.class)) {
+ return false;
+ }
+ // Allow only public methods if PUBLIC_MEMBER access is requested
+ if (accessType == XmlAccessType.PUBLIC_MEMBER && !Modifier.isPublic(method.getModifiers())) {
+ return false;
+ }
+ if (isGetter(method)) {
+ // does nothing
+ } else if (isSetter(method)) {
+ if (!acceptSetters) {
+ return false;
+ }
+ } else {
+ // we accept only getters and setters
+ return false;
+ }
+ // let JAXB annotations decide if NONE or FIELD access is requested
+ if (accessType == XmlAccessType.NONE || accessType == XmlAccessType.FIELD) {
+ return JAXBContextInitializer.checkJaxbAnnotation(method.getAnnotations());
+ }
+ // method accepted
+ return true;
+ }
+
+ private static boolean isGetter(Method m) {
+ Class<?> declaringClass = m.getDeclaringClass();
+ if (m.getReturnType() != Void.class && m.getParameterTypes().length == 0) {
+ final int index = getterIndex(m.getName());
+ if (index != -1) {
+ String setterName = "set" + m.getName().substring(index);
+ Class<?> paramTypes = m.getReturnType();
+ Method setter = getDeclaredMethod(declaringClass, setterName, paramTypes);
+ if (setter != null && !setter.isAnnotationPresent(XmlTransient.class)) {
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+
+ private static boolean isSetter(Method m) {
+ Class<?> declaringClass = m.getDeclaringClass();
+ boolean isVoidReturnType = m.getReturnType() == Void.class || m.getReturnType() == Void.TYPE;
+ if (isVoidReturnType && m.getParameterTypes().length == 1 && m.getName().startsWith("set")) {
+ String getterName = "get" + m.getName().substring(3);
+ Class<?> setterParamType = m.getParameterTypes()[0];
+ Method getter = getDeclaredMethod(declaringClass, getterName);
+ if (getter != null && getter.getReturnType().equals(setterParamType)
+ && !getter.isAnnotationPresent(XmlTransient.class)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ private static int getterIndex(String methodName) {
+ if (methodName.startsWith("is")) {
+ return 2;
+ }
+ if (methodName.startsWith("get")) {
+ return 3;
+ }
+ return -1;
+ }
+
+ private static Method getDeclaredMethod(Class<?> cls, String methodName, Class<?>... paramTypes) {
+ try {
+ return cls.getDeclaredMethod(methodName, paramTypes);
+ } catch (Exception e) {
+ return null;
+ }
+ }
+
+ static Class<?> getFieldType(Field f) {
+ XmlJavaTypeAdapter adapter = getFieldXJTA(f);
+ Class<?> adapterType = getTypeFromXmlAdapter(adapter);
+ return adapterType != null ? adapterType : f.getType();
+ }
+
+ static Class<?> getMethodReturnType(Method m) {
+ XmlJavaTypeAdapter adapter = getMethodXJTA(m);
+ Class<?> adapterType = getTypeFromXmlAdapter(adapter);
+ return adapterType != null ? adapterType : m.getReturnType();
+ }
+
+ @SuppressWarnings({ "rawtypes", "unchecked" })
+ static Object getFieldValue(Field f, Object target) throws Exception {
+ XmlJavaTypeAdapter adapterAnnotation = getFieldXJTA(f);
+ XmlAdapter adapter = getXmlAdapter(adapterAnnotation);
+ return adapter != null ? adapter.marshal(f.get(target)) : f.get(target);
+ }
+
+ @SuppressWarnings({ "rawtypes", "unchecked" })
+ static Object getMethodValue(Method m, Object target) throws Exception {
+ XmlJavaTypeAdapter adapterAnnotation = getMethodXJTA(m);
+ XmlAdapter adapter = getXmlAdapter(adapterAnnotation);
+ return adapter != null ? adapter.marshal(m.invoke(target)) : m.invoke(target);
+ }
+
+ @SuppressWarnings({ "rawtypes", "unchecked" })
+ static void setFieldValue(Field f, Object target, Object value) throws Exception {
+ XmlJavaTypeAdapter xjta = getFieldXJTA(f);
+ XmlAdapter adapter = getXmlAdapter(xjta);
+ f.set(target, adapter != null ? adapter.unmarshal(value) : value);
+ }
+
+ @SuppressWarnings({ "rawtypes", "unchecked" })
+ static void setMethodValue(Method getter, Method setter, Object target, Object value) throws Exception {
+ XmlJavaTypeAdapter xjta = getMethodXJTA(getter);
+ XmlAdapter adapter = getXmlAdapter(xjta);
+ setter.invoke(target, adapter != null ? adapter.unmarshal(value) : value);
+ }
+
+ @SuppressWarnings("rawtypes")
+ static XmlAdapter getXmlAdapter(XmlJavaTypeAdapter adapterAnnotation)
+ throws InstantiationException, IllegalAccessException {
+ return adapterAnnotation != null ? adapterAnnotation.value().newInstance() : null;
+ }
+
+ static XmlJavaTypeAdapter getFieldXJTA(final Field f) {
+ XmlJavaTypeAdapter adapter = f.getAnnotation(XmlJavaTypeAdapter.class);
+ if (adapter == null) {
+ adapter = f.getType().getAnnotation(XmlJavaTypeAdapter.class);
+ }
+ if (adapter == null) {
+ XmlJavaTypeAdapters adapters = f.getDeclaringClass().getPackage().getAnnotation(XmlJavaTypeAdapters.class);
+ if (adapters != null) {
+ for (XmlJavaTypeAdapter candidate : adapters.value()) {
+ if (candidate != null && candidate.type().equals(f.getType())) {
+ adapter = candidate;
+ break;
+ }
+ }
+ }
+ }
+ return adapter;
+ }
+
+ static XmlJavaTypeAdapter getMethodXJTA(final Method m) {
+ XmlJavaTypeAdapter adapter = m.getAnnotation(XmlJavaTypeAdapter.class);
+ if (adapter == null) {
+ adapter = m.getReturnType().getAnnotation(XmlJavaTypeAdapter.class);
+ }
+ if (adapter == null) {
+ XmlJavaTypeAdapters adapters = m.getDeclaringClass().getPackage().getAnnotation(XmlJavaTypeAdapters.class);
+ if (adapters != null) {
+ for (XmlJavaTypeAdapter candidate : adapters.value()) {
+ if (candidate != null && candidate.type().equals(m.getGenericReturnType())) {
+ adapter = candidate;
+ break;
+ }
+ }
+ }
+ }
+ return adapter;
+ }
+
+ static Class<?> getTypeFromXmlAdapter(XmlJavaTypeAdapter xjta) {
+ if (xjta != null) {
+ Class<?> c2 = xjta.value();
+ Type sp = c2.getGenericSuperclass();
+ while (!XmlAdapter.class.equals(c2) && c2 != null) {
+ sp = c2.getGenericSuperclass();
+ c2 = c2.getSuperclass();
+ }
+ if (sp instanceof ParameterizedType) {
+ return (Class<?>)((ParameterizedType)sp).getActualTypeArguments()[0];
+ }
+ }
+ return null;
+ }
+
+}
12 years, 1 month
JBossWS SVN: r17139 - thirdparty/cxf/branches/cxf-2.2.12-patch02_JBPAPP-10129/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb.
by jbossws-commits@lists.jboss.org
Author: mmusaji
Date: 2012-12-19 06:10:25 -0500 (Wed, 19 Dec 2012)
New Revision: 17139
Modified:
thirdparty/cxf/branches/cxf-2.2.12-patch02_JBPAPP-10129/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBContextInitializer.java
thirdparty/cxf/branches/cxf-2.2.12-patch02_JBPAPP-10129/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBEncoderDecoder.java
thirdparty/cxf/branches/cxf-2.2.12-patch02_JBPAPP-10129/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBSchemaInitializer.java
Log:
[JBPAPP-10129] - Commit after applying changes from CXF-4542. This allows the annotation for @XMLJavaTypeAdapter to picked up on exception classes
Modified: thirdparty/cxf/branches/cxf-2.2.12-patch02_JBPAPP-10129/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBContextInitializer.java
===================================================================
--- thirdparty/cxf/branches/cxf-2.2.12-patch02_JBPAPP-10129/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBContextInitializer.java 2012-12-19 10:37:43 UTC (rev 17138)
+++ thirdparty/cxf/branches/cxf-2.2.12-patch02_JBPAPP-10129/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBContextInitializer.java 2012-12-19 11:10:25 UTC (rev 17139)
@@ -41,6 +41,7 @@
import javax.xml.bind.annotation.XmlType;
import javax.xml.bind.annotation.adapters.XmlAdapter;
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
+import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapters;
import javax.xml.namespace.QName;
import org.apache.cxf.common.classloader.ClassLoaderUtils;
@@ -196,13 +197,19 @@
if (anns != null) {
for (Annotation a : anns) {
if (XmlJavaTypeAdapter.class.isAssignableFrom(a.annotationType())) {
- inspectTypeAdapter(((XmlJavaTypeAdapter)a).value());
+ Type t = getTypeFromXmlAdapter((XmlJavaTypeAdapter)a);
+ if (t != null) {
+ addType(t);
+ }
}
}
}
XmlJavaTypeAdapter xjta = clazz.getAnnotation(XmlJavaTypeAdapter.class);
if (xjta != null) {
- inspectTypeAdapter(xjta.value());
+ Type t = getTypeFromXmlAdapter(xjta);
+ if (t != null) {
+ addType(t);
+ }
}
}
@@ -286,8 +293,11 @@
}
XmlJavaTypeAdapter xjta = cls.getAnnotation(XmlJavaTypeAdapter.class);
if (xjta != null) {
- Class<? extends XmlAdapter> c2 = xjta.value();
- inspectTypeAdapter(c2);
+ Type t = getTypeFromXmlAdapter(xjta);
+ if (t != null) {
+ addType(t);
+ }
+ return;
}
} else if (classes.contains(cls)) {
return;
@@ -299,18 +309,66 @@
}
}
- private void inspectTypeAdapter(Class<? extends XmlAdapter> aclass) {
- Class<?> c2 = aclass;
- Type sp = c2.getGenericSuperclass();
- while (!XmlAdapter.class.equals(c2) && c2 != null) {
- sp = c2.getGenericSuperclass();
- c2 = c2.getSuperclass();
+ static XmlJavaTypeAdapter getFieldXJTA(final Field f) {
+ XmlJavaTypeAdapter adapter = f.getAnnotation(XmlJavaTypeAdapter.class);
+ if (adapter == null) {
+ adapter = f.getType().getAnnotation(XmlJavaTypeAdapter.class);
}
- if (sp instanceof ParameterizedType) {
- addType(((ParameterizedType)sp).getActualTypeArguments()[0]);
+ if (adapter == null) {
+ XmlJavaTypeAdapters adapters = f.getDeclaringClass().getPackage().getAnnotation(XmlJavaTypeAdapters.class);
+ if (adapters != null) {
+ for (XmlJavaTypeAdapter candidate : adapters.value()) {
+ if (candidate != null && candidate.type().equals(f.getType())) {
+ adapter = candidate;
+ break;
+ }
+ }
+ }
}
+ return adapter;
}
+ static XmlJavaTypeAdapter getMethodXJTA(final Method m) {
+ XmlJavaTypeAdapter adapter = m.getAnnotation(XmlJavaTypeAdapter.class);
+ if (adapter == null) {
+ adapter = m.getReturnType().getAnnotation(XmlJavaTypeAdapter.class);
+ }
+ if (adapter == null) {
+ XmlJavaTypeAdapters adapters = m.getDeclaringClass().getPackage().getAnnotation(XmlJavaTypeAdapters.class);
+ if (adapters != null) {
+ for (XmlJavaTypeAdapter candidate : adapters.value()) {
+ if (candidate != null && candidate.type().equals(m.getGenericReturnType())) {
+ adapter = candidate;
+ break;
+ }
+ }
+ }
+ }
+ return adapter;
+ }
+
+ static Class<?> getTypeFromXmlAdapter(XmlJavaTypeAdapter xjta) {
+ if (xjta != null) {
+ Class<?> c2 = xjta.value();
+ Type sp = c2.getGenericSuperclass();
+ while (!XmlAdapter.class.equals(c2) && c2 != null) {
+ sp = c2.getGenericSuperclass();
+ c2 = c2.getSuperclass();
+ }
+ if (sp instanceof ParameterizedType) {
+ return (Class<?>)((ParameterizedType)sp).getActualTypeArguments()[0];
+ }
+ }
+ return null;
+ }
+
+ @SuppressWarnings("rawtypes")
+ static XmlAdapter getXmlAdapter(XmlJavaTypeAdapter adapterAnnotation)
+ throws InstantiationException, IllegalAccessException {
+ return adapterAnnotation != null ? adapterAnnotation.value().newInstance() : null;
+ }
+
+
private void walkReferences(Class<?> cls) {
if (cls == null) {
return;
@@ -368,9 +426,6 @@
&& !Modifier.isPublic(field.getModifiers())) {
return false;
}
- if (field.getAnnotation(XmlJavaTypeAdapter.class) != null) {
- return false;
- }
if (accessType == XmlAccessType.NONE
|| accessType == XmlAccessType.PROPERTY) {
return checkJaxbAnnotation(field.getAnnotations());
@@ -397,12 +452,6 @@
return false;
}
- boolean isPropGetter = method.getName().startsWith("get") || method.getName().startsWith("is");
-
- if (!isPropGetter
- || method.getAnnotation(XmlJavaTypeAdapter.class) != null) {
- return false;
- }
int beginIndex = 3;
if (method.getName().startsWith("is")) {
beginIndex = 2;
Modified: thirdparty/cxf/branches/cxf-2.2.12-patch02_JBPAPP-10129/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBEncoderDecoder.java
===================================================================
--- thirdparty/cxf/branches/cxf-2.2.12-patch02_JBPAPP-10129/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBEncoderDecoder.java 2012-12-19 10:37:43 UTC (rev 17138)
+++ thirdparty/cxf/branches/cxf-2.2.12-patch02_JBPAPP-10129/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBEncoderDecoder.java 2012-12-19 11:10:25 UTC (rev 17139)
@@ -50,6 +50,8 @@
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.adapters.HexBinaryAdapter;
+import javax.xml.bind.annotation.adapters.XmlAdapter;
+import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
import javax.xml.bind.attachment.AttachmentMarshaller;
import javax.xml.bind.attachment.AttachmentUnmarshaller;
import javax.xml.namespace.NamespaceContext;
@@ -360,8 +362,8 @@
if (JAXBSchemaInitializer.isArray(f.getGenericType())) {
writeArrayObject(marshaller, writer, fname, f.get(elValue));
} else {
- writeObject(marshaller, writer, new JAXBElement(fname, String.class,
- f.get(elValue)));
+ Object o = getFieldValue(f, elValue);
+ writeObject(marshaller, writer, new JAXBElement(fname, String.class, o));
}
}
}
@@ -374,8 +376,8 @@
if (JAXBSchemaInitializer.isArray(m.getGenericReturnType())) {
writeArrayObject(marshaller, writer, mname, m.invoke(elValue));
} else {
- writeObject(marshaller, writer, new JAXBElement(mname, String.class,
- m.invoke(elValue)));
+ Object o = getMethodValue(m, elValue);
+ writeObject(marshaller, writer, new JAXBElement(mname, String.class, o));
}
}
}
@@ -483,7 +485,8 @@
f.set(obj, o);
} else {
- f.set(obj, u.unmarshal(reader, f.getType()));
+ Object o = getElementValue(u.unmarshal(reader, getFieldType(f)));
+ setFieldValue(f, obj, o);
}
}
} catch (NoSuchFieldException ex) {
@@ -518,8 +521,8 @@
m2.invoke(obj, o);
} else {
- Object o = getElementValue(u.unmarshal(reader, m.getReturnType()));
- m2.invoke(obj, o);
+ Object o = getElementValue(u.unmarshal(reader, getMethodReturnType(m)));
+ setMethodValue(m, m2, obj, o);
}
}
}
@@ -529,6 +532,46 @@
}
}
+ private static Class<?> getFieldType(final Field f) {
+ XmlJavaTypeAdapter adapter = JAXBContextInitializer.getFieldXJTA(f);
+ Class<?> adapterType = JAXBContextInitializer.getTypeFromXmlAdapter(adapter);
+ return adapterType != null ? adapterType : f.getType();
+ }
+
+ private static Class<?> getMethodReturnType(final Method m) {
+ XmlJavaTypeAdapter adapter = JAXBContextInitializer.getMethodXJTA(m);
+ Class<?> adapterType = JAXBContextInitializer.getTypeFromXmlAdapter(adapter);
+ return adapterType != null ? adapterType : m.getReturnType();
+ }
+
+ @SuppressWarnings({ "rawtypes", "unchecked" })
+ private static Object getFieldValue(Field f, Object target) throws Exception {
+ XmlJavaTypeAdapter adapterAnnotation = JAXBContextInitializer.getFieldXJTA(f);
+ XmlAdapter adapter = JAXBContextInitializer.getXmlAdapter(adapterAnnotation);
+ return adapter != null ? adapter.marshal(f.get(target)) : f.get(target);
+ }
+
+ @SuppressWarnings({ "rawtypes", "unchecked" })
+ private static Object getMethodValue(Method m, Object target) throws Exception {
+ XmlJavaTypeAdapter adapterAnnotation = JAXBContextInitializer.getMethodXJTA(m);
+ XmlAdapter adapter = JAXBContextInitializer.getXmlAdapter(adapterAnnotation);
+ return adapter != null ? adapter.marshal(m.invoke(target)) : m.invoke(target);
+ }
+
+ @SuppressWarnings({ "rawtypes", "unchecked" })
+ private static void setFieldValue(Field f, Object target, Object value) throws Exception {
+ XmlJavaTypeAdapter xjta = JAXBContextInitializer.getFieldXJTA(f);
+ XmlAdapter adapter = JAXBContextInitializer.getXmlAdapter(xjta);
+ f.set(target, adapter != null ? adapter.unmarshal(value) : value);
+ }
+
+ @SuppressWarnings({ "rawtypes", "unchecked" })
+ private static void setMethodValue(Method getter, Method setter, Object target, Object value) throws Exception {
+ XmlJavaTypeAdapter xjta = JAXBContextInitializer.getMethodXJTA(getter);
+ XmlAdapter adapter = JAXBContextInitializer.getXmlAdapter(xjta);
+ setter.invoke(target, adapter != null ? adapter.unmarshal(value) : value);
+ }
+
private static void writeObject(Marshaller u, Object source, Object mObj) throws Fault, JAXBException {
if (source instanceof XMLStreamWriter) {
u.marshal(mObj, (XMLStreamWriter)source);
Modified: thirdparty/cxf/branches/cxf-2.2.12-patch02_JBPAPP-10129/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBSchemaInitializer.java
===================================================================
--- thirdparty/cxf/branches/cxf-2.2.12-patch02_JBPAPP-10129/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBSchemaInitializer.java 2012-12-19 10:37:43 UTC (rev 17138)
+++ thirdparty/cxf/branches/cxf-2.2.12-patch02_JBPAPP-10129/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBSchemaInitializer.java 2012-12-19 11:10:25 UTC (rev 17139)
@@ -527,7 +527,7 @@
for (Field f : cls.getDeclaredFields()) {
if (JAXBContextInitializer.isFieldAccepted(f, accessType)) {
//map field
- Type type = f.getGenericType();
+ Type type = getFieldType(f);
JAXBBeanInfo beanInfo = getBeanInfo(type);
if (beanInfo != null) {
addElement(seq, beanInfo, new QName(namespace, f.getName()), isArray(type));
@@ -536,8 +536,8 @@
}
for (Method m : cls.getMethods()) {
if (JAXBContextInitializer.isMethodAccepted(m, accessType)) {
- //map field
- Type type = m.getGenericReturnType();
+ //map method
+ Type type = getMethodReturnType(m);
JAXBBeanInfo beanInfo = getBeanInfo(type);
if (beanInfo != null) {
int idx = m.getName().startsWith("get") ? 3 : 2;
@@ -550,6 +550,18 @@
part.setProperty(JAXBDataBinding.class.getName() + ".CUSTOM_EXCEPTION", Boolean.TRUE);
}
+ private static Type getFieldType(final Field f) {
+ XmlJavaTypeAdapter adapter = JAXBContextInitializer.getFieldXJTA(f);
+ Class<?> adapterType = JAXBContextInitializer.getTypeFromXmlAdapter(adapter);
+ return adapterType != null ? adapterType : f.getGenericType();
+ }
+
+ private static Type getMethodReturnType(final Method m) {
+ XmlJavaTypeAdapter adapter = JAXBContextInitializer.getMethodXJTA(m);
+ Class<?> adapterType = JAXBContextInitializer.getTypeFromXmlAdapter(adapter);
+ return adapterType != null ? adapterType : m.getGenericReturnType();
+ }
+
static boolean isArray(Type cls) {
if (cls instanceof Class) {
return ((Class)cls).isArray();
12 years, 1 month
JBossWS SVN: r17138 - in stack/cxf/trunk/modules: server/src/main/java/org/jboss/wsf/stack/cxf/security/authentication and 1 other directory.
by jbossws-commits@lists.jboss.org
Author: alessio.soldano(a)jboss.com
Date: 2012-12-19 05:37:43 -0500 (Wed, 19 Dec 2012)
New Revision: 17138
Modified:
stack/cxf/trunk/modules/client/src/main/java/org/jboss/wsf/stack/cxf/client/ProviderImpl.java
stack/cxf/trunk/modules/server/src/main/java/org/jboss/wsf/stack/cxf/security/authentication/SubjectCreator.java
Log:
[JBWS-3573] Create DelegateClassloader in a doPrivileged action
Modified: stack/cxf/trunk/modules/client/src/main/java/org/jboss/wsf/stack/cxf/client/ProviderImpl.java
===================================================================
--- stack/cxf/trunk/modules/client/src/main/java/org/jboss/wsf/stack/cxf/client/ProviderImpl.java 2012-12-19 10:08:52 UTC (rev 17137)
+++ stack/cxf/trunk/modules/client/src/main/java/org/jboss/wsf/stack/cxf/client/ProviderImpl.java 2012-12-19 10:37:43 UTC (rev 17138)
@@ -225,7 +225,7 @@
}
//then setup a new TCCL having visibility over both the client path (JBossWS
//jaxws-client module on AS7) and the the former TCCL (i.e. the deployment classloader)
- setContextClassLoader(new DelegateClassLoader(clientClassLoader, origClassLoader));
+ setContextClassLoader(createDelegateClassLoader(clientClassLoader, origClassLoader));
return true;
}
return false;
@@ -243,6 +243,25 @@
}
return bus;
}
+
+ private static DelegateClassLoader createDelegateClassLoader(final ClassLoader clientClassLoader, final ClassLoader origClassLoader)
+ {
+ SecurityManager sm = System.getSecurityManager();
+ if (sm == null)
+ {
+ return new DelegateClassLoader(clientClassLoader, origClassLoader);
+ }
+ else
+ {
+ return AccessController.doPrivileged(new PrivilegedAction<DelegateClassLoader>()
+ {
+ public DelegateClassLoader run()
+ {
+ return new DelegateClassLoader(clientClassLoader, origClassLoader);
+ }
+ });
+ }
+ }
/**
* Get context classloader.
Modified: stack/cxf/trunk/modules/server/src/main/java/org/jboss/wsf/stack/cxf/security/authentication/SubjectCreator.java
===================================================================
--- stack/cxf/trunk/modules/server/src/main/java/org/jboss/wsf/stack/cxf/security/authentication/SubjectCreator.java 2012-12-19 10:08:52 UTC (rev 17137)
+++ stack/cxf/trunk/modules/server/src/main/java/org/jboss/wsf/stack/cxf/security/authentication/SubjectCreator.java 2012-12-19 10:37:43 UTC (rev 17138)
@@ -24,6 +24,8 @@
import static org.jboss.wsf.stack.cxf.Loggers.SECURITY_LOGGER;
import static org.jboss.wsf.stack.cxf.Messages.MESSAGES;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
import java.security.Principal;
import java.util.Calendar;
import java.util.TimeZone;
@@ -88,7 +90,7 @@
{
ClassLoader tccl = SecurityActions.getContextClassLoader();
//allow PicketBox to see jbossws modules' classes
- SecurityActions.setContextClassLoader(new DelegateClassLoader(ClassLoaderProvider.getDefaultProvider().getServerIntegrationClassLoader(), tccl));
+ SecurityActions.setContextClassLoader(createDelegateClassLoader(ClassLoaderProvider.getDefaultProvider().getServerIntegrationClassLoader(), tccl));
try
{
if (ctx.isValid(principal, password, subject) == false)
@@ -161,6 +163,25 @@
{
this.decodeNonce = decodeNonce;
}
+
+ private static DelegateClassLoader createDelegateClassLoader(final ClassLoader clientClassLoader, final ClassLoader origClassLoader)
+ {
+ SecurityManager sm = System.getSecurityManager();
+ if (sm == null)
+ {
+ return new DelegateClassLoader(clientClassLoader, origClassLoader);
+ }
+ else
+ {
+ return AccessController.doPrivileged(new PrivilegedAction<DelegateClassLoader>()
+ {
+ public DelegateClassLoader run()
+ {
+ return new DelegateClassLoader(clientClassLoader, origClassLoader);
+ }
+ });
+ }
+ }
private static Calendar unmarshalDateTime(String value)
{
12 years, 1 month
JBossWS SVN: r17137 - common/trunk/src/main/java/org/jboss/ws/common/utils.
by jbossws-commits@lists.jboss.org
Author: alessio.soldano(a)jboss.com
Date: 2012-12-19 05:08:52 -0500 (Wed, 19 Dec 2012)
New Revision: 17137
Modified:
common/trunk/src/main/java/org/jboss/ws/common/utils/AbstractWSDLFilePublisher.java
Log:
[JBWS-3573] More minor fixes...
Modified: common/trunk/src/main/java/org/jboss/ws/common/utils/AbstractWSDLFilePublisher.java
===================================================================
--- common/trunk/src/main/java/org/jboss/ws/common/utils/AbstractWSDLFilePublisher.java 2012-12-19 10:06:05 UTC (rev 17136)
+++ common/trunk/src/main/java/org/jboss/ws/common/utils/AbstractWSDLFilePublisher.java 2012-12-19 10:08:52 UTC (rev 17137)
@@ -174,7 +174,7 @@
}
}
- private static void createParentDir(File targetFile)
+ protected void createParentDir(File targetFile)
{
File parentFile = targetFile.getParentFile();
if (parentFile != null) {
12 years, 1 month
JBossWS SVN: r17136 - in stack/cxf/trunk/modules/server/src/main/java/org/jboss/wsf/stack/cxf: metadata/services and 1 other directory.
by jbossws-commits@lists.jboss.org
Author: alessio.soldano(a)jboss.com
Date: 2012-12-19 05:06:05 -0500 (Wed, 19 Dec 2012)
New Revision: 17136
Modified:
stack/cxf/trunk/modules/server/src/main/java/org/jboss/wsf/stack/cxf/deployment/EndpointImpl.java
stack/cxf/trunk/modules/server/src/main/java/org/jboss/wsf/stack/cxf/deployment/WSDLFilePublisher.java
stack/cxf/trunk/modules/server/src/main/java/org/jboss/wsf/stack/cxf/metadata/services/DDBeans.java
Log:
[JBWS-3573] More misc minor fixes..
Modified: stack/cxf/trunk/modules/server/src/main/java/org/jboss/wsf/stack/cxf/deployment/EndpointImpl.java
===================================================================
--- stack/cxf/trunk/modules/server/src/main/java/org/jboss/wsf/stack/cxf/deployment/EndpointImpl.java 2012-12-19 08:08:14 UTC (rev 17135)
+++ stack/cxf/trunk/modules/server/src/main/java/org/jboss/wsf/stack/cxf/deployment/EndpointImpl.java 2012-12-19 10:06:05 UTC (rev 17136)
@@ -129,7 +129,7 @@
JaxWsImplementorInfo info = new JaxWsImplementorInfo(getImplementorClass());
wsdlLocation = info.getWsdlLocation();
}
- wsdlPublisher.publishWsdlFiles(service.getName(), wsdlLocation, BusFactory.getThreadDefaultBus(false), service.getServiceInfos());
+ wsdlPublisher.publishWsdlFiles(service.getName(), wsdlLocation, this.getBus(), service.getServiceInfos());
}
catch (IOException ioe)
{
Modified: stack/cxf/trunk/modules/server/src/main/java/org/jboss/wsf/stack/cxf/deployment/WSDLFilePublisher.java
===================================================================
--- stack/cxf/trunk/modules/server/src/main/java/org/jboss/wsf/stack/cxf/deployment/WSDLFilePublisher.java 2012-12-19 08:08:14 UTC (rev 17135)
+++ stack/cxf/trunk/modules/server/src/main/java/org/jboss/wsf/stack/cxf/deployment/WSDLFilePublisher.java 2012-12-19 10:06:05 UTC (rev 17136)
@@ -67,7 +67,8 @@
{
String deploymentName = dep.getCanonicalName();
File wsdlFile = getPublishLocation(serviceName.getLocalPart(), deploymentName, wsdlLocation);
- wsdlFile.getParentFile().mkdirs();
+ if (wsdlFile == null) return;
+ createParentDir(wsdlFile);
try
{
// Write the wsdl def to file
Modified: stack/cxf/trunk/modules/server/src/main/java/org/jboss/wsf/stack/cxf/metadata/services/DDBeans.java
===================================================================
--- stack/cxf/trunk/modules/server/src/main/java/org/jboss/wsf/stack/cxf/metadata/services/DDBeans.java 2012-12-19 08:08:14 UTC (rev 17135)
+++ stack/cxf/trunk/modules/server/src/main/java/org/jboss/wsf/stack/cxf/metadata/services/DDBeans.java 2012-12-19 10:06:05 UTC (rev 17136)
@@ -85,7 +85,7 @@
{
File tmpDir = IOUtils.createTempDirectory();
tmpFile = File.createTempFile("jbossws-cxf", ".xml", tmpDir);
- Writer writer = new OutputStreamWriter(new FileOutputStream(tmpFile));
+ Writer writer = new OutputStreamWriter(new FileOutputStream(tmpFile), "UTF-8");
try
{
writeTo(writer);
@@ -114,7 +114,7 @@
public void writeTo(Writer writer) throws IOException
{
- writer.write("<beans " +
+ writer.write("<?xml version = \"1.0\" encoding = \"UTF-8\"?><beans " +
"xmlns='http://www.springframework.org/schema/beans' " +
"xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' " +
"xmlns:beans='http://www.springframework.org/schema/beans' " +
12 years, 1 month
JBossWS SVN: r17135 - in stack/cxf/trunk/modules: server/src/main/java/org/jboss/wsf/stack/cxf/deployment/aspect and 2 other directories.
by jbossws-commits@lists.jboss.org
Author: alessio.soldano(a)jboss.com
Date: 2012-12-19 03:08:14 -0500 (Wed, 19 Dec 2012)
New Revision: 17135
Modified:
stack/cxf/trunk/modules/client/src/main/java/org/jboss/wsf/stack/cxf/client/serviceref/CXFServiceObjectFactoryJAXWS.java
stack/cxf/trunk/modules/server/src/main/java/org/jboss/wsf/stack/cxf/deployment/aspect/BusDeploymentAspect.java
stack/cxf/trunk/modules/server/src/main/java/org/jboss/wsf/stack/cxf/deployment/aspect/CXFInstanceProviderDeploymentAspect.java
stack/cxf/trunk/modules/server/src/main/java/org/jboss/wsf/stack/cxf/deployment/aspect/DescriptorDeploymentAspect.java
stack/cxf/trunk/modules/server/src/main/java/org/jboss/wsf/stack/cxf/metadata/MetadataBuilder.java
stack/cxf/trunk/modules/server/src/main/java/org/jboss/wsf/stack/cxf/resolver/JBossWSResourceResolver.java
Log:
[JBWS-3551] Impl and use failsafe methods
Modified: stack/cxf/trunk/modules/client/src/main/java/org/jboss/wsf/stack/cxf/client/serviceref/CXFServiceObjectFactoryJAXWS.java
===================================================================
--- stack/cxf/trunk/modules/client/src/main/java/org/jboss/wsf/stack/cxf/client/serviceref/CXFServiceObjectFactoryJAXWS.java 2012-12-19 07:58:54 UTC (rev 17134)
+++ stack/cxf/trunk/modules/client/src/main/java/org/jboss/wsf/stack/cxf/client/serviceref/CXFServiceObjectFactoryJAXWS.java 2012-12-19 08:08:14 UTC (rev 17135)
@@ -93,24 +93,14 @@
private URL getCXFConfiguration(final UnifiedVirtualFile vfsRoot)
{
- URL url = null;
- try
- {
- url = vfsRoot.findChild("WEB-INF/" + Constants.JBOSSWS_CXF_SPRING_DD).toURL();
- }
- catch (Exception e)
- {
- }
+ UnifiedVirtualFile uvf = vfsRoot.findChildFailSafe("WEB-INF/" + Constants.JBOSSWS_CXF_SPRING_DD);
+ URL url = (uvf != null) ? uvf.toURL() : null;
if (url == null)
{
- try
- {
- url = vfsRoot.findChild("META-INF/" + Constants.JBOSSWS_CXF_SPRING_DD).toURL();
- }
- catch (Exception e)
- {
- }
+ uvf = vfsRoot.findChildFailSafe("META-INF/" + Constants.JBOSSWS_CXF_SPRING_DD);
+ if (uvf != null)
+ url = uvf.toURL();
}
return url;
}
Modified: stack/cxf/trunk/modules/server/src/main/java/org/jboss/wsf/stack/cxf/deployment/aspect/BusDeploymentAspect.java
===================================================================
--- stack/cxf/trunk/modules/server/src/main/java/org/jboss/wsf/stack/cxf/deployment/aspect/BusDeploymentAspect.java 2012-12-19 07:58:54 UTC (rev 17134)
+++ stack/cxf/trunk/modules/server/src/main/java/org/jboss/wsf/stack/cxf/deployment/aspect/BusDeploymentAspect.java 2012-12-19 08:08:14 UTC (rev 17135)
@@ -99,8 +99,8 @@
if (jbosswsCxfXml != null)
{
// Spring available and jbossws-cxf.xml provided
- final URL cxfServletUrl = getResourceUrl(deploymentResolver, "WEB-INF/cxf-servlet.xml", false); // TODO: decide not to support this?
- final URL jbosswsCxfUrl = getResourceUrl(deploymentResolver, jbosswsCxfXml, true);
+ final URL cxfServletUrl = deploymentResolver.resolveFailSafe("WEB-INF/cxf-servlet.xml"); // TODO: decide not to support this?
+ final URL jbosswsCxfUrl = getResourceUrl(deploymentResolver, jbosswsCxfXml);
holder = new SpringBusHolder(cxfServletUrl, jbosswsCxfUrl);
}
else
@@ -135,16 +135,16 @@
}
}
- private static URL getResourceUrl(final ResourceResolver resolver, final String resourcePath, final boolean fail) {
- try {
- return resolver.resolve(resourcePath);
- } catch (final IOException e) {
- if (fail) {
- throw new RuntimeException(e);
- } else {
- return null;
- }
- }
+ private static URL getResourceUrl(final ResourceResolver resolver, final String resourcePath)
+ {
+ try
+ {
+ return resolver.resolve(resourcePath);
+ }
+ catch (final IOException e)
+ {
+ throw new RuntimeException(e);
+ }
}
}
Modified: stack/cxf/trunk/modules/server/src/main/java/org/jboss/wsf/stack/cxf/deployment/aspect/CXFInstanceProviderDeploymentAspect.java
===================================================================
--- stack/cxf/trunk/modules/server/src/main/java/org/jboss/wsf/stack/cxf/deployment/aspect/CXFInstanceProviderDeploymentAspect.java 2012-12-19 07:58:54 UTC (rev 17134)
+++ stack/cxf/trunk/modules/server/src/main/java/org/jboss/wsf/stack/cxf/deployment/aspect/CXFInstanceProviderDeploymentAspect.java 2012-12-19 08:08:14 UTC (rev 17135)
@@ -41,11 +41,12 @@
@Override
public void start(final Deployment dep)
{
+ boolean springAvailable = SpringUtils.isSpringAvailable();
for (final Endpoint ep : dep.getService().getEndpoints())
{
final ServerFactoryBean factory = ep.getAttachment(ServerFactoryBean.class);
//TODO: remove this after JBWS-3396 resolved
- if (factory == null && SpringUtils.isSpringAvailable())
+ if (factory == null && springAvailable)
{
throw Messages.MESSAGES.endpointNotDefineInJbwsCxf(ep.getTargetBeanName());
}
Modified: stack/cxf/trunk/modules/server/src/main/java/org/jboss/wsf/stack/cxf/deployment/aspect/DescriptorDeploymentAspect.java
===================================================================
--- stack/cxf/trunk/modules/server/src/main/java/org/jboss/wsf/stack/cxf/deployment/aspect/DescriptorDeploymentAspect.java 2012-12-19 07:58:54 UTC (rev 17134)
+++ stack/cxf/trunk/modules/server/src/main/java/org/jboss/wsf/stack/cxf/deployment/aspect/DescriptorDeploymentAspect.java 2012-12-19 08:08:14 UTC (rev 17135)
@@ -27,7 +27,6 @@
import static org.jboss.ws.common.integration.WSHelper.isWarArchive;
import static org.jboss.wsf.stack.cxf.Loggers.DEPLOYMENT_LOGGER;
-import java.io.IOException;
import java.net.URL;
import java.util.HashMap;
import java.util.Map;
@@ -121,17 +120,11 @@
}
URL cxfURL = null;
- try
- {
- // get resource URL
- ArchiveDeployment archDep = (ArchiveDeployment)dep;
- cxfURL = archDep.getResourceResolver().resolve(metadir + "/" + Constants.JBOSSWS_CXF_SPRING_DD);
+ //get resource URL
+ ArchiveDeployment archDep = (ArchiveDeployment)dep;
+ cxfURL = archDep.getResourceResolver().resolveFailSafe(metadir + "/" + Constants.JBOSSWS_CXF_SPRING_DD);
+ if (cxfURL != null)
DEPLOYMENT_LOGGER.jbwscxfConfFound(cxfURL);
- }
- catch (IOException ignore)
- {
- // resource not found
- }
return cxfURL;
}
Modified: stack/cxf/trunk/modules/server/src/main/java/org/jboss/wsf/stack/cxf/metadata/MetadataBuilder.java
===================================================================
--- stack/cxf/trunk/modules/server/src/main/java/org/jboss/wsf/stack/cxf/metadata/MetadataBuilder.java 2012-12-19 07:58:54 UTC (rev 17134)
+++ stack/cxf/trunk/modules/server/src/main/java/org/jboss/wsf/stack/cxf/metadata/MetadataBuilder.java 2012-12-19 08:08:14 UTC (rev 17135)
@@ -276,24 +276,23 @@
wsdlLocation = ddep.getAnnotationWsdlLocation();
}
if (wsdlLocation != null) {
- try {
- URL wsdlUrl = dep.getResourceResolver().resolve(wsdlLocation);
-
- SOAPAddressWSDLParser parser = getCurrentSOAPAddressWSDLParser(wsdlUrl, soapAddressWsdlParsers);
- //do not try rewriting addresses for not-http binding
- String wsdlAddress = parser.filterSoapAddress(ddep.getServiceName(), ddep.getPortName(), SOAPAddressWSDLParser.SOAP_HTTP_NS);
-
- final ServerConfig sc = AbstractServerConfig.getServerIntegrationServerConfig();
- String rewrittenWsdlAddress = SoapAddressRewriteHelper.getRewrittenPublishedEndpointUrl(wsdlAddress, ddep.getAddress(), sc);
- //If "auto rewrite", leave "publishedEndpointUrl" unset so that CXF do not force host/port values for
- //wsdl imports and auto-rewrite them too; otherwise set the new address into "publishedEndpointUrl",
- //which causes CXF to override any address in the published wsdl.
- if (!SoapAddressRewriteHelper.isAutoRewriteOn(sc)) {
- ddep.setPublishedEndpointUrl(rewrittenWsdlAddress);
+ URL wsdlUrl = dep.getResourceResolver().resolveFailSafe(wsdlLocation);
+ if (wsdlUrl != null) {
+ SOAPAddressWSDLParser parser = getCurrentSOAPAddressWSDLParser(wsdlUrl, soapAddressWsdlParsers);
+ //do not try rewriting addresses for not-http binding
+ String wsdlAddress = parser.filterSoapAddress(ddep.getServiceName(), ddep.getPortName(), SOAPAddressWSDLParser.SOAP_HTTP_NS);
+
+ final ServerConfig sc = AbstractServerConfig.getServerIntegrationServerConfig();
+ String rewrittenWsdlAddress = SoapAddressRewriteHelper.getRewrittenPublishedEndpointUrl(wsdlAddress, ddep.getAddress(), sc);
+ //If "auto rewrite", leave "publishedEndpointUrl" unset so that CXF do not force host/port values for
+ //wsdl imports and auto-rewrite them too; otherwise set the new address into "publishedEndpointUrl",
+ //which causes CXF to override any address in the published wsdl.
+ if (!SoapAddressRewriteHelper.isAutoRewriteOn(sc)) {
+ ddep.setPublishedEndpointUrl(rewrittenWsdlAddress);
+ }
+ } else {
+ METADATA_LOGGER.abortSoapAddressRewrite(wsdlLocation, null);
}
- } catch (IOException e) {
- METADATA_LOGGER.abortSoapAddressRewrite(wsdlLocation, e);
- }
}
}
Modified: stack/cxf/trunk/modules/server/src/main/java/org/jboss/wsf/stack/cxf/resolver/JBossWSResourceResolver.java
===================================================================
--- stack/cxf/trunk/modules/server/src/main/java/org/jboss/wsf/stack/cxf/resolver/JBossWSResourceResolver.java 2012-12-19 07:58:54 UTC (rev 17134)
+++ stack/cxf/trunk/modules/server/src/main/java/org/jboss/wsf/stack/cxf/resolver/JBossWSResourceResolver.java 2012-12-19 08:08:14 UTC (rev 17135)
@@ -1,6 +1,6 @@
/*
* JBoss, Home of Professional Open Source.
- * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * Copyright 2012, Red Hat Middleware LLC, and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
@@ -65,16 +65,10 @@
public <T> T resolve(String resourcePath, Class<T> resourceType)
{
- URL url = null;
- try
- {
- url = resolver.resolve(resourcePath);
+ URL url = resolver.resolveFailSafe(resourcePath);
+ if (url == null && Loggers.ROOT_LOGGER.isDebugEnabled()) {
+ Loggers.ROOT_LOGGER.cannotResolveResource(JBossWSResourceResolver.class.getSimpleName(), resourcePath);
}
- catch (IOException ioe)
- {
- if (Loggers.ROOT_LOGGER.isDebugEnabled())
- Loggers.ROOT_LOGGER.cannotResolveResource(JBossWSResourceResolver.class.getSimpleName(), resourcePath);
- }
if (url != null && resourceType.isInstance(url))
{
return resourceType.cast(url);
12 years, 1 month
JBossWS SVN: r17134 - in container/jboss71/branches/jbossws-jboss712/server-integration/src/main/java/org/jboss/as/webservices: deployers and 1 other directories.
by jbossws-commits@lists.jboss.org
Author: alessio.soldano(a)jboss.com
Date: 2012-12-19 02:58:54 -0500 (Wed, 19 Dec 2012)
New Revision: 17134
Modified:
container/jboss71/branches/jbossws-jboss712/server-integration/src/main/java/org/jboss/as/webservices/WSLogger.java
container/jboss71/branches/jbossws-jboss712/server-integration/src/main/java/org/jboss/as/webservices/deployers/WSIntegrationProcessorJAXWS_JMS.java
container/jboss71/branches/jbossws-jboss712/server-integration/src/main/java/org/jboss/as/webservices/util/VirtualFileAdaptor.java
Log:
[JBWS-3551] Impl failsafe methods
Modified: container/jboss71/branches/jbossws-jboss712/server-integration/src/main/java/org/jboss/as/webservices/WSLogger.java
===================================================================
--- container/jboss71/branches/jbossws-jboss712/server-integration/src/main/java/org/jboss/as/webservices/WSLogger.java 2012-12-19 07:55:44 UTC (rev 17133)
+++ container/jboss71/branches/jbossws-jboss712/server-integration/src/main/java/org/jboss/as/webservices/WSLogger.java 2012-12-19 07:58:54 UTC (rev 17134)
@@ -1,6 +1,6 @@
/*
* JBoss, Home of Professional Open Source.
- * Copyright 2011, Red Hat, Inc., and individual contributors
+ * Copyright 2012, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
@@ -40,6 +40,7 @@
/**
* @author <a href="mailto:ropalka@redhat.com">Richard Opalka</a>
+ * @author <a href="mailto:alessio.soldano@jboss.com">Alessio Soldano</a>
*/
@MessageLogger(projectCode = "JBAS")
public interface WSLogger extends BasicLogger {
@@ -262,4 +263,8 @@
@Message(id = 15596, value = "Multiple EJB3 endpoints in the same deployment with different declared security roles; be aware this might be a security risk if you're not controlling allowed roles (@RolesAllowed) on each ws endpoint method.")
void multipleEndpointsWithDifferentDeclaredSecurityRoles();
+ @LogMessage(level = TRACE)
+ @Message(id = 15597, value = "Child '%s' not found for VirtualFile: %s")
+ void missingChild(String child, VirtualFile file);
+
}
\ No newline at end of file
Modified: container/jboss71/branches/jbossws-jboss712/server-integration/src/main/java/org/jboss/as/webservices/deployers/WSIntegrationProcessorJAXWS_JMS.java
===================================================================
--- container/jboss71/branches/jbossws-jboss712/server-integration/src/main/java/org/jboss/as/webservices/deployers/WSIntegrationProcessorJAXWS_JMS.java 2012-12-19 07:55:44 UTC (rev 17133)
+++ container/jboss71/branches/jbossws-jboss712/server-integration/src/main/java/org/jboss/as/webservices/deployers/WSIntegrationProcessorJAXWS_JMS.java 2012-12-19 07:58:54 UTC (rev 17134)
@@ -99,11 +99,12 @@
if (!map.isEmpty()) {
for (String wsdlLocation : map.keySet()) {
- try {
- final ResourceRoot resourceRoot = getWsdlResourceRoot(unit, wsdlLocation);
- if (resourceRoot == null) continue;
- final UnifiedVirtualFile uvf = new VirtualFileAdaptor(resourceRoot.getRoot());
- URL url = uvf.findChild(wsdlLocation).toURL();
+ final ResourceRoot resourceRoot = getWsdlResourceRoot(unit, wsdlLocation);
+ if (resourceRoot == null) continue;
+ final UnifiedVirtualFile uvf = new VirtualFileAdaptor(resourceRoot.getRoot());
+ UnifiedVirtualFile childUvf = uvf.findChildFailSafe(wsdlLocation);
+ if (childUvf != null) {
+ URL url = childUvf.toURL();
SOAPAddressWSDLParser parser = new SOAPAddressWSDLParser(url);
for (AnnotationInstance ai : map.get(wsdlLocation)) {
String port = ai.value(PORT_NAME).asString();
@@ -127,7 +128,7 @@
endpointsMetaData.addEndpointMetaData(endpointMetaData);
}
}
- } catch (Exception ignore) {
+ } else {
ROOT_LOGGER.cannotReadWsdl(wsdlLocation);
}
}
@@ -141,7 +142,7 @@
// NOOP
}
- private static ResourceRoot getWsdlResourceRoot(final DeploymentUnit unit, final String wsdlPath) throws MalformedURLException {
+ private static ResourceRoot getWsdlResourceRoot(final DeploymentUnit unit, final String wsdlPath) {
final AttachmentList<ResourceRoot> resourceRoots = new AttachmentList<ResourceRoot>(ResourceRoot.class);
final ResourceRoot root = unit.getAttachment(DEPLOYMENT_ROOT);
resourceRoots.add(root);
Modified: container/jboss71/branches/jbossws-jboss712/server-integration/src/main/java/org/jboss/as/webservices/util/VirtualFileAdaptor.java
===================================================================
--- container/jboss71/branches/jbossws-jboss712/server-integration/src/main/java/org/jboss/as/webservices/util/VirtualFileAdaptor.java 2012-12-19 07:55:44 UTC (rev 17133)
+++ container/jboss71/branches/jbossws-jboss712/server-integration/src/main/java/org/jboss/as/webservices/util/VirtualFileAdaptor.java 2012-12-19 07:58:54 UTC (rev 17134)
@@ -1,6 +1,6 @@
/*
* JBoss, Home of Professional Open Source
- * Copyright 2010, JBoss Inc., and individual contributors as indicated
+ * Copyright 2012, JBoss Inc., and individual contributors as indicated
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
@@ -22,6 +22,7 @@
package org.jboss.as.webservices.util;
import static org.jboss.as.webservices.WSMessages.MESSAGES;
+import static org.jboss.as.webservices.WSLogger.ROOT_LOGGER;
import java.io.IOException;
import java.net.URL;
@@ -52,14 +53,32 @@
return file;
}
- public UnifiedVirtualFile findChild(String child) throws IOException {
+ private UnifiedVirtualFile findChild(String child, boolean throwExceptionIfNotFound) throws IOException {
final VirtualFile virtualFile = getFile();
final VirtualFile childFile = file.getChild(child);
- if (!childFile.exists())
- throw MESSAGES.missingChild(child, virtualFile);
+ if (!childFile.exists()) {
+ if (throwExceptionIfNotFound) {
+ throw MESSAGES.missingChild(child, virtualFile);
+ } else {
+ if (ROOT_LOGGER.isTraceEnabled()) ROOT_LOGGER.missingChild(child, virtualFile);
+ return null;
+ }
+ }
return new VirtualFileAdaptor(childFile);
}
+
+ public UnifiedVirtualFile findChild(String child) throws IOException {
+ return findChild(child, true);
+ }
+ public UnifiedVirtualFile findChildFailSafe(String child) {
+ try {
+ return findChild(child, false);
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
public URL toURL() {
try {
return getFile().toURL();
12 years, 1 month
JBossWS SVN: r17133 - in container/jboss71/branches/jbossws-jboss713/server-integration/src/main/java/org/jboss/as/webservices: deployers and 1 other directories.
by jbossws-commits@lists.jboss.org
Author: alessio.soldano(a)jboss.com
Date: 2012-12-19 02:55:44 -0500 (Wed, 19 Dec 2012)
New Revision: 17133
Modified:
container/jboss71/branches/jbossws-jboss713/server-integration/src/main/java/org/jboss/as/webservices/WSLogger.java
container/jboss71/branches/jbossws-jboss713/server-integration/src/main/java/org/jboss/as/webservices/deployers/WSIntegrationProcessorJAXWS_JMS.java
container/jboss71/branches/jbossws-jboss713/server-integration/src/main/java/org/jboss/as/webservices/util/VirtualFileAdaptor.java
Log:
[JBWS-3551] Impl failsafe methods
Modified: container/jboss71/branches/jbossws-jboss713/server-integration/src/main/java/org/jboss/as/webservices/WSLogger.java
===================================================================
--- container/jboss71/branches/jbossws-jboss713/server-integration/src/main/java/org/jboss/as/webservices/WSLogger.java 2012-12-19 07:47:36 UTC (rev 17132)
+++ container/jboss71/branches/jbossws-jboss713/server-integration/src/main/java/org/jboss/as/webservices/WSLogger.java 2012-12-19 07:55:44 UTC (rev 17133)
@@ -1,6 +1,6 @@
/*
* JBoss, Home of Professional Open Source.
- * Copyright 2011, Red Hat, Inc., and individual contributors
+ * Copyright 20112 Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
@@ -40,6 +40,7 @@
/**
* @author <a href="mailto:ropalka@redhat.com">Richard Opalka</a>
+ * @author <a href="mailto:alessio.soldano@jboss.com">Alessio Soldano</a>
*/
@MessageLogger(projectCode = "JBAS")
public interface WSLogger extends BasicLogger {
@@ -261,5 +262,9 @@
@LogMessage(level = WARN)
@Message(id = 15596, value = "Multiple EJB3 endpoints in the same deployment with different declared security roles; be aware this might be a security risk if you're not controlling allowed roles (@RolesAllowed) on each ws endpoint method.")
void multipleEndpointsWithDifferentDeclaredSecurityRoles();
+
+ @LogMessage(level = TRACE)
+ @Message(id = 15597, value = "Child '%s' not found for VirtualFile: %s")
+ void missingChild(String child, VirtualFile file);
}
\ No newline at end of file
Modified: container/jboss71/branches/jbossws-jboss713/server-integration/src/main/java/org/jboss/as/webservices/deployers/WSIntegrationProcessorJAXWS_JMS.java
===================================================================
--- container/jboss71/branches/jbossws-jboss713/server-integration/src/main/java/org/jboss/as/webservices/deployers/WSIntegrationProcessorJAXWS_JMS.java 2012-12-19 07:47:36 UTC (rev 17132)
+++ container/jboss71/branches/jbossws-jboss713/server-integration/src/main/java/org/jboss/as/webservices/deployers/WSIntegrationProcessorJAXWS_JMS.java 2012-12-19 07:55:44 UTC (rev 17133)
@@ -99,11 +99,12 @@
if (!map.isEmpty()) {
for (String wsdlLocation : map.keySet()) {
- try {
- final ResourceRoot resourceRoot = getWsdlResourceRoot(unit, wsdlLocation);
- if (resourceRoot == null) continue;
- final UnifiedVirtualFile uvf = new VirtualFileAdaptor(resourceRoot.getRoot());
- URL url = uvf.findChild(wsdlLocation).toURL();
+ final ResourceRoot resourceRoot = getWsdlResourceRoot(unit, wsdlLocation);
+ if (resourceRoot == null) continue;
+ final UnifiedVirtualFile uvf = new VirtualFileAdaptor(resourceRoot.getRoot());
+ UnifiedVirtualFile childUvf = uvf.findChildFailSafe(wsdlLocation);
+ if (childUvf != null) {
+ URL url = childUvf.toURL();
SOAPAddressWSDLParser parser = new SOAPAddressWSDLParser(url);
for (AnnotationInstance ai : map.get(wsdlLocation)) {
String port = ai.value(PORT_NAME).asString();
@@ -127,7 +128,7 @@
endpointsMetaData.addEndpointMetaData(endpointMetaData);
}
}
- } catch (Exception ignore) {
+ } else {
ROOT_LOGGER.cannotReadWsdl(wsdlLocation);
}
}
@@ -141,7 +142,7 @@
// NOOP
}
- private static ResourceRoot getWsdlResourceRoot(final DeploymentUnit unit, final String wsdlPath) throws MalformedURLException {
+ private static ResourceRoot getWsdlResourceRoot(final DeploymentUnit unit, final String wsdlPath) {
final AttachmentList<ResourceRoot> resourceRoots = new AttachmentList<ResourceRoot>(ResourceRoot.class);
final ResourceRoot root = unit.getAttachment(DEPLOYMENT_ROOT);
resourceRoots.add(root);
Modified: container/jboss71/branches/jbossws-jboss713/server-integration/src/main/java/org/jboss/as/webservices/util/VirtualFileAdaptor.java
===================================================================
--- container/jboss71/branches/jbossws-jboss713/server-integration/src/main/java/org/jboss/as/webservices/util/VirtualFileAdaptor.java 2012-12-19 07:47:36 UTC (rev 17132)
+++ container/jboss71/branches/jbossws-jboss713/server-integration/src/main/java/org/jboss/as/webservices/util/VirtualFileAdaptor.java 2012-12-19 07:55:44 UTC (rev 17133)
@@ -1,6 +1,6 @@
/*
* JBoss, Home of Professional Open Source
- * Copyright 2010, JBoss Inc., and individual contributors as indicated
+ * Copyright 2012, JBoss Inc., and individual contributors as indicated
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
@@ -22,6 +22,7 @@
package org.jboss.as.webservices.util;
import static org.jboss.as.webservices.WSMessages.MESSAGES;
+import static org.jboss.as.webservices.WSLogger.ROOT_LOGGER;
import java.io.IOException;
import java.net.URL;
@@ -52,14 +53,32 @@
return file;
}
- public UnifiedVirtualFile findChild(String child) throws IOException {
+ private UnifiedVirtualFile findChild(String child, boolean throwExceptionIfNotFound) throws IOException {
final VirtualFile virtualFile = getFile();
final VirtualFile childFile = file.getChild(child);
- if (!childFile.exists())
- throw MESSAGES.missingChild(child, virtualFile);
+ if (!childFile.exists()) {
+ if (throwExceptionIfNotFound) {
+ throw MESSAGES.missingChild(child, virtualFile);
+ } else {
+ if (ROOT_LOGGER.isTraceEnabled()) ROOT_LOGGER.missingChild(child, virtualFile);
+ return null;
+ }
+ }
return new VirtualFileAdaptor(childFile);
}
+ public UnifiedVirtualFile findChild(String child) throws IOException {
+ return findChild(child, true);
+ }
+
+ public UnifiedVirtualFile findChildFailSafe(String child) {
+ try {
+ return findChild(child, false);
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
public URL toURL() {
try {
return getFile().toURL();
12 years, 1 month
JBossWS SVN: r17132 - in common/trunk/src: main/java/org/jboss/ws/common/deployment and 1 other directories.
by jbossws-commits@lists.jboss.org
Author: alessio.soldano(a)jboss.com
Date: 2012-12-19 02:47:36 -0500 (Wed, 19 Dec 2012)
New Revision: 17132
Modified:
common/trunk/src/main/java/org/jboss/ws/common/Loggers.java
common/trunk/src/main/java/org/jboss/ws/common/ResourceLoaderAdapter.java
common/trunk/src/main/java/org/jboss/ws/common/deployment/JAXBIntroDeploymentAspect.java
common/trunk/src/main/java/org/jboss/ws/common/deployment/ResourceResolverImpl.java
common/trunk/src/test/java/org/jboss/test/ws/common/ResourceLoaderAdapterTestCase.java
common/trunk/src/test/java/org/jboss/test/ws/common/URLLoaderAdapterTestCase.java
Log:
[JBWS-3551] Impl failsafe methods
Modified: common/trunk/src/main/java/org/jboss/ws/common/Loggers.java
===================================================================
--- common/trunk/src/main/java/org/jboss/ws/common/Loggers.java 2012-12-19 07:40:24 UTC (rev 17131)
+++ common/trunk/src/main/java/org/jboss/ws/common/Loggers.java 2012-12-19 07:47:36 UTC (rev 17132)
@@ -214,4 +214,12 @@
@LogMessage(level = TRACE)
@Message(id = 22114, value = "%s doesn't work on %s")
void aspectDoesNotWorkOnDeployment(Class<?> aspect, Class<?> deployment);
+
+ @LogMessage(level = TRACE)
+ @Message(id = 22115, value = "Cannot get URL for %s")
+ void cannotGetURLFor(String path);
+
+ @LogMessage(level = TRACE)
+ @Message(id = 22116, value = "Could not find %s in the additional metadatafiles")
+ void cannotFindInAdditionalMetaData(String resourcePath);
}
Modified: common/trunk/src/main/java/org/jboss/ws/common/ResourceLoaderAdapter.java
===================================================================
--- common/trunk/src/main/java/org/jboss/ws/common/ResourceLoaderAdapter.java 2012-12-19 07:40:24 UTC (rev 17131)
+++ common/trunk/src/main/java/org/jboss/ws/common/ResourceLoaderAdapter.java 2012-12-19 07:47:36 UTC (rev 17132)
@@ -68,7 +68,7 @@
this.loader = loader;
}
- public UnifiedVirtualFile findChild(String resourcePath) throws IOException
+ private UnifiedVirtualFile findChild(String resourcePath, boolean throwExceptionIfNotFound) throws IOException
{
URL resourceURL = null;
if (resourcePath != null)
@@ -113,11 +113,38 @@
}
if (resourceURL == null)
- throw MESSAGES.cannotGetURLFor(resourcePath);
+ {
+ if (throwExceptionIfNotFound)
+ {
+ throw MESSAGES.cannotGetURLFor(resourcePath);
+ }
+ else
+ {
+ if (ROOT_LOGGER.isTraceEnabled()) ROOT_LOGGER.cannotGetURLFor(resourcePath);
+ return null;
+ }
+ }
return new ResourceLoaderAdapter(loader, resourceURL);
}
+ public UnifiedVirtualFile findChild(String child) throws IOException
+ {
+ return findChild(child, true);
+ }
+
+ public UnifiedVirtualFile findChildFailSafe(String child)
+ {
+ try
+ {
+ return findChild(child, false);
+ }
+ catch (IOException e)
+ {
+ throw new RuntimeException(e);
+ }
+ }
+
public URL toURL()
{
if (null == this.resourceURL)
Modified: common/trunk/src/main/java/org/jboss/ws/common/deployment/JAXBIntroDeploymentAspect.java
===================================================================
--- common/trunk/src/main/java/org/jboss/ws/common/deployment/JAXBIntroDeploymentAspect.java 2012-12-19 07:40:24 UTC (rev 17131)
+++ common/trunk/src/main/java/org/jboss/ws/common/deployment/JAXBIntroDeploymentAspect.java 2012-12-19 07:47:36 UTC (rev 17132)
@@ -63,9 +63,11 @@
try
{
// META-INF first
- UnifiedVirtualFile vfs = archive.getRootFile().findChild(META_INF_JAXB_INTROS_XML);
- url = vfs.toURL();
- introsConfigStream = url.openStream();
+ UnifiedVirtualFile vfs = archive.getRootFile().findChildFailSafe(META_INF_JAXB_INTROS_XML);
+ if (vfs != null) {
+ url = vfs.toURL();
+ introsConfigStream = url.openStream();
+ }
} catch (Exception e) {}
if(null == introsConfigStream)
@@ -73,9 +75,11 @@
try
{
// WEB-INF second
- UnifiedVirtualFile vfs = archive.getRootFile().findChild(WEB_INF_JAXB_INTROS_XML);
- url = vfs.toURL();
- introsConfigStream = url.openStream();
+ UnifiedVirtualFile vfs = archive.getRootFile().findChildFailSafe(WEB_INF_JAXB_INTROS_XML);
+ if (vfs != null) {
+ url = vfs.toURL();
+ introsConfigStream = url.openStream();
+ }
} catch (Exception e) {
return;
}
Modified: common/trunk/src/main/java/org/jboss/ws/common/deployment/ResourceResolverImpl.java
===================================================================
--- common/trunk/src/main/java/org/jboss/ws/common/deployment/ResourceResolverImpl.java 2012-12-19 07:40:24 UTC (rev 17131)
+++ common/trunk/src/main/java/org/jboss/ws/common/deployment/ResourceResolverImpl.java 2012-12-19 07:47:36 UTC (rev 17132)
@@ -1,6 +1,6 @@
/*
* JBoss, Home of Professional Open Source.
- * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * Copyright 2012, Red Hat Middleware LLC, and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
@@ -124,4 +124,78 @@
return resourceURL;
}
+ public URL resolveFailSafe(String resourcePath)
+ {
+ final boolean traceEnabled = ROOT_LOGGER.isTraceEnabled();
+ URL resourceURL = null;
+ if (resourcePath != null && resourcePath.length() > 0)
+ {
+ if (resourcePath.startsWith("/"))
+ resourcePath = resourcePath.substring(1);
+
+ try
+ {
+ // assign an absolute URL
+ resourceURL = new URL(resourcePath);
+ }
+ catch (MalformedURLException ex)
+ {
+ // ignore
+ }
+
+ if (resourceURL == null && rootFile != null)
+ {
+ UnifiedVirtualFile vfResource = rootFile.findChildFailSafe(resourcePath);
+ if (vfResource == null)
+ {
+ if (metadataFiles == null || metadataFiles.isEmpty())
+ {
+ if (traceEnabled) ROOT_LOGGER.cannotGetRootResourceFrom(resourcePath, rootFile, null);
+ }
+ else
+ {
+ if (traceEnabled) ROOT_LOGGER.cannotGetRootFileTryingWithAdditionalMetaData(resourcePath);
+ }
+ }
+ else
+ {
+ resourceURL = vfResource.toURL();
+ }
+ }
+ //scan additional metadata files (for instance originally attached to a VFSDeploymentUnit)
+ if (resourceURL == null && metadataFiles != null && !metadataFiles.isEmpty())
+ {
+ UnifiedVirtualFile vfResource = null;
+ for (Iterator<UnifiedVirtualFile> it = metadataFiles.iterator(); it.hasNext() && vfResource == null;)
+ {
+ UnifiedVirtualFile uvf = it.next();
+ URL wsdlUrl = uvf.toURL();
+ String wsdlPath = wsdlUrl.getPath();
+ if (wsdlPath.startsWith("/"))
+ wsdlPath = wsdlPath.substring(1);
+ if (resourcePath.equals(wsdlPath))
+ {
+ vfResource = uvf;
+ }
+ else
+ {
+ vfResource = uvf.findChildFailSafe(resourcePath);
+ if (traceEnabled && vfResource == null) {
+ ROOT_LOGGER.cannotGetRootResourceFrom(resourcePath, uvf, null);
+ }
+ }
+ }
+ if (vfResource == null)
+ {
+ if (traceEnabled) ROOT_LOGGER.cannotFindInAdditionalMetaData(resourcePath);
+ }
+ else
+ {
+ resourceURL = vfResource.toURL();
+ }
+ }
+ }
+ return resourceURL;
+ }
+
}
Modified: common/trunk/src/test/java/org/jboss/test/ws/common/ResourceLoaderAdapterTestCase.java
===================================================================
--- common/trunk/src/test/java/org/jboss/test/ws/common/ResourceLoaderAdapterTestCase.java 2012-12-19 07:40:24 UTC (rev 17131)
+++ common/trunk/src/test/java/org/jboss/test/ws/common/ResourceLoaderAdapterTestCase.java 2012-12-19 07:47:36 UTC (rev 17132)
@@ -1,6 +1,6 @@
/*
* JBoss, Home of Professional Open Source.
- * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * Copyright 2012, Red Hat Middleware LLC, and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
@@ -21,6 +21,7 @@
*/
package org.jboss.test.ws.common;
+import java.io.IOException;
import java.util.List;
import junit.framework.TestCase;
@@ -85,4 +86,22 @@
assertNotNull(utils);
assertTrue(resourceLoaderAdapter.getChildren().size() == 0);
}
+
+ public void testFailSafeGetChild()
+ {
+ ClassLoader cl = UnifiedVirtualFile.class.getClassLoader();
+ ResourceLoaderAdapter ula = new ResourceLoaderAdapter(cl);
+ try {
+ ula.findChild("foo/bar/");
+ fail("IOException expected");
+ } catch (IOException e) {
+ //expected
+ }
+ try {
+ UnifiedVirtualFile uvf = ula.findChildFailSafe("foo/bar/");
+ assertNull(uvf);
+ } catch (Exception e) {
+ fail("Exception not expected, 'null' should have been returned instead: " + e.getMessage());
+ }
+ }
}
Modified: common/trunk/src/test/java/org/jboss/test/ws/common/URLLoaderAdapterTestCase.java
===================================================================
--- common/trunk/src/test/java/org/jboss/test/ws/common/URLLoaderAdapterTestCase.java 2012-12-19 07:40:24 UTC (rev 17131)
+++ common/trunk/src/test/java/org/jboss/test/ws/common/URLLoaderAdapterTestCase.java 2012-12-19 07:47:36 UTC (rev 17132)
@@ -21,6 +21,7 @@
*/
package org.jboss.test.ws.common;
+import java.io.IOException;
import java.net.URL;
import java.util.List;
@@ -90,6 +91,26 @@
assertTrue(urlLoaderAdapter.getChildren().size() == 0);
}
+ public void testFailSafeGetChild() throws Exception
+ {
+ ClassLoader cl = UnifiedVirtualFile.class.getClassLoader();
+ URL rootURL = getJarUrl(cl.getResource("org/jboss/wsf/spi/deployment"));
+ assertNotNull(rootURL);
+ URLLoaderAdapter ula = new URLLoaderAdapter(rootURL);
+ try {
+ ula.findChild("foo/bar/");
+ fail("IOException expected");
+ } catch (IOException e) {
+ //expected
+ }
+ try {
+ UnifiedVirtualFile uvf = ula.findChildFailSafe("foo/bar/");
+ assertNull(uvf);
+ } catch (Exception e) {
+ fail("Exception not expected, 'null' should have been returned instead: " + e.getMessage());
+ }
+ }
+
private static URL getJarUrl(URL url) throws Exception
{
String urlString = url.toExternalForm();
12 years, 1 month