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 2007/07/16 16:41:32 UTC
svn commit: r556638 - in
/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2:
builder/BuilderUtil.java transport/TransportUtils.java
transport/http/ApplicationXMLFormatter.java
transport/http/SOAPMessageFormatter.java
Author: scheu
Date: Mon Jul 16 07:41:26 2007
New Revision: 556638
URL: http://svn.apache.org/viewvc?view=rev&rev=556638
Log:
Contributor: Rich Scheuerle
Additional logging added to formatter builder classes.
During the JAX-WS REST development, we encountered several situations where additional logging helped identify problems (with content-type and character encoding).
Made a small change to ApplicationXMLFormatter to ensure that REST messages are not
sent with a SOAP content-type.
Modified:
webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/builder/BuilderUtil.java
webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/TransportUtils.java
webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/ApplicationXMLFormatter.java
webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/SOAPMessageFormatter.java
Modified: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/builder/BuilderUtil.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/builder/BuilderUtil.java?view=diff&rev=556638&r1=556637&r2=556638
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/builder/BuilderUtil.java (original)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/builder/BuilderUtil.java Mon Jul 16 07:41:26 2007
@@ -238,25 +238,43 @@
if ((bom[0] == (byte) 0xEF) && (bom[1] == (byte) 0xBB) && (bom[2] == (byte) 0xBF)) {
encoding = "UTF-8";
+ if (log.isDebugEnabled()) {
+ log.debug("char set encoding set from BOM =" + encoding);
+ }
unread = n - 3;
} else if ((bom[0] == (byte) 0xFE) && (bom[1] == (byte) 0xFF)) {
encoding = "UTF-16BE";
+ if (log.isDebugEnabled()) {
+ log.debug("char set encoding set from BOM =" + encoding);
+ }
unread = n - 2;
} else if ((bom[0] == (byte) 0xFF) && (bom[1] == (byte) 0xFE)) {
encoding = "UTF-16LE";
+ if (log.isDebugEnabled()) {
+ log.debug("char set encoding set from BOM =" + encoding);
+ }
unread = n - 2;
} else if ((bom[0] == (byte) 0x00) && (bom[1] == (byte) 0x00) && (bom[2] == (byte) 0xFE)
&& (bom[3] == (byte) 0xFF)) {
encoding = "UTF-32BE";
+ if (log.isDebugEnabled()) {
+ log.debug("char set encoding set from BOM =" + encoding);
+ }
unread = n - 4;
} else if ((bom[0] == (byte) 0xFF) && (bom[1] == (byte) 0xFE) && (bom[2] == (byte) 0x00)
&& (bom[3] == (byte) 0x00)) {
encoding = "UTF-32LE";
+ if (log.isDebugEnabled()) {
+ log.debug("char set encoding set from BOM =" + encoding);
+ }
unread = n - 4;
} else {
// Unicode BOM mark not found, unread all bytes
encoding = defaultEncoding;
+ if (log.isDebugEnabled()) {
+ log.debug("char set encoding set from default =" + encoding);
+ }
unread = n;
}
@@ -290,8 +308,14 @@
* @param contentType
*/
public static String getCharSetEncoding(String contentType) {
+ if (log.isDebugEnabled()) {
+ log.debug("Input contentType (" + contentType + ")");
+ }
if (contentType == null) {
// Using the default UTF-8
+ if (log.isDebugEnabled()) {
+ log.debug("CharSetEncoding defaulted (" + MessageContext.DEFAULT_CHAR_SET_ENCODING + ")");
+ }
return MessageContext.DEFAULT_CHAR_SET_ENCODING;
}
@@ -299,6 +323,9 @@
if (index == -1) { // Charset encoding not found in the content-type header
// Using the default UTF-8
+ if (log.isDebugEnabled()) {
+ log.debug("CharSetEncoding defaulted (" + MessageContext.DEFAULT_CHAR_SET_ENCODING + ")");
+ }
return MessageContext.DEFAULT_CHAR_SET_ENCODING;
}
@@ -319,8 +346,11 @@
if (value.indexOf('\"') != -1) {
value = value.replaceAll("\"", "");
}
-
- return value.trim();
+ value = value.trim();
+ if (log.isDebugEnabled()) {
+ log.debug("CharSetEncoding from content-type (" + value + ")");
+ }
+ return value;
}
public static StAXBuilder getAttachmentsBuilder(MessageContext msgContext,
Modified: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/TransportUtils.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/TransportUtils.java?view=diff&rev=556638&r1=556637&r2=556638
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/TransportUtils.java (original)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/TransportUtils.java Mon Jul 16 07:41:26 2007
@@ -125,8 +125,8 @@
MessageContext msgContext,
InputStream inStream) throws AxisFault, XMLStreamException {
OMElement documentElement = null;
+ String type = null;
if (contentType != null) {
- String type;
int index = contentType.indexOf(';');
if (index > 0) {
type = contentType.substring(0, index);
@@ -146,17 +146,27 @@
}
}
Builder builder = BuilderUtil.getBuilderFromSelector(type, msgContext);
+ if (log.isDebugEnabled()) {
+ log.debug("createSOAPEnvelope using Builder (" +
+ builder.getClass().getCanonicalName() + ") selected from type (" + type +")");
+ }
if (builder != null) {
documentElement = builder.processDocument(inStream, contentType, msgContext);
}
}
if (documentElement == null) {
if (msgContext.isDoingREST()) {
+ if (log.isDebugEnabled()) {
+ log.debug("Could not find a Builder for type (" + type + "). Using REST.");
+ }
StAXBuilder builder = BuilderUtil.getPOXBuilder(inStream, null);
documentElement = builder.getDocumentElement();
} else {
// FIXME making soap defualt for the moment..might effect the
// performance
+ if (log.isDebugEnabled()) {
+ log.debug("Could not find a Builder for type (" + type + "). Using SOAP.");
+ }
String charSetEnc = (String) msgContext
.getProperty(Constants.Configuration.CHARACTER_SET_ENCODING);
StAXBuilder builder = BuilderUtil.getSOAPBuilder(inStream, charSetEnc);
@@ -175,10 +185,16 @@
* @param contentType
*/
public static String getCharSetEncoding(String contentType) {
+ if (log.isDebugEnabled()) {
+ log.debug("Input contentType (" + contentType + ")");
+ }
int index = contentType.indexOf(HTTPConstants.CHAR_SET_ENCODING);
if (index == -1) { // Charset encoding not found in the content-type header
// Using the default UTF-8
+ if (log.isDebugEnabled()) {
+ log.debug("CharSetEncoding defaulted (" + MessageContext.DEFAULT_CHAR_SET_ENCODING + ")");
+ }
return MessageContext.DEFAULT_CHAR_SET_ENCODING;
}
@@ -199,8 +215,11 @@
if (value.indexOf('\"') != -1) {
value = value.replaceAll("\"", "");
}
-
- return value.trim();
+ value = value.trim();
+ if (log.isDebugEnabled()) {
+ log.debug("CharSetEncoding from content-type (" + value + ")");
+ }
+ return value;
}
public static void writeMessage(MessageContext msgContext, OutputStream out) throws AxisFault {
Modified: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/ApplicationXMLFormatter.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/ApplicationXMLFormatter.java?view=diff&rev=556638&r1=556637&r2=556638
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/ApplicationXMLFormatter.java (original)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/ApplicationXMLFormatter.java Mon Jul 16 07:41:26 2007
@@ -20,6 +20,8 @@
import org.apache.axiom.om.OMElement;
import org.apache.axiom.om.OMOutputFormat;
+import org.apache.axiom.soap.SOAP11Constants;
+import org.apache.axiom.soap.SOAP12Constants;
import org.apache.axiom.soap.SOAPFault;
import org.apache.axiom.soap.SOAPFaultDetail;
import org.apache.axis2.AxisFault;
@@ -27,6 +29,9 @@
import org.apache.axis2.context.MessageContext;
import org.apache.axis2.transport.MessageFormatter;
import org.apache.axis2.transport.http.util.URLTemplatingUtil;
+import org.apache.axis2.util.JavaUtils;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
import javax.xml.stream.XMLStreamException;
import java.io.ByteArrayOutputStream;
@@ -39,67 +44,87 @@
*/
public class ApplicationXMLFormatter implements MessageFormatter {
+ private static final Log log = LogFactory.getLog(ApplicationXMLFormatter.class);
public byte[] getBytes(MessageContext messageContext, OMOutputFormat format) throws AxisFault {
- OMElement omElement;
+ if (log.isDebugEnabled()) {
+ log.debug("start getBytes()");
+ log.debug(" fault flow=" + (messageContext.getFLOW() == MessageContext.OUT_FAULT_FLOW));
+ }
+ try {
+ OMElement omElement;
+
+ if (messageContext.getFLOW() == MessageContext.OUT_FAULT_FLOW) {
+ SOAPFault fault = messageContext.getEnvelope().getBody().getFault();
+ SOAPFaultDetail soapFaultDetail = fault.getDetail();
+ omElement = soapFaultDetail.getFirstElement();
- if (messageContext.getFLOW() == MessageContext.OUT_FAULT_FLOW) {
- SOAPFault fault = messageContext.getEnvelope().getBody().getFault();
- SOAPFaultDetail soapFaultDetail = fault.getDetail();
- omElement = soapFaultDetail.getFirstElement();
+ if (omElement == null) {
+ omElement = fault.getReason();
+ }
- if (omElement == null) {
- omElement = fault.getReason();
+ } else {
+ omElement = messageContext.getEnvelope().getBody().getFirstElement();
}
+ ByteArrayOutputStream bytesOut = new ByteArrayOutputStream();
- } else {
- omElement = messageContext.getEnvelope().getBody().getFirstElement();
- }
- ByteArrayOutputStream bytesOut = new ByteArrayOutputStream();
+ if (omElement != null) {
- if (omElement != null) {
+ try {
+ omElement.serializeAndConsume(bytesOut, format);
+ } catch (XMLStreamException e) {
+ throw AxisFault.makeFault(e);
+ }
- try {
- omElement.serializeAndConsume(bytesOut, format);
- } catch (XMLStreamException e) {
- throw AxisFault.makeFault(e);
+ return bytesOut.toByteArray();
}
- return bytesOut.toByteArray();
+ return new byte[0];
+ } finally {
+ if (log.isDebugEnabled()) {
+ log.debug("end getBytes()");
+ }
}
-
- return new byte[0];
}
public void writeTo(MessageContext messageContext, OMOutputFormat format,
OutputStream outputStream, boolean preserve) throws AxisFault {
- OMElement omElement = null;
+ if (log.isDebugEnabled()) {
+ log.debug("start writeTo()");
+ }
+ try {
+ OMElement omElement = null;
+
+ if (messageContext.getFLOW() == MessageContext.OUT_FAULT_FLOW) {
+ SOAPFault fault = messageContext.getEnvelope().getBody().getFault();
+ SOAPFaultDetail soapFaultDetail = fault.getDetail();
+ if (soapFaultDetail != null) {
+ omElement = soapFaultDetail.getFirstElement();
+ }
+ if (omElement == null) {
+ omElement = fault.getReason();
+ }
- if (messageContext.getFLOW() == MessageContext.OUT_FAULT_FLOW) {
- SOAPFault fault = messageContext.getEnvelope().getBody().getFault();
- SOAPFaultDetail soapFaultDetail = fault.getDetail();
- if (soapFaultDetail != null) {
- omElement = soapFaultDetail.getFirstElement();
+ } else {
+ omElement = messageContext.getEnvelope().getBody().getFirstElement();
}
- if (omElement == null) {
- omElement = fault.getReason();
+ if (omElement != null) {
+ try {
+ omElement.serializeAndConsume(outputStream, format);
+ } catch (XMLStreamException e) {
+ throw AxisFault.makeFault(e);
+ }
}
-
- } else {
- omElement = messageContext.getEnvelope().getBody().getFirstElement();
- }
- if (omElement != null) {
try {
- omElement.serializeAndConsume(outputStream, format);
- } catch (XMLStreamException e) {
+ outputStream.flush();
+ } catch (IOException e) {
throw AxisFault.makeFault(e);
}
- }
- try {
- outputStream.flush();
- } catch (IOException e) {
- throw AxisFault.makeFault(e);
+ } finally {
+ if (log.isDebugEnabled()) {
+ log.debug("end writeTo()");
+ }
}
}
@@ -110,8 +135,19 @@
String contentType;
contentType = (String) messageContext.getProperty(Constants.Configuration.CONTENT_TYPE);
+ if (log.isDebugEnabled()) {
+ log.debug("contentType set from messageContext =" + contentType);
+ log.debug("(NOTE) contentType from format is=" + format.getContentType());
+ }
+
if (contentType == null) {
contentType = HTTPConstants.MEDIA_TYPE_APPLICATION_XML;
+ } else if (isSOAPContentType(contentType)) {
+ contentType = HTTPConstants.MEDIA_TYPE_APPLICATION_XML;
+ if (log.isDebugEnabled()) {
+ log.debug("contentType is set incorrectly for Application XML.");
+ log.debug("It is changed to " + contentType);
+ }
}
if (encoding != null) {
@@ -124,7 +160,9 @@
&& !"\"\"".equals(soapAction.trim())) {
contentType = contentType;
}
-
+ if (log.isDebugEnabled()) {
+ log.debug("contentType returned =" + contentType);
+ }
return contentType;
}
@@ -141,5 +179,16 @@
public String formatSOAPAction(MessageContext messageContext, OMOutputFormat format,
String soapAction) {
return soapAction;
+ }
+
+ private boolean isSOAPContentType(String contentType) {
+ if (JavaUtils.indexOfIgnoreCase(contentType, SOAP12Constants.SOAP_12_CONTENT_TYPE) > -1) {
+ return true;
+ }
+ // search for "type=text/xml"
+ else if (JavaUtils.indexOfIgnoreCase(contentType, SOAP11Constants.SOAP_11_CONTENT_TYPE) > -1) {
+ return true;
+ }
+ return false;
}
}
Modified: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/SOAPMessageFormatter.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/SOAPMessageFormatter.java?view=diff&rev=556638&r1=556637&r2=556638
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/SOAPMessageFormatter.java (original)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/SOAPMessageFormatter.java Mon Jul 16 07:41:26 2007
@@ -29,6 +29,8 @@
import org.apache.axis2.transport.MessageFormatter;
import org.apache.axis2.transport.http.util.URLTemplatingUtil;
import org.apache.axis2.util.JavaUtils;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
import javax.xml.stream.FactoryConfigurationError;
import javax.xml.stream.XMLStreamException;
@@ -39,8 +41,16 @@
public class SOAPMessageFormatter implements MessageFormatter {
+ private static final Log log = LogFactory.getLog(SOAPMessageFormatter.class);
+
public void writeTo(MessageContext msgCtxt, OMOutputFormat format,
OutputStream out, boolean preserve) throws AxisFault {
+ if (log.isDebugEnabled()) {
+ log.debug("start writeTo()");
+ log.debug(" preserve=" + preserve);
+ log.debug(" isOptimized=" + format.isOptimized());
+ log.debug(" isDoingSWA=" + format.isDoingSWA());
+ }
OMElement element = msgCtxt.getEnvelope();
try {
if (!(format.isOptimized()) & format.isDoingSWA()) {
@@ -60,11 +70,20 @@
}
} catch (XMLStreamException e) {
throw AxisFault.makeFault(e);
+ } finally {
+ if (log.isDebugEnabled()) {
+ log.debug("end writeTo()");
+ }
}
}
public byte[] getBytes(MessageContext msgCtxt, OMOutputFormat format)
throws AxisFault {
+ if (log.isDebugEnabled()) {
+ log.debug("start getBytes()");
+ log.debug(" isOptimized=" + format.isOptimized());
+ log.debug(" isDoingSWA=" + format.isDoingSWA());
+ }
OMElement element = msgCtxt.getEnvelope();
try {
ByteArrayOutputStream bytesOut = new ByteArrayOutputStream();
@@ -88,6 +107,10 @@
throw AxisFault.makeFault(e);
} catch (FactoryConfigurationError e) {
throw AxisFault.makeFault(e);
+ } finally {
+ if (log.isDebugEnabled()) {
+ log.debug("end getBytes()");
+ }
}
}
@@ -95,6 +118,9 @@
String soapActionString) {
String encoding = format.getCharSetEncoding();
String contentType = format.getContentType();
+ if (log.isDebugEnabled()) {
+ log.debug("contentType from the OMOutputFormat =" + contentType);
+ }
if (encoding != null) {
contentType += "; charset=" + encoding;
}
@@ -106,6 +132,9 @@
&& !"\"\"".equals(soapActionString.trim())) {
contentType = contentType + "; action=\"" + soapActionString+ "\"";
}
+ if (log.isDebugEnabled()) {
+ log.debug("contentType returned =" + contentType);
+ }
return contentType;
}
@@ -140,6 +169,9 @@
private void writeSwAMessage(MessageContext msgCtxt,
StringWriter bufferedSOAPBody, OutputStream outputStream,
OMOutputFormat format) {
+ if (log.isDebugEnabled()) {
+ log.debug("start writeSwAMessage()");
+ }
Object property = msgCtxt
.getProperty(Constants.Configuration.MM7_COMPATIBLE);
boolean MM7CompatMode = false;
@@ -172,6 +204,9 @@
MIMEOutputUtils.writeMM7Message(bufferedSOAPBody, outputStream,
msgCtxt.getAttachmentMap(), format, partCID,
innerBoundary);
+ }
+ if (log.isDebugEnabled()) {
+ log.debug("end writeSwAMessage()");
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: axis-cvs-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-cvs-help@ws.apache.org