You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-commits@axis.apache.org by ro...@apache.org on 2022/06/07 15:54:13 UTC
[axis-axis2-java-core] branch master updated: Also parse action from start-info and use axiom ContentType for parsing
This is an automated email from the ASF dual-hosted git repository.
robertlazarski pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/axis-axis2-java-core.git
The following commit(s) were added to refs/heads/master by this push:
new 9ac5ef7168 Also parse action from start-info and use axiom ContentType for parsing
new e45019c1d3 Merge pull request #308 from manfredweiss/AXIS2-5986
9ac5ef7168 is described below
commit 9ac5ef71688deb994d0b814c89c1623ef7eec886
Author: Manfred Weiss <ma...@ith-icoserve.com>
AuthorDate: Fri May 27 12:07:34 2022 +0200
Also parse action from start-info and use axiom ContentType for parsing
---
.../org/apache/axis2/kernel/TransportUtils.java | 29 +++++++++++-----------
.../apache/axis2/kernel/TransportUtilsTest.java | 27 ++++++++++++++++++++
2 files changed, 41 insertions(+), 15 deletions(-)
diff --git a/modules/kernel/src/org/apache/axis2/kernel/TransportUtils.java b/modules/kernel/src/org/apache/axis2/kernel/TransportUtils.java
index ab9c80d5f5..91a5e94512 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 @@ package org.apache.axis2.kernel;
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 javax.xml.stream.XMLStreamException;
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 class TransportUtils {
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 0000000000..f30c548680
--- /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=\"<ro...@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=\"<my...@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