You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-dev@axis.apache.org by sc...@apache.org on 2006/11/18 02:38:45 UTC
svn commit: r476407 - in /webservices/axis2/trunk/java/modules/jaxws:
src/org/apache/axis2/jaxws/ src/org/apache/axis2/jaxws/i18n/
src/org/apache/axis2/jaxws/message/databinding/impl/
test/org/apache/axis2/jaxws/dispatch/
Author: scheu
Date: Fri Nov 17 17:38:44 2006
New Revision: 476407
URL: http://svn.apache.org/viewvc?view=rev&rev=476407
Log:
AXIS2-1744
Contributor:Rich Scheuerle
Improved Exception when a bad Source object is provided to a JAX-WS Dispatch
Modified:
webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/ExceptionFactory.java
webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/i18n/resource.properties
webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/databinding/impl/SourceBlockImpl.java
webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/dispatch/DOMSourceDispatch.java
webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/dispatch/SAXSourceDispatch.java
Modified: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/ExceptionFactory.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/ExceptionFactory.java?view=diff&rev=476407&r1=476406&r2=476407
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/ExceptionFactory.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/ExceptionFactory.java Fri Nov 17 17:38:44 2006
@@ -213,6 +213,22 @@
* @return WebServiceException
*/
private static WebServiceException createWebServiceException(String message, Throwable t) {
+
+ // We might have an embedded MessageException that has a good message on it
+ MessageException me = (MessageException) findException(t, MessageException.class);
+ if (me != null) {
+ String meMessage = me.getMessage();
+ if (meMessage != null) {
+ if (message == null) {
+ message = meMessage;
+ } else {
+ message = message + ": " + meMessage;
+ }
+ }
+ }
+
+ // Get the root cause. We want to strip out the intermediate exceptions (like AxisFault) because
+ // these won't make sense to the user.
Throwable rootCause = null;
if (t != null) {
rootCause = getRootCause(t);
@@ -220,10 +236,11 @@
rootCause = rootCause==null ? t :rootCause;
WebServiceException e = null;
+ // The root cause may not have a good message. We might want to enhance it
String enhancedMessage = enhanceMessage(rootCause);
if (enhancedMessage != null) {
if (message != null)
- message.concat(": " + enhancedMessage);
+ message = message + ": " + enhancedMessage;
else
message = enhancedMessage;
}
@@ -296,6 +313,7 @@
* @return MessageException
*/
private static MessageInternalException createMessageInternalException(String message, Throwable t) {
+
Throwable rootCause = null;
if (t != null) {
rootCause = getRootCause(t);
@@ -400,8 +418,7 @@
// TODO better criteria
if ((t instanceof StackOverflowError) && (stackTrace.contains("JAXB")))
- // TODO better message
- return "The system threw a StackOverflowError at the JAXB level. This usually means there is a circular type reference in the WSDL.";
+ return Messages.getMessage("JABGraphProblem");
return null;
}
Modified: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/i18n/resource.properties
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/i18n/resource.properties?view=diff&rev=476407&r1=476406&r2=476407
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/i18n/resource.properties (original)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/i18n/resource.properties Fri Nov 17 17:38:44 2006
@@ -133,3 +133,5 @@
ClassUtilsErr2={0} might not be a valid package because the encoding is unsupported.
ClassUtilsErr3=An IOException error was thrown when trying to get all of the resources for {0}
MethodMarshallerErr1=A JAX-WS service exception for the {0} fault bean cannot be created.
+SourceReadErr=A problem was encountered while reading the Source object. Please verify that your Source object is correct. The class of the Source object is {0}
+JABGraphProblem=The system threw a StackOverflowError at the JAXB level. This usually means that your JAXB object has a circular reference. This is not supported by JAXB.
\ No newline at end of file
Modified: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/databinding/impl/SourceBlockImpl.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/databinding/impl/SourceBlockImpl.java?view=diff&rev=476407&r1=476406&r2=476407
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/databinding/impl/SourceBlockImpl.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/databinding/impl/SourceBlockImpl.java Fri Nov 17 17:38:44 2006
@@ -135,42 +135,47 @@
}
@Override
- protected XMLStreamReader _getReaderFromBO(Object busObj, Object busContext) throws XMLStreamException {
- // TODO not sure if this is always the most performant way to do this.
- if (busObj instanceof DOMSource) {
- // Let's use our own DOMReader for now...
- Element element = null;
-
- // Business Object msut be a Document or Element
- Node node = ((DOMSource)busObj).getNode();
- if(node instanceof Document){
- element = ((Document)node).getDocumentElement();
- }else{
- element = (Element) ((DOMSource)busObj).getNode();
- }
-
- // We had some problems with testers producing DOMSources w/o Namespaces.
- // It's easy to catch this here.
- if (element.getLocalName() == null) {
- throw new XMLStreamException(ExceptionFactory.makeMessageException(Messages.getMessage("JAXBSourceNamespaceErr")));
- }
-
- return new DOMReader(element);
- }
-
- if(busObj instanceof StreamSource){
- XMLInputFactory f = StAXUtils.getXMLInputFactory();
-
- XMLStreamReader reader = f.createXMLStreamReader((Source) busObj);
- StAXUtils.releaseXMLInputFactory(f);
- return reader;
- }
- //TODO: For GM we need to only use this approach when absolutely necessary.
- // For example, we don't want to do this if this is a (1.6) StaxSource or if the installed parser provides
- // a better solution.
- //TODO: Uncomment this code if woodstock parser handles JAXBSource and SAXSource correctly.
- //return inputFactory.createXMLStreamReader((Source) busObj);
- return _slow_getReaderFromSource((Source)busObj);
+ protected XMLStreamReader _getReaderFromBO(Object busObj, Object busContext) throws XMLStreamException, MessageException {
+ try {
+ // TODO not sure if this is always the most performant way to do this.
+ if (busObj instanceof DOMSource) {
+ // Let's use our own DOMReader for now...
+ Element element = null;
+
+ // Business Object msut be a Document or Element
+ Node node = ((DOMSource)busObj).getNode();
+ if(node instanceof Document){
+ element = ((Document)node).getDocumentElement();
+ }else{
+ element = (Element) ((DOMSource)busObj).getNode();
+ }
+
+ // We had some problems with testers producing DOMSources w/o Namespaces.
+ // It's easy to catch this here.
+ if (element.getLocalName() == null) {
+ throw new XMLStreamException(ExceptionFactory.makeMessageException(Messages.getMessage("JAXBSourceNamespaceErr")));
+ }
+
+ return new DOMReader(element);
+ }
+
+ if(busObj instanceof StreamSource){
+ XMLInputFactory f = StAXUtils.getXMLInputFactory();
+
+ XMLStreamReader reader = f.createXMLStreamReader((Source) busObj);
+ StAXUtils.releaseXMLInputFactory(f);
+ return reader;
+ }
+ //TODO: For GM we need to only use this approach when absolutely necessary.
+ // For example, we don't want to do this if this is a (1.6) StaxSource or if the installed parser provides
+ // a better solution.
+ //TODO: Uncomment this code if woodstock parser handles JAXBSource and SAXSource correctly.
+ //return inputFactory.createXMLStreamReader((Source) busObj);
+ return _slow_getReaderFromSource((Source)busObj);
+ } catch (Exception e) {
+ String className = (busObj == null) ? "none" : busObj.getClass().getName();
+ throw ExceptionFactory.makeMessageException(Messages.getMessage("SourceReadErr", className), e);
+ }
}
/**
@@ -191,7 +196,7 @@
}
@Override
- protected void _outputFromBO(Object busObject, Object busContext, XMLStreamWriter writer) throws XMLStreamException {
+ protected void _outputFromBO(Object busObject, Object busContext, XMLStreamWriter writer) throws XMLStreamException, MessageException {
// There is no fast way to output the Source to a writer, so get the reader
// and pass use the default reader->writer.
XMLStreamReader reader = _getReaderFromBO(busObject, busContext);
Modified: webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/dispatch/DOMSourceDispatch.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/dispatch/DOMSourceDispatch.java?view=diff&rev=476407&r1=476406&r2=476407
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/dispatch/DOMSourceDispatch.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/dispatch/DOMSourceDispatch.java Fri Nov 17 17:38:44 2006
@@ -30,6 +30,7 @@
import javax.xml.ws.Dispatch;
import javax.xml.ws.Response;
import javax.xml.ws.Service;
+import javax.xml.ws.WebServiceException;
import junit.framework.TestCase;
@@ -281,6 +282,28 @@
dispatch.invokeOneWay(request);
}
+ public void testBadDOMSource() throws Exception {
+ System.out.println("---------------------------------------");
+ System.out.println("test: " + getName());
+
+ // Initialize the JAX-WS client artifacts
+ Service svc = Service.create(DispatchTestConstants.QNAME_SERVICE);
+ svc.addPort(DispatchTestConstants.QNAME_PORT, null, DispatchTestConstants.URL);
+ Dispatch<Source> dispatch = svc.createDispatch(DispatchTestConstants.QNAME_PORT,
+ Source.class, Service.Mode.PAYLOAD);
+
+ // Create the DOMSource
+ DOMSource request = new DOMSource();
+
+ try {
+ dispatch.invokeOneWay(request);
+ fail("WebServiceException was expected");
+ } catch (WebServiceException e) {
+ System.out.println("A Web Service Exception was expected: " + e.toString());
+ assertTrue(e.getMessage() != null);
+ }
+
+ }
/**
* Create a DOMSource with the provided String as the content
* @param input
Modified: webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/dispatch/SAXSourceDispatch.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/dispatch/SAXSourceDispatch.java?view=diff&rev=476407&r1=476406&r2=476407
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/dispatch/SAXSourceDispatch.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/dispatch/SAXSourceDispatch.java Fri Nov 17 17:38:44 2006
@@ -28,6 +28,7 @@
import javax.xml.ws.Dispatch;
import javax.xml.ws.Response;
import javax.xml.ws.Service;
+import javax.xml.ws.WebServiceException;
import junit.framework.TestCase;
@@ -315,4 +316,26 @@
System.out.println(">> Invoking One Way Dispatch");
dispatch.invokeOneWay(request);
}
+
+ public void testBadSAXSource() throws Exception {
+ System.out.println("---------------------------------------");
+ System.out.println("test: " + getName());
+
+ // Initialize the JAX-WS client artifacts
+ Service svc = Service.create(DispatchTestConstants.QNAME_SERVICE);
+ svc.addPort(DispatchTestConstants.QNAME_PORT, null, DispatchTestConstants.URL);
+ Dispatch<Source> dispatch = svc.createDispatch(DispatchTestConstants.QNAME_PORT,
+ Source.class, Service.Mode.MESSAGE);
+
+ // Create an empty (invalid) SAXSource
+ Source request = new SAXSource();
+
+ try {
+ dispatch.invokeOneWay(request);
+ fail("WebServiceException was expected");
+ } catch (WebServiceException e) {
+ System.out.println("A Web Service Exception was expected: " + e.toString());
+ assertTrue(e.getMessage() != null);
+ }
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: axis-cvs-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-cvs-help@ws.apache.org