Added toString() to message factories

This commit is contained in:
Arjen Poutsma
2007-06-01 11:07:23 +00:00
parent 12307e33b4
commit 4ef0b01447
4 changed files with 80 additions and 12 deletions

View File

@@ -20,7 +20,6 @@ import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import org.springframework.util.Assert;
import org.springframework.util.ReflectionUtils;
/**
* Represents a bean method that will be invoked as part of an incoming Web service message.
@@ -78,11 +77,30 @@ public final class MethodEndpoint {
*
* @param args the arguments
* @return the invocation result
* @throws IllegalAccessException when there is insufficient access to invoke the method
* @throws InvocationTargetException when the method invocation results in an exception
* @throws Exception when the method invocation results in an exception
*/
public Object invoke(Object[] args) throws IllegalAccessException, InvocationTargetException {
return ReflectionUtils.invokeMethod(this.method, this.bean, args);
public Object invoke(Object[] args) throws Exception {
try {
return this.method.invoke(this.bean, args);
}
catch (InvocationTargetException ex) {
handleInvocationTargetException(ex);
throw new IllegalStateException("Unexpected exception thrown by method - " +
ex.getTargetException().getClass().getName() + ": " + ex.getTargetException().getMessage());
}
}
private void handleInvocationTargetException(InvocationTargetException ex) throws Exception {
if (ex.getTargetException() instanceof RuntimeException) {
throw (RuntimeException) ex.getTargetException();
}
if (ex.getTargetException() instanceof Error) {
throw (Error) ex.getTargetException();
}
if (ex.getTargetException() instanceof Exception) {
throw (Exception) ex.getTargetException();
}
}
public boolean equals(Object o) {

View File

@@ -238,4 +238,15 @@ public class AxiomSoapMessageFactory implements SoapMessageFactory, Initializing
}
}
public String toString() {
StringBuffer buffer = new StringBuffer("AxiomSoapMessageFactory[");
if (soapFactory instanceof SOAP11Factory) {
buffer.append("SOAP 1.1");
}
else if (soapFactory instanceof SOAP12Factory) {
buffer.append("SOAP 1.2");
}
buffer.append(']');
return buffer.toString();
}
}

View File

@@ -65,16 +65,16 @@ public class SaajSoapMessageFactory implements SoapMessageFactory, InitializingB
this.messageFactory = messageFactory;
}
/** Sets the SAAJ <code>MessageFactory</code>. */
public void setMessageFactory(MessageFactory messageFactory) {
this.messageFactory = messageFactory;
}
/** Returns the SAAJ <code>MessageFactory</code> used. */
public MessageFactory getMessageFactory() {
return messageFactory;
}
/** Sets the SAAJ <code>MessageFactory</code>. */
public void setMessageFactory(MessageFactory messageFactory) {
this.messageFactory = messageFactory;
}
public void setSoapVersion(SoapVersion version) {
if (SaajUtils.getSaajVersion() >= SaajUtils.SAAJ_13) {
if (SoapVersion.SOAP_11 == version) {
@@ -115,11 +115,17 @@ public class SaajSoapMessageFactory implements SoapMessageFactory, InitializingB
}
else {
throw new IllegalStateException(
"SaajSoapMessageFactory requires SAAJ 1.1, which was not" + "found on the classpath");
"SaajSoapMessageFactory requires SAAJ 1.1, which was not found on the classpath");
}
}
catch (NoSuchMethodError ex) {
throw new SoapMessageCreationException(
"Could not create SAAJ MessageFactory. Is the version of the SAAJ specification interfaces [" +
SaajUtils.getSaajVersionString() +
"] the same as the version supported by the application server?", ex);
}
catch (SOAPException ex) {
throw new SoapMessageCreationException("Could not create MessageFactory: " + ex.getMessage(), ex);
throw new SoapMessageCreationException("Could not create SAAJ MessageFactory: " + ex.getMessage(), ex);
}
}
if (logger.isDebugEnabled()) {
@@ -158,4 +164,15 @@ public class SaajSoapMessageFactory implements SoapMessageFactory, InitializingB
throw new SoapMessageCreationException("Could not create message from InputStream: " + ex.getMessage(), ex);
}
}
public String toString() {
StringBuffer buffer = new StringBuffer("SaajSoapMessageFactory[");
buffer.append(SaajUtils.getSaajVersionString());
if (SaajUtils.getSaajVersion() >= SaajUtils.SAAJ_13) {
buffer.append(',');
buffer.append(messageFactoryProtocol);
}
buffer.append(']');
return buffer.toString();
}
}

View File

@@ -103,6 +103,28 @@ public abstract class SaajUtils {
return saajVersion;
}
/**
* Returns the SAAJ version as a String. The returned string will be "<code>SAAJ 1.3</code>",
* "<code>SAAJ 1.2</code>", or "<code>SAAJ 1.1</code>".
*
* @return a string representation of the SAAJ version
* @see #getSaajVersion()
*/
public static String getSaajVersionString() {
if (saajVersion >= SaajUtils.SAAJ_13) {
return "SAAJ 1.3";
}
else if (saajVersion == SaajUtils.SAAJ_12) {
return "SAAJ 1.2";
}
else if (saajVersion == SaajUtils.SAAJ_11) {
return "SAAJ 1.1";
}
else {
return "";
}
}
/**
* Converts a <code>javax.xml.namespace.QName</code> to a <code>javax.xml.soap.Name</code>. A
* <code>SOAPElement</code> is required to create the name.