Also parse action from start-info and use axiom ContentType for parsing
diff --git a/modules/kernel/src/org/apache/axis2/kernel/TransportUtils.java b/modules/kernel/src/org/apache/axis2/kernel/TransportUtils.java
index ab9c80d..91a5e94 100644
--- a/modules/kernel/src/org/apache/axis2/kernel/TransportUtils.java
+++ b/modules/kernel/src/org/apache/axis2/kernel/TransportUtils.java
@@ -23,6 +23,7 @@
import org.apache.axiom.attachments.Attachments;
import org.apache.axiom.attachments.CachedFileDataSource;
import org.apache.axiom.attachments.lifecycle.LifecycleManager;
+import org.apache.axiom.mime.ContentType;
import org.apache.axiom.om.OMAbstractFactory;
import org.apache.axiom.om.OMElement;
import org.apache.axiom.om.OMException;
@@ -55,7 +56,9 @@
import java.io.File;
import java.io.InputStream;
import java.io.OutputStream;
+import java.text.ParseException;
import java.util.List;
+import java.util.Optional;
public class TransportUtils {
@@ -409,23 +412,19 @@
public static void processContentTypeForAction(String contentType, MessageContext msgContext) {
//Check for action header and set it in as soapAction in MessageContext
- int index = contentType.indexOf("action");
- if (index > -1) {
- String transientString = contentType.substring(index, contentType.length());
- int equal = transientString.indexOf("=");
- int firstSemiColon = transientString.indexOf(";");
- String soapAction; // This will contain "" in the string
- if (firstSemiColon > -1) {
- soapAction = transientString.substring(equal + 1, firstSemiColon);
- } else {
- soapAction = transientString.substring(equal + 1, transientString.length());
+ try {
+ ContentType ct = new ContentType(contentType);
+ String startInfo = ct.getParameter("start-info");
+ if (startInfo != null) {
+ Optional.ofNullable(new ContentType(startInfo).getParameter("action"))
+ .ifPresent(msgContext::setSoapAction);
}
- if ((soapAction != null) && soapAction.startsWith("\"")
- && soapAction.endsWith("\"")) {
- soapAction = soapAction
- .substring(1, soapAction.length() - 1);
+ Optional.ofNullable(ct.getParameter("action"))
+ .ifPresent(msgContext::setSoapAction);
+ } catch (ParseException e) {
+ if (log.isDebugEnabled()) {
+ log.debug("Failed to parse Content-Type Header: " + e.getMessage(), e);
}
- msgContext.setSoapAction(soapAction);
}
}
diff --git a/modules/kernel/test/org/apache/axis2/kernel/TransportUtilsTest.java b/modules/kernel/test/org/apache/axis2/kernel/TransportUtilsTest.java
new file mode 100644
index 0000000..f30c548
--- /dev/null
+++ b/modules/kernel/test/org/apache/axis2/kernel/TransportUtilsTest.java
@@ -0,0 +1,27 @@
+package org.apache.axis2.kernel;
+
+import junit.framework.TestCase;
+import org.apache.axis2.context.MessageContext;
+
+import java.util.UUID;
+
+public class TransportUtilsTest extends TestCase {
+
+ private static final String ACTION_INSIDE_STARTINFO = "multipart/related; type=\"application/xop+xml\"; boundary=\"%s\"; start=\"<root.message@cxf.apache.org>\"; start-info=\"application/soap+xml; action=\\\"%s\\\"\"";
+ private static final String ACTION_OUTSIDE_STARTINFO = "Multipart/Related;boundary=MIME_boundary;type=\"application/xop+xml\";start=\"<mymessage.xml@example.org>\";start-info=\"application/soap+xml\"; action=\"%s\"";
+
+ public void testProcessContentTypeForAction() {
+
+ String soapAction = "http://www.example.com/ProcessData";
+ String contentType;
+ MessageContext msgContext = new MessageContext();
+
+ contentType = String.format(ACTION_INSIDE_STARTINFO, UUID.randomUUID().toString(), soapAction);
+ TransportUtils.processContentTypeForAction(contentType, msgContext);
+ assertEquals(soapAction, msgContext.getSoapAction());
+
+ contentType = String.format(ACTION_OUTSIDE_STARTINFO, soapAction);
+ TransportUtils.processContentTypeForAction(contentType, msgContext);
+ assertEquals(soapAction, msgContext.getSoapAction());
+ }
+}
\ No newline at end of file