You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by da...@apache.org on 2006/11/10 02:28:36 UTC
svn commit: r473156 - in /incubator/cxf/trunk/rt:
bindings/http/src/main/java/org/apache/cxf/binding/http/
bindings/http/src/test/java/org/apache/cxf/binding/http/
bindings/http/src/test/java/org/apache/cxf/binding/http/bare/
bindings/xml/src/main/java...
Author: dandiep
Date: Thu Nov 9 17:28:35 2006
New Revision: 473156
URL: http://svn.apache.org/viewvc?view=rev&rev=473156
Log:
Add fault interceptors to HTTP binding. Also, clean up usage of getBeanClass() in the service factories. It seems my IDE refactoring went wild when I added that method originally and it was used in places it shouldn't be.
Added:
incubator/cxf/trunk/rt/bindings/http/src/test/java/org/apache/cxf/binding/http/CustomerNotFoundDetails.java (with props)
incubator/cxf/trunk/rt/bindings/http/src/test/java/org/apache/cxf/binding/http/CustomerNotFoundFault.java (with props)
Modified:
incubator/cxf/trunk/rt/bindings/http/src/main/java/org/apache/cxf/binding/http/HttpBindingFactory.java
incubator/cxf/trunk/rt/bindings/http/src/test/java/org/apache/cxf/binding/http/AbstractRestTest.java
incubator/cxf/trunk/rt/bindings/http/src/test/java/org/apache/cxf/binding/http/bare/BareServiceTest.java
incubator/cxf/trunk/rt/bindings/http/src/test/java/org/apache/cxf/binding/http/bare/CustomerService.java
incubator/cxf/trunk/rt/bindings/http/src/test/java/org/apache/cxf/binding/http/bare/GetCustomer.java
incubator/cxf/trunk/rt/bindings/xml/src/main/java/org/apache/cxf/binding/xml/interceptor/XMLFaultOutInterceptor.java
incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/support/JaxWsServiceFactoryBean.java
incubator/cxf/trunk/rt/frontend/simple/src/main/java/org/apache/cxf/service/factory/ReflectionServiceFactoryBean.java
incubator/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/AbstractHTTPDestination.java
Modified: incubator/cxf/trunk/rt/bindings/http/src/main/java/org/apache/cxf/binding/http/HttpBindingFactory.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/bindings/http/src/main/java/org/apache/cxf/binding/http/HttpBindingFactory.java?view=diff&rev=473156&r1=473155&r2=473156
==============================================================================
--- incubator/cxf/trunk/rt/bindings/http/src/main/java/org/apache/cxf/binding/http/HttpBindingFactory.java (original)
+++ incubator/cxf/trunk/rt/bindings/http/src/main/java/org/apache/cxf/binding/http/HttpBindingFactory.java Thu Nov 9 17:28:35 2006
@@ -28,6 +28,8 @@
import org.apache.cxf.binding.Binding;
import org.apache.cxf.binding.BindingFactoryManager;
import org.apache.cxf.binding.xml.XMLBinding;
+import org.apache.cxf.binding.xml.interceptor.XMLFaultInInterceptor;
+import org.apache.cxf.binding.xml.interceptor.XMLFaultOutInterceptor;
import org.apache.cxf.binding.xml.interceptor.XMLMessageOutInterceptor;
import org.apache.cxf.interceptor.StaxOutInterceptor;
import org.apache.cxf.interceptor.WrappedOutInterceptor;
@@ -72,6 +74,12 @@
binding.getOutInterceptors().add(new ContentTypeOutInterceptor());
binding.getOutInterceptors().add(new WrappedOutInterceptor());
binding.getOutInterceptors().add(new XMLMessageOutInterceptor());
+
+
+ binding.getInFaultInterceptors().add(new XMLFaultInInterceptor());
+
+ binding.getOutFaultInterceptors().add(new StaxOutInterceptor());
+ binding.getOutFaultInterceptors().add(new XMLFaultOutInterceptor());
return binding;
}
Modified: incubator/cxf/trunk/rt/bindings/http/src/test/java/org/apache/cxf/binding/http/AbstractRestTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/bindings/http/src/test/java/org/apache/cxf/binding/http/AbstractRestTest.java?view=diff&rev=473156&r1=473155&r2=473156
==============================================================================
--- incubator/cxf/trunk/rt/bindings/http/src/test/java/org/apache/cxf/binding/http/AbstractRestTest.java (original)
+++ incubator/cxf/trunk/rt/bindings/http/src/test/java/org/apache/cxf/binding/http/AbstractRestTest.java Thu Nov 9 17:28:35 2006
@@ -47,10 +47,24 @@
protected Document get(String urlStr) throws MalformedURLException, IOException, SAXException,
ParserConfigurationException {
+ return get(urlStr, null);
+ }
+
+ protected Document get(String urlStr, Integer resCode)
+ throws MalformedURLException, IOException, SAXException,
+ ParserConfigurationException {
URL url = new URL(urlStr);
HttpURLConnection c = (HttpURLConnection)url.openConnection();
-
- InputStream is = c.getInputStream();
+
+ if (resCode != null) {
+ assertEquals(resCode.intValue(), c.getResponseCode());
+ }
+ InputStream is;
+ if (c.getResponseCode() >= 400) {
+ is = c.getErrorStream();
+ } else {
+ is = c.getInputStream();
+ }
return DOMUtils.readXml(is);
}
Added: incubator/cxf/trunk/rt/bindings/http/src/test/java/org/apache/cxf/binding/http/CustomerNotFoundDetails.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/bindings/http/src/test/java/org/apache/cxf/binding/http/CustomerNotFoundDetails.java?view=auto&rev=473156
==============================================================================
--- incubator/cxf/trunk/rt/bindings/http/src/test/java/org/apache/cxf/binding/http/CustomerNotFoundDetails.java (added)
+++ incubator/cxf/trunk/rt/bindings/http/src/test/java/org/apache/cxf/binding/http/CustomerNotFoundDetails.java Thu Nov 9 17:28:35 2006
@@ -0,0 +1,35 @@
+/**
+ * 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.binding.http;
+
+import javax.xml.bind.annotation.XmlRootElement;
+
+@XmlRootElement(name = "CustomerNotFoundDetails")
+public class CustomerNotFoundDetails {
+ private long id;
+
+ public long getId() {
+ return id;
+ }
+
+ public void setId(long id) {
+ this.id = id;
+ }
+
+}
Propchange: incubator/cxf/trunk/rt/bindings/http/src/test/java/org/apache/cxf/binding/http/CustomerNotFoundDetails.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/cxf/trunk/rt/bindings/http/src/test/java/org/apache/cxf/binding/http/CustomerNotFoundDetails.java
------------------------------------------------------------------------------
svn:executable = *
Propchange: incubator/cxf/trunk/rt/bindings/http/src/test/java/org/apache/cxf/binding/http/CustomerNotFoundDetails.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: incubator/cxf/trunk/rt/bindings/http/src/test/java/org/apache/cxf/binding/http/CustomerNotFoundFault.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/bindings/http/src/test/java/org/apache/cxf/binding/http/CustomerNotFoundFault.java?view=auto&rev=473156
==============================================================================
--- incubator/cxf/trunk/rt/bindings/http/src/test/java/org/apache/cxf/binding/http/CustomerNotFoundFault.java (added)
+++ incubator/cxf/trunk/rt/bindings/http/src/test/java/org/apache/cxf/binding/http/CustomerNotFoundFault.java Thu Nov 9 17:28:35 2006
@@ -0,0 +1,35 @@
+/**
+ * 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.binding.http;
+
+import javax.xml.ws.WebFault;
+
+@WebFault
+public class CustomerNotFoundFault extends Exception {
+ private CustomerNotFoundDetails details;
+
+ public CustomerNotFoundFault(CustomerNotFoundDetails details) {
+ super();
+ this.details = details;
+ }
+
+ public CustomerNotFoundDetails getFaultInfo() {
+ return details;
+ }
+}
Propchange: incubator/cxf/trunk/rt/bindings/http/src/test/java/org/apache/cxf/binding/http/CustomerNotFoundFault.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/cxf/trunk/rt/bindings/http/src/test/java/org/apache/cxf/binding/http/CustomerNotFoundFault.java
------------------------------------------------------------------------------
svn:executable = *
Propchange: incubator/cxf/trunk/rt/bindings/http/src/test/java/org/apache/cxf/binding/http/CustomerNotFoundFault.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
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?view=diff&rev=473156&r1=473155&r2=473156
==============================================================================
--- 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 Thu Nov 9 17:28:35 2006
@@ -82,10 +82,15 @@
res = get("http://localhost:9001/foo/customers/123");
assertNotNull(res);
- addNamespace("c", "http://cxf.apache.org/jra");
assertValid("/c:customer", res);
assertValid("/c:customer/c:id[text()='123']", res);
assertValid("/c:customer/c:name[text()='Dan Diephouse']", res);
+
+ // Try invalid customer
+ res = get("http://localhost:9001/foo/customers/0", 500);
+ assertNotNull(res);
+
+ assertValid("//c:CustomerNotFoundDetails", res);
res = put("http://localhost:9001/foo/customers/123", "update.xml");
assertNotNull(res);
Modified: incubator/cxf/trunk/rt/bindings/http/src/test/java/org/apache/cxf/binding/http/bare/CustomerService.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/bindings/http/src/test/java/org/apache/cxf/binding/http/bare/CustomerService.java?view=diff&rev=473156&r1=473155&r2=473156
==============================================================================
--- incubator/cxf/trunk/rt/bindings/http/src/test/java/org/apache/cxf/binding/http/bare/CustomerService.java (original)
+++ incubator/cxf/trunk/rt/bindings/http/src/test/java/org/apache/cxf/binding/http/bare/CustomerService.java Thu Nov 9 17:28:35 2006
@@ -26,6 +26,8 @@
import javax.jws.WebService;
import org.apache.cxf.binding.http.Customer;
+import org.apache.cxf.binding.http.CustomerNotFoundDetails;
+import org.apache.cxf.binding.http.CustomerNotFoundFault;
import org.apache.cxf.binding.http.Customers;
import org.codehaus.jra.Delete;
import org.codehaus.jra.Get;
@@ -56,8 +58,15 @@
@Get
@HttpResource(location = "/customers/{id}")
@WebMethod
- public Customer getCustomer(@WebParam(name = "GetCustomer") GetCustomer getCustomer) {
- return customers.get(new Long(getCustomer.getId()));
+ public Customer getCustomer(@WebParam(name = "GetCustomer") GetCustomer getCustomer)
+ throws CustomerNotFoundFault {
+ Customer c = customers.get(getCustomer.getId());
+ if (c == null) {
+ CustomerNotFoundDetails details = new CustomerNotFoundDetails();
+ details.setId(getCustomer.getId());
+ throw new CustomerNotFoundFault(details);
+ }
+ return c;
}
@Put
Modified: incubator/cxf/trunk/rt/bindings/http/src/test/java/org/apache/cxf/binding/http/bare/GetCustomer.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/bindings/http/src/test/java/org/apache/cxf/binding/http/bare/GetCustomer.java?view=diff&rev=473156&r1=473155&r2=473156
==============================================================================
--- incubator/cxf/trunk/rt/bindings/http/src/test/java/org/apache/cxf/binding/http/bare/GetCustomer.java (original)
+++ incubator/cxf/trunk/rt/bindings/http/src/test/java/org/apache/cxf/binding/http/bare/GetCustomer.java Thu Nov 9 17:28:35 2006
@@ -22,13 +22,13 @@
@XmlRootElement(name = "GetCustomer")
public class GetCustomer {
- private String id;
+ private long id;
- public String getId() {
+ public long getId() {
return id;
}
- public void setId(String id) {
+ public void setId(long id) {
this.id = id;
}
Modified: incubator/cxf/trunk/rt/bindings/xml/src/main/java/org/apache/cxf/binding/xml/interceptor/XMLFaultOutInterceptor.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/bindings/xml/src/main/java/org/apache/cxf/binding/xml/interceptor/XMLFaultOutInterceptor.java?view=diff&rev=473156&r1=473155&r2=473156
==============================================================================
--- incubator/cxf/trunk/rt/bindings/xml/src/main/java/org/apache/cxf/binding/xml/interceptor/XMLFaultOutInterceptor.java (original)
+++ incubator/cxf/trunk/rt/bindings/xml/src/main/java/org/apache/cxf/binding/xml/interceptor/XMLFaultOutInterceptor.java Thu Nov 9 17:28:35 2006
@@ -70,8 +70,8 @@
// call data writer to marshal exception
BindingOperationInfo bop = message.getExchange().get(BindingOperationInfo.class);
if (t != null && bop != null) {
- if (!bop.isUnwrappedCapable()) {
- bop = bop.getUnwrappedOperation();
+ if (bop.isUnwrapped()) {
+ bop = bop.getWrappedOperation();
}
Iterator<FaultInfo> it = bop.getOperationInfo().getFaults().iterator();
MessagePartInfo part = null;
Modified: incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/support/JaxWsServiceFactoryBean.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/support/JaxWsServiceFactoryBean.java?view=diff&rev=473156&r1=473155&r2=473156
==============================================================================
--- incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/support/JaxWsServiceFactoryBean.java (original)
+++ incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/support/JaxWsServiceFactoryBean.java Thu Nov 9 17:28:35 2006
@@ -153,19 +153,28 @@
}
if (mpi.getConcreteName().getLocalPart().equals(name.getLocalPart())
&& name.getNamespaceURI().equals(ns)) {
- try {
- Method method = beanClass.getMethod("getFaultInfo", new Class[0]);
- Class sub = method.getReturnType();
- fi.setProperty(Class.class.getName(), exClass);
- mpi.setTypeClass(sub);
- } catch (NoSuchMethodException nsme) {
- nsme.printStackTrace();
- }
+ fi.setProperty(Class.class.getName(), exClass);
+ mpi.setTypeClass(beanClass);
}
}
}
}
}
+
+
+ @Override
+ protected Class getBeanClass(Class exClass) {
+ try {
+ Method getFaultInfo = exClass.getMethod("getFaultInfo", new Class[0]);
+
+ return getFaultInfo.getReturnType();
+ } catch (SecurityException e) {
+ throw new ServiceConstructionException(e);
+ } catch (NoSuchMethodException e) {
+ return super.getBeanClass(exClass);
+ }
+ }
+
/**
* set the holder generic type info into message part info
*
Modified: incubator/cxf/trunk/rt/frontend/simple/src/main/java/org/apache/cxf/service/factory/ReflectionServiceFactoryBean.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/simple/src/main/java/org/apache/cxf/service/factory/ReflectionServiceFactoryBean.java?view=diff&rev=473156&r1=473155&r2=473156
==============================================================================
--- incubator/cxf/trunk/rt/frontend/simple/src/main/java/org/apache/cxf/service/factory/ReflectionServiceFactoryBean.java (original)
+++ incubator/cxf/trunk/rt/frontend/simple/src/main/java/org/apache/cxf/service/factory/ReflectionServiceFactoryBean.java Thu Nov 9 17:28:35 2006
@@ -601,7 +601,7 @@
protected FaultInfo addFault(final InterfaceInfo service, final OperationInfo op, Class exClass) {
Class beanClass = getBeanClass(exClass);
- QName faultName = getFaultName(service, op, getBeanClass(exClass), getBeanClass(beanClass));
+ QName faultName = getFaultName(service, op, exClass, beanClass);
FaultInfo fi = op.addFault(faultName, faultName);
fi.setProperty(Class.class.getName(), exClass);
@@ -618,7 +618,7 @@
protected QName getFaultName(InterfaceInfo service, OperationInfo o, Class exClass, Class beanClass) {
for (Iterator itr = serviceConfigurations.iterator(); itr.hasNext();) {
AbstractServiceConfiguration c = (AbstractServiceConfiguration)itr.next();
- QName q = c.getFaultName(service, o, getBeanClass(exClass), getBeanClass(beanClass));
+ QName q = c.getFaultName(service, o, exClass, beanClass);
if (q != null) {
return q;
}
@@ -750,8 +750,8 @@
protected Class getResponseWrapper(Method selected) {
for (AbstractServiceConfiguration c : serviceConfigurations) {
Class cls = c.getResponseWrapper(selected);
- if (getBeanClass(cls) != null) {
- return getBeanClass(cls);
+ if (cls != null) {
+ return cls;
}
}
return null;
@@ -759,8 +759,8 @@
protected Class getRequestWrapper(Method selected) {
for (AbstractServiceConfiguration c : serviceConfigurations) {
Class cls = c.getRequestWrapper(selected);
- if (getBeanClass(cls) != null) {
- return getBeanClass(cls);
+ if (cls != null) {
+ return cls;
}
}
return null;
Modified: incubator/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/AbstractHTTPDestination.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/AbstractHTTPDestination.java?view=diff&rev=473156&r1=473155&r2=473156
==============================================================================
--- incubator/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/AbstractHTTPDestination.java (original)
+++ incubator/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/AbstractHTTPDestination.java Thu Nov 9 17:28:35 2006
@@ -88,7 +88,10 @@
@Override
public String getBeanName() {
- return endpointInfo.getName().toString() + ".http-destination";
+ if (endpointInfo.getName() != null) {
+ return endpointInfo.getName().toString() + ".http-destination";
+ }
+ return null;
}