Author: dkulp
Date: Wed Aug 29 18:43:50 2007
New Revision: 571016
URL: http://svn.apache.org/viewvc?rev=571016&view=rev
Log:
[CXF-926, CXF-873] Fix fault element names on wire to make it match JAX-WS spec
if XmlRootElement annotation is on the details type
* Fix issue of multiple identical elements being created in schema for faults
* Possible fix for some Rest matching issues. If two operations return the
same "score", retry without the tail match to see if one matches furthur
without the tail then the others.
Modified:
incubator/cxf/trunk/rt/bindings/http/src/main/java/org/apache/cxf/binding/http/URIMapper.java
incubator/cxf/trunk/rt/bindings/http/src/test/java/org/apache/cxf/binding/http/bare/BareServiceTest.java
incubator/cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBSchemaInitializer.java
incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/interceptors/WebFaultOutInterceptor.java
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxws/ClientServerMiscTest.java
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxws/ServiceTestFault.java
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/servlet/HttpBindingServletTest.java
Modified:
incubator/cxf/trunk/rt/bindings/http/src/main/java/org/apache/cxf/binding/http/URIMapper.java
URL:
http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/bindings/http/src/main/java/org/apache/cxf/binding/http/URIMapper.java?rev=571016&r1=571015&r2=571016&view=diff
==============================================================================
---
incubator/cxf/trunk/rt/bindings/http/src/main/java/org/apache/cxf/binding/http/URIMapper.java
(original)
+++
incubator/cxf/trunk/rt/bindings/http/src/main/java/org/apache/cxf/binding/http/URIMapper.java
Wed Aug 29 18:43:50 2007
@@ -38,20 +38,42 @@
new HashMap<OperationInfo, String>();
public BindingOperationInfo getOperation(String uri, String verb, Message
m) {
- ResourceInfo bestMatch = null;
+ List<ResourceInfo> bestMatch = new ArrayList<ResourceInfo>();
int bestScore = 0;
for (ResourceInfo r : resources) {
if (r.getVerb().equals(verb)) {
int newScore = ResourceUtil.getMatchScore(uri, r.getUri());
if (newScore > bestScore) {
- bestMatch = r;
+ bestMatch.clear();
bestScore = newScore;
}
+ if (newScore >= bestScore) {
+ bestMatch.add(r);
+ }
}
}
- if (bestScore > -1 && bestMatch != null) {
- return bestMatch.getOperation();
+ if (bestScore > -1 && !bestMatch.isEmpty()) {
+ if (bestMatch.size() == 1) {
+ return bestMatch.get(0).getOperation();
+ }
+
+ //two or more with the same score... find the one with longest
match
+ // NOT counting any tail match
+ bestScore = -1;
+ ResourceInfo newBest = null;
+ for (ResourceInfo r : bestMatch) {
+ String newUri = r.getUri();
+ if (newUri.charAt(newUri.length() - 1) == '}') {
+ newUri = newUri.substring(0, newUri.lastIndexOf('{'));
+ }
+ int newScore = ResourceUtil.getMatchScore(uri, newUri);
+ if (newScore > bestScore) {
+ bestScore = newScore;
+ newBest = r;
+ }
+ }
+ return newBest.getOperation();
}
return null;
Modified:
incubator/cxf/trunk/rt/bindings/http/src/test/java/org/apache/cxf/binding/http/bare/BareServiceTest.java
URL:
http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/bindings/http/src/test/java/org/apache/cxf/binding/http/bare/BareServiceTest.java?rev=571016&r1=571015&r2=571016&view=diff
==============================================================================
---
incubator/cxf/trunk/rt/bindings/http/src/test/java/org/apache/cxf/binding/http/bare/BareServiceTest.java
(original)
+++
incubator/cxf/trunk/rt/bindings/http/src/test/java/org/apache/cxf/binding/http/bare/BareServiceTest.java
Wed Aug 29 18:43:50 2007
@@ -105,7 +105,7 @@
res = get("http://localhost:9001/foo/customers/0", 500);
assertNotNull(res);
- assertValid("//c:CustomerNotFoundDetails", res);
+ assertValid("//c:CustomerNotFoundFault", res);
res = put("http://localhost:9001/foo/customers/123", "update.xml");
assertNotNull(res);
Modified:
incubator/cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBSchemaInitializer.java
URL:
http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBSchemaInitializer.java?rev=571016&r1=571015&r2=571016&view=diff
==============================================================================
---
incubator/cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBSchemaInitializer.java
(original)
+++
incubator/cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBSchemaInitializer.java
Wed Aug 29 18:43:50 2007
@@ -155,6 +155,7 @@
el = createXsElement(part, typeName, schemaInfo);
+ schemaInfo.getSchema().getElements().add(el.getQName(), el);
schemaInfo.getSchema().getItems().add(el);
return;
@@ -166,6 +167,7 @@
XmlSchema schema = new XmlSchema(qn.getNamespaceURI(), schemas);
schemaInfo.setSchema(schema);
+ schema.getElements().add(el.getQName(), el);
schema.getItems().add(el);
NamespaceMap nsMap = new NamespaceMap();
@@ -195,7 +197,8 @@
JaxBeanInfo<?> beanInfo = context.getBeanInfo(cls);
SchemaInfo schemaInfo = null;
for (SchemaInfo s : serviceInfo.getSchemas()) {
- if
(s.getNamespaceURI().equals(part.getElementQName().getNamespaceURI())) {
+ if
(s.getNamespaceURI().equals(part.getElementQName().getNamespaceURI())
+ && !isExistSchemaElement(s.getSchema(),
part.getElementQName())) {
schemaInfo = s;
XmlSchemaElement el = new XmlSchemaElement();
@@ -203,10 +206,9 @@
el.setName(part.getElementQName().getLocalPart());
el.setNillable(true);
- if (!isExistSchemaElement(schemaInfo.getSchema(),
part.getElementQName())) {
- schemaInfo.getSchema().getItems().add(el);
- }
-
+ schemaInfo.getSchema().getItems().add(el);
+ schemaInfo.getSchema().getElements().add(el.getQName(),
el);
+
Iterator<QName> itr = beanInfo.getTypeNames().iterator();
if (!itr.hasNext()) {
continue;
@@ -259,7 +261,8 @@
el.setQName(part.getElementQName());
el.setName(part.getElementQName().getLocalPart());
schema.getItems().add(el);
-
+ schema.getElements().add(el.getQName(), el);
+
schema.getItems().add(ct);
schema.addType(ct);
el.setSchemaTypeName(part.getElementQName());
Modified:
incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/interceptors/WebFaultOutInterceptor.java
URL:
http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/interceptors/WebFaultOutInterceptor.java?rev=571016&r1=571015&r2=571016&view=diff
==============================================================================
---
incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/interceptors/WebFaultOutInterceptor.java
(original)
+++
incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/interceptors/WebFaultOutInterceptor.java
Wed Aug 29 18:43:50 2007
@@ -31,6 +31,7 @@
import org.apache.cxf.common.i18n.BundleUtils;
import org.apache.cxf.common.logging.LogUtils;
+import org.apache.cxf.common.util.StringUtils;
import org.apache.cxf.databinding.DataWriter;
import org.apache.cxf.interceptor.Fault;
import org.apache.cxf.jaxws.support.JaxWsServiceConfiguration;
@@ -52,8 +53,16 @@
super(Phase.PRE_PROTOCOL);
}
- private QName getFaultName(WebFault wf) {
- return new QName(wf.targetNamespace(), wf.name());
+ private QName getFaultName(WebFault wf, Class<?> cls, OperationInfo op) {
+ String ns = wf.targetNamespace();
+ if (StringUtils.isEmpty(ns)) {
+ ns = op.getName().getNamespaceURI();
+ }
+ String name = wf.name();
+ if (StringUtils.isEmpty(name)) {
+ name = cls.getSimpleName();
+ }
+ return new QName(ns, name);
}
@@ -98,7 +107,7 @@
DataWriter<Node> writer =
service.getDataBinding().createWriter(Node.class);
OperationInfo op =
message.getExchange().get(BindingOperationInfo.class).getOperationInfo();
- QName faultName = getFaultName(fault);
+ QName faultName = getFaultName(fault, cause.getClass(), op);
MessagePartInfo part = getFaultMessagePart(faultName, op);
writer.write(faultInfo, part, f.getOrCreateDetail());
Modified:
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxws/ClientServerMiscTest.java
URL:
http://svn.apache.org/viewvc/incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxws/ClientServerMiscTest.java?rev=571016&r1=571015&r2=571016&view=diff
==============================================================================
---
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxws/ClientServerMiscTest.java
(original)
+++
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxws/ClientServerMiscTest.java
Wed Aug 29 18:43:50 2007
@@ -58,7 +58,7 @@
@BeforeClass
public static void startServers() throws Exception {
- assertTrue("server did not launch correctly",
launchServer(ServerMisc.class));
+ assertTrue("server did not launch correctly",
launchServer(ServerMisc.class, true));
}
@Test
@@ -262,15 +262,15 @@
assertEquals(3, ints.length);
assertEquals(1, ints[0]);
- /* CXF-926 test case - this should work, but doesn't right now
+ /* CXF-926 test case */
try {
port.throwException(10);
fail("Expected exception not found");
} catch (ServiceTestFault ex) {
assertEquals(10, ex.getFaultInfo().getId());
}
- */
}
+
@Test
public void testRpcLitNoWsdl() throws Exception {
Modified:
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxws/ServiceTestFault.java
URL:
http://svn.apache.org/viewvc/incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxws/ServiceTestFault.java?rev=571016&r1=571015&r2=571016&view=diff
==============================================================================
---
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxws/ServiceTestFault.java
(original)
+++
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxws/ServiceTestFault.java
Wed Aug 29 18:43:50 2007
@@ -21,7 +21,7 @@
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.ws.WebFault;
[EMAIL PROTECTED](name = "ServiceTestFault")
[EMAIL PROTECTED]()
public class ServiceTestFault extends Exception {
private ServiceTestDetails details;
public ServiceTestFault(String msg, ServiceTestDetails details) {
Modified:
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/servlet/HttpBindingServletTest.java
URL:
http://svn.apache.org/viewvc/incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/servlet/HttpBindingServletTest.java?rev=571016&r1=571015&r2=571016&view=diff
==============================================================================
---
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/servlet/HttpBindingServletTest.java
(original)
+++
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/servlet/HttpBindingServletTest.java
Wed Aug 29 18:43:50 2007
@@ -92,7 +92,7 @@
doc = DOMUtils.readXml(response.getInputStream());
assertNotNull(doc);
- assertValid("//c:CustomerNotFoundDetails", doc);
+ assertValid("//c:CustomerNotFoundFault", doc);
PostMethodWebRequest postReq =
new PostMethodWebRequest(CONTEXT_URL + serviceAddress +
"/customers",