You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by jl...@apache.org on 2007/06/27 05:56:58 UTC
svn commit: r551026 - in /incubator/cxf/trunk:
rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/interceptors/
systests/src/test/java/org/apache/cxf/systest/handlers/
Author: jliu
Date: Tue Jun 26 20:56:57 2007
New Revision: 551026
URL: http://svn.apache.org/viewvc?view=rev&rev=551026
Log:
Refactored exceptions in DispatchOutInterceptor
Modified:
incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/interceptors/DispatchOutInterceptor.java
incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/interceptors/Messages.properties
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/handlers/DispatchHandlerInvocationTest.java
Modified: incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/interceptors/DispatchOutInterceptor.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/interceptors/DispatchOutInterceptor.java?view=diff&rev=551026&r1=551025&r2=551026
==============================================================================
--- incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/interceptors/DispatchOutInterceptor.java (original)
+++ incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/interceptors/DispatchOutInterceptor.java Tue Jun 26 20:56:57 2007
@@ -25,7 +25,6 @@
import java.util.logging.Logger;
import javax.activation.DataSource;
-import javax.xml.bind.JAXBElement;
import javax.xml.soap.MessageFactory;
import javax.xml.soap.SOAPException;
import javax.xml.soap.SOAPMessage;
@@ -71,64 +70,72 @@
throw new Fault(new org.apache.cxf.common.i18n.Message("DISPATCH_OBJECT_CANNOT_BE_NULL", LOG));
}
- try {
- if (message instanceof SoapMessage) {
- if (m == Service.Mode.PAYLOAD) {
- if (obj instanceof SOAPMessage || obj instanceof DataSource) {
- throw new RuntimeException(obj.getClass()
- + " is not valid in PAYLOAD mode with SOAP/HTTP binding");
- } else {
- // Input is Source or JAXB in payload mode, need to wrap it
- // with a SOAPMessage
+ if (message instanceof SoapMessage) {
+ if (m == Service.Mode.PAYLOAD) {
+ if (obj instanceof SOAPMessage || obj instanceof DataSource) {
+ throw new Fault(
+ new org.apache.cxf.common.i18n.Message(
+ "DISPATCH_OBJECT_NOT_SUPPORTED_SOAPBINDING",
+ LOG, obj.getClass(), "PAYLOAD"));
+ } else {
+ // Input is Source or JAXB in payload mode, need to wrap it
+ // with a SOAPMessage
+ try {
SOAPMessage msg = initSOAPMessage();
DataWriter<Node> dataWriter = getDataWriter(message, service, Node.class);
dataWriter.write(obj, msg.getSOAPBody());
message.setContent(Object.class, msg);
message.setContent(SOAPMessage.class, msg);
- }
- } else {
- if (obj instanceof DataSource) {
- throw new RuntimeException(
- "DataSource is not valid in MESSAGE mode with SOAP/HTTP binding");
- } else if (obj instanceof JAXBElement) {
- // REVISIT: Not sure if this is a valid combination
- } else {
- //Input is Source or SOAPMessage, no conversion needed
+ } catch (SOAPException e) {
+ throw new Fault(new org.apache.cxf.common.i18n.Message("EXCEPTION_WRITING_OBJECT",
+ LOG), e);
}
}
- } else if (message instanceof XMLMessage) {
- if (obj instanceof SOAPMessage) {
- throw new RuntimeException("SOAPMessage is not valid with XML/HTTP binding");
+ } else {
+ if (obj instanceof DataSource) {
+ throw new Fault(
+ new org.apache.cxf.common.i18n.Message(
+ "DISPATCH_OBJECT_NOT_SUPPORTED_SOAPBINDING",
+ LOG, "DataSource", "MESSAGE"));
+ } else if (obj instanceof Source || obj instanceof SOAPMessage) {
+ // Input is Source or SOAPMessage, no conversion needed
+ } else {
+ //REVISIT: JAXB element in Message mode, is this a valid input?
}
+ }
+ } else if (message instanceof XMLMessage) {
+ if (obj instanceof SOAPMessage) {
+ throw new Fault(
+ new org.apache.cxf.common.i18n.Message(
+ "DISPATCH_OBJECT_NOT_SUPPORTED_XMLBINDING",
+ LOG, "SOAPMessage", "PAYLOAD/MESSAGE"));
+ }
- if (m == Service.Mode.PAYLOAD && obj instanceof DataSource) {
- throw new RuntimeException(
- "DataSource is not valid in PAYLOAD mode with XML/HTTP binding");
- }
+ if (m == Service.Mode.PAYLOAD && obj instanceof DataSource) {
+ throw new Fault(
+ new org.apache.cxf.common.i18n.Message(
+ "DISPATCH_OBJECT_NOT_SUPPORTED_XMLBINDING",
+ LOG, "DataSource", "PAYLOAD"));
+ }
- if (obj instanceof Source || obj instanceof DataSource) {
- // no conversion needed
- } else {
- //JAXB element
- DataWriter<XMLStreamWriter> dataWriter = getDataWriter(message, service,
- XMLStreamWriter.class);
- XMLStreamWriter xmlWriter = message.getContent(XMLStreamWriter.class);
- //W3CDOMStreamWriter xmlWriter = new W3CDOMStreamWriter();
-
- if (xmlWriter == null) {
- xmlWriter = StaxUtils.createXMLStreamWriter(os, "UTF-8");
- }
-
- dataWriter.write(obj, xmlWriter);
- message.setContent(XMLStreamWriter.class, xmlWriter);
+ if (obj instanceof Source || obj instanceof DataSource) {
+ // no conversion needed
+ } else {
+ // JAXB element
+ DataWriter<XMLStreamWriter> dataWriter = getDataWriter(message, service,
+ XMLStreamWriter.class);
+ XMLStreamWriter xmlWriter = message.getContent(XMLStreamWriter.class);
+ // W3CDOMStreamWriter xmlWriter = new W3CDOMStreamWriter();
+ if (xmlWriter == null) {
+ xmlWriter = StaxUtils.createXMLStreamWriter(os, "UTF-8");
}
- }
- } catch (Exception e) {
- throw new Fault(new org.apache.cxf.common.i18n.Message("EXCEPTION_WRITING_OBJECT", LOG));
- }
+ dataWriter.write(obj, xmlWriter);
+ message.setContent(XMLStreamWriter.class, xmlWriter);
+ }
+ }
message.getInterceptorChain().add(ending);
}
Modified: incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/interceptors/Messages.properties
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/interceptors/Messages.properties?view=diff&rev=551026&r1=551025&r2=551026
==============================================================================
--- incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/interceptors/Messages.properties (original)
+++ incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/interceptors/Messages.properties Tue Jun 26 20:56:57 2007
@@ -23,4 +23,6 @@
COULD_NOT_INVOKE = Could not invoke getFaultInfo method on Exception.
DISPATCH_OBJECT_CANNOT_BE_NULL = Null object passed into Dispatch marshalling
EXCEPTION_WRITING_OBJECT = Exception occured while marshalling Dispatch object to stream
-ATTACHMENT_NOT_SUPPORTED = Attachments of type {0} are not supported.
\ No newline at end of file
+ATTACHMENT_NOT_SUPPORTED = Attachments of type {0} are not supported.
+DISPATCH_OBJECT_NOT_SUPPORTED_SOAPBINDING = {0} is not valid in {1} mode with SOAP/HTTP binding.
+DISPATCH_OBJECT_NOT_SUPPORTED_XMLBINDING = {0} is not valid in {1} mode with XML/HTTP binding.
\ No newline at end of file
Modified: incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/handlers/DispatchHandlerInvocationTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/handlers/DispatchHandlerInvocationTest.java?view=diff&rev=551026&r1=551025&r2=551026
==============================================================================
--- incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/handlers/DispatchHandlerInvocationTest.java (original)
+++ incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/handlers/DispatchHandlerInvocationTest.java Tue Jun 26 20:56:57 2007
@@ -183,8 +183,8 @@
disp.invoke(soapReq);
fail("Did not get expected exception");
} catch (SOAPFaultException e) {
- assertEquals("Exception occured while marshalling Dispatch object to stream", e.getMessage());
- e.printStackTrace();
+ assertTrue("Did not get expected exception message", e.getMessage()
+ .indexOf("is not valid in PAYLOAD mode with SOAP/HTTP binding") > -1);
}
}