You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ws.apache.org by ve...@apache.org on 2015/01/01 18:08:13 UTC
svn commit: r1648892 - in /webservices/axiom/trunk:
axiom-spring-ws/src/main/java/org/apache/axiom/spring/ws/soap/
testing/spring-ws-testsuite/src/main/java/org/apache/axiom/ts/springws/
testing/spring-ws-testsuite/src/main/java/org/apache/axiom/ts/spr...
Author: veithen
Date: Thu Jan 1 17:08:13 2015
New Revision: 1648892
URL: http://svn.apache.org/r1648892
Log:
AXIOM-447: Implement SOAP action.
Added:
webservices/axiom/trunk/axiom-spring-ws/src/main/java/org/apache/axiom/spring/ws/soap/SoapUtils.java (with props)
webservices/axiom/trunk/testing/spring-ws-testsuite/src/main/java/org/apache/axiom/ts/springws/scenario/soapaction/
webservices/axiom/trunk/testing/spring-ws-testsuite/src/main/java/org/apache/axiom/ts/springws/scenario/soapaction/EchoEndpoint.java (with props)
webservices/axiom/trunk/testing/spring-ws-testsuite/src/main/java/org/apache/axiom/ts/springws/scenario/soapaction/SoapActionTest.java (with props)
webservices/axiom/trunk/testing/spring-ws-testsuite/src/main/resources/org/apache/axiom/ts/springws/scenario/soapaction/
webservices/axiom/trunk/testing/spring-ws-testsuite/src/main/resources/org/apache/axiom/ts/springws/scenario/soapaction/client.xml (with props)
webservices/axiom/trunk/testing/spring-ws-testsuite/src/main/resources/org/apache/axiom/ts/springws/scenario/soapaction/server.xml (with props)
Modified:
webservices/axiom/trunk/axiom-spring-ws/src/main/java/org/apache/axiom/spring/ws/soap/AxiomSoapMessageFactory.java
webservices/axiom/trunk/axiom-spring-ws/src/main/java/org/apache/axiom/spring/ws/soap/SoapMessageImpl.java
webservices/axiom/trunk/testing/spring-ws-testsuite/src/main/java/org/apache/axiom/ts/springws/SpringWSTestSuiteBuilder.java
Modified: webservices/axiom/trunk/axiom-spring-ws/src/main/java/org/apache/axiom/spring/ws/soap/AxiomSoapMessageFactory.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/axiom-spring-ws/src/main/java/org/apache/axiom/spring/ws/soap/AxiomSoapMessageFactory.java?rev=1648892&r1=1648891&r2=1648892&view=diff
==============================================================================
--- webservices/axiom/trunk/axiom-spring-ws/src/main/java/org/apache/axiom/spring/ws/soap/AxiomSoapMessageFactory.java (original)
+++ webservices/axiom/trunk/axiom-spring-ws/src/main/java/org/apache/axiom/spring/ws/soap/AxiomSoapMessageFactory.java Thu Jan 1 17:08:13 2015
@@ -24,6 +24,7 @@ import java.text.ParseException;
import java.util.Iterator;
import org.apache.axiom.mime.ContentType;
+import org.apache.axiom.mime.MediaType;
import org.apache.axiom.om.OMAbstractFactory;
import org.apache.axiom.om.OMMetaFactory;
import org.apache.axiom.om.OMXMLBuilderFactory;
@@ -73,11 +74,17 @@ public final class AxiomSoapMessageFacto
}
public SoapMessage createWebServiceMessage() {
- return new SoapMessageImpl(soapFactory.createDefaultSOAPMessage(), true);
+ return new SoapMessageImpl(soapFactory.createDefaultSOAPMessage(), null, true);
+ }
+
+ private static String getHeaderValue(TransportInputStream transportInputStream, String name) throws IOException {
+ Iterator<String> iterator = transportInputStream.getHeaders(name);
+ return iterator.hasNext() ? iterator.next() : null;
}
public SoapMessage createWebServiceMessage(InputStream inputStream) throws IOException {
String charset;
+ String soapAction;
if (inputStream instanceof TransportInputStream) {
TransportInputStream transportInputStream = (TransportInputStream)inputStream;
Iterator<String> it = transportInputStream.getHeaders(TransportConstants.HEADER_CONTENT_TYPE);
@@ -92,12 +99,19 @@ public final class AxiomSoapMessageFacto
throw new SoapMessageCreationException("No Content-Type header found");
}
charset = contentType.getParameter("charset");
+ MediaType mediaType = contentType.getMediaType();
+ if (mediaType.equals(MediaType.TEXT_XML)) {
+ soapAction = SoapUtils.unescapeAction(getHeaderValue(transportInputStream, TransportConstants.HEADER_SOAP_ACTION));
+ } else {
+ soapAction = contentType.getParameter("action");
+ }
} else {
charset = null;
+ soapAction = null;
}
SOAPModelBuilder builder = OMXMLBuilderFactory.createSOAPModelBuilder(metaFactory, inputStream, charset);
// TODO: should SOAPModelBuilder have a getSOAPMessage() method?
// TODO: need to check that the SOAP version matches the content type
- return new SoapMessageImpl((SOAPMessage)builder.getDocument(), false);
+ return new SoapMessageImpl((SOAPMessage)builder.getDocument(), soapAction, false);
}
}
Modified: webservices/axiom/trunk/axiom-spring-ws/src/main/java/org/apache/axiom/spring/ws/soap/SoapMessageImpl.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/axiom-spring-ws/src/main/java/org/apache/axiom/spring/ws/soap/SoapMessageImpl.java?rev=1648892&r1=1648891&r2=1648892&view=diff
==============================================================================
--- webservices/axiom/trunk/axiom-spring-ws/src/main/java/org/apache/axiom/spring/ws/soap/SoapMessageImpl.java (original)
+++ webservices/axiom/trunk/axiom-spring-ws/src/main/java/org/apache/axiom/spring/ws/soap/SoapMessageImpl.java Thu Jan 1 17:08:13 2015
@@ -54,9 +54,11 @@ final class SoapMessageImpl extends Abst
private SOAPMessage axiomMessage;
private final SourceExtractionStrategyStack extractionStrategyStack = new SourceExtractionStrategyStack();
private SoapEnvelopeImpl envelope;
+ private String soapAction;
- SoapMessageImpl(SOAPMessage axiomMessage, boolean autoCreateHeader) {
+ SoapMessageImpl(SOAPMessage axiomMessage, String soapAction, boolean autoCreateHeader) {
this.axiomMessage = axiomMessage;
+ this.soapAction = soapAction;
if (autoCreateHeader) {
envelope = new SoapEnvelopeImpl(this, axiomMessage.getSOAPEnvelope(), true);
}
@@ -70,14 +72,14 @@ final class SoapMessageImpl extends Abst
return envelope;
}
+ @Override
public String getSoapAction() {
- // TODO Auto-generated method stub
- return "\"\"";
+ return SoapUtils.escapeAction(soapAction);
}
+ @Override
public void setSoapAction(String soapAction) {
- // TODO Auto-generated method stub
- throw new UnsupportedOperationException();
+ this.soapAction = SoapUtils.unescapeAction(soapAction);
}
public Document getDocument() {
@@ -125,12 +127,19 @@ final class SoapMessageImpl extends Abst
public void writeTo(OutputStream outputStream) throws IOException {
OMOutputFormat outputFormat = new OMOutputFormat();
- outputFormat.setSOAP11(((SOAPFactory)axiomMessage.getOMFactory()).getSOAPVersion() == SOAP11Version.getSingleton());
+ boolean soap11 = ((SOAPFactory)axiomMessage.getOMFactory()).getSOAPVersion() == SOAP11Version.getSingleton();
+ outputFormat.setSOAP11(soap11);
if (outputStream instanceof TransportOutputStream) {
TransportOutputStream transportOutputStream = (TransportOutputStream)outputStream;
// TODO: ensure that charset is specified in content type
// TODO: omit XML declaration
- transportOutputStream.addHeader(TransportConstants.HEADER_CONTENT_TYPE, outputFormat.getContentType());
+ String contentType = outputFormat.getContentType();
+ if (soap11) {
+ transportOutputStream.addHeader(TransportConstants.HEADER_SOAP_ACTION, "\"" + soapAction + "\"");
+ } else {
+ contentType += "; action=\"" + soapAction + "\"";
+ }
+ transportOutputStream.addHeader(TransportConstants.HEADER_CONTENT_TYPE, contentType);
}
try {
axiomMessage.serializeAndConsume(outputStream);
Added: webservices/axiom/trunk/axiom-spring-ws/src/main/java/org/apache/axiom/spring/ws/soap/SoapUtils.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/axiom-spring-ws/src/main/java/org/apache/axiom/spring/ws/soap/SoapUtils.java?rev=1648892&view=auto
==============================================================================
--- webservices/axiom/trunk/axiom-spring-ws/src/main/java/org/apache/axiom/spring/ws/soap/SoapUtils.java (added)
+++ webservices/axiom/trunk/axiom-spring-ws/src/main/java/org/apache/axiom/spring/ws/soap/SoapUtils.java Thu Jan 1 17:08:13 2015
@@ -0,0 +1,37 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.axiom.spring.ws.soap;
+
+final class SoapUtils {
+ private SoapUtils() {}
+
+ static String escapeAction(String soapAction) {
+ return org.springframework.ws.soap.support.SoapUtils.escapeAction(soapAction);
+ }
+
+ static String unescapeAction(String headerValue) {
+ if (headerValue == null || headerValue.isEmpty()) {
+ return null;
+ } else if (headerValue.length() >= 2 && headerValue.charAt(0) == '"' && headerValue.charAt(headerValue.length()-1) == '"') {
+ return headerValue.substring(1, headerValue.length()-1);
+ } else {
+ return headerValue;
+ }
+ }
+}
Propchange: webservices/axiom/trunk/axiom-spring-ws/src/main/java/org/apache/axiom/spring/ws/soap/SoapUtils.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: webservices/axiom/trunk/testing/spring-ws-testsuite/src/main/java/org/apache/axiom/ts/springws/SpringWSTestSuiteBuilder.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/testing/spring-ws-testsuite/src/main/java/org/apache/axiom/ts/springws/SpringWSTestSuiteBuilder.java?rev=1648892&r1=1648891&r2=1648892&view=diff
==============================================================================
--- webservices/axiom/trunk/testing/spring-ws-testsuite/src/main/java/org/apache/axiom/ts/springws/SpringWSTestSuiteBuilder.java (original)
+++ webservices/axiom/trunk/testing/spring-ws-testsuite/src/main/java/org/apache/axiom/ts/springws/SpringWSTestSuiteBuilder.java Thu Jan 1 17:08:13 2015
@@ -26,6 +26,7 @@ import org.apache.axiom.ts.springws.scen
import org.apache.axiom.ts.springws.scenario.jaxb2.JAXB2Test;
import org.apache.axiom.ts.springws.scenario.jdom.ClientServerTest;
import org.apache.axiom.ts.springws.scenario.secureecho.SecureEchoTest;
+import org.apache.axiom.ts.springws.scenario.soapaction.SoapActionTest;
import org.apache.axiom.ts.springws.scenario.validation.ValidationTest;
import org.apache.axiom.ts.springws.scenario.wsadom.WSAddressingDOMTest;
import org.apache.axiom.ts.springws.soap.messagefactory.TestCreateWebServiceMessage;
@@ -66,5 +67,6 @@ public class SpringWSTestSuiteBuilder ex
addTest(new BrokerScenarioTest(config, spec));
addTest(new ValidationTest(config, spec));
addTest(new SecureEchoTest(config, spec));
+ addTest(new SoapActionTest(config, spec));
}
}
Added: webservices/axiom/trunk/testing/spring-ws-testsuite/src/main/java/org/apache/axiom/ts/springws/scenario/soapaction/EchoEndpoint.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/testing/spring-ws-testsuite/src/main/java/org/apache/axiom/ts/springws/scenario/soapaction/EchoEndpoint.java?rev=1648892&view=auto
==============================================================================
--- webservices/axiom/trunk/testing/spring-ws-testsuite/src/main/java/org/apache/axiom/ts/springws/scenario/soapaction/EchoEndpoint.java (added)
+++ webservices/axiom/trunk/testing/spring-ws-testsuite/src/main/java/org/apache/axiom/ts/springws/scenario/soapaction/EchoEndpoint.java Thu Jan 1 17:08:13 2015
@@ -0,0 +1,34 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.axiom.ts.springws.scenario.soapaction;
+
+import org.springframework.ws.server.endpoint.annotation.Endpoint;
+import org.springframework.ws.server.endpoint.annotation.RequestPayload;
+import org.springframework.ws.server.endpoint.annotation.ResponsePayload;
+import org.springframework.ws.soap.server.endpoint.annotation.SoapAction;
+import org.w3c.dom.Element;
+
+@Endpoint
+public class EchoEndpoint {
+ @SoapAction("http://www.example.com/echo")
+ @ResponsePayload
+ public Element echo(@RequestPayload Element request) {
+ return request;
+ }
+}
\ No newline at end of file
Propchange: webservices/axiom/trunk/testing/spring-ws-testsuite/src/main/java/org/apache/axiom/ts/springws/scenario/soapaction/EchoEndpoint.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: webservices/axiom/trunk/testing/spring-ws-testsuite/src/main/java/org/apache/axiom/ts/springws/scenario/soapaction/SoapActionTest.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/testing/spring-ws-testsuite/src/main/java/org/apache/axiom/ts/springws/scenario/soapaction/SoapActionTest.java?rev=1648892&view=auto
==============================================================================
--- webservices/axiom/trunk/testing/spring-ws-testsuite/src/main/java/org/apache/axiom/ts/springws/scenario/soapaction/SoapActionTest.java (added)
+++ webservices/axiom/trunk/testing/spring-ws-testsuite/src/main/java/org/apache/axiom/ts/springws/scenario/soapaction/SoapActionTest.java Thu Jan 1 17:08:13 2015
@@ -0,0 +1,55 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.axiom.ts.springws.scenario.soapaction;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.transform.dom.DOMResult;
+import javax.xml.transform.dom.DOMSource;
+
+import org.apache.axiom.ts.soap.SOAPSpec;
+import org.apache.axiom.ts.springws.scenario.ScenarioConfig;
+import org.apache.axiom.ts.springws.scenario.ScenarioTestCase;
+import org.springframework.ws.client.core.WebServiceTemplate;
+import org.springframework.ws.soap.client.core.SoapActionCallback;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+
+public class SoapActionTest extends ScenarioTestCase {
+ public SoapActionTest(ScenarioConfig config, SOAPSpec spec) {
+ super(config, spec);
+ }
+
+ @Override
+ protected void runTest() throws Throwable {
+ DocumentBuilder documentBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
+ Document requestDocument = documentBuilder.newDocument();
+ Element request = requestDocument.createElementNS("urn:test", "p:Echo");
+ request.setTextContent("Hello");
+ Document responseDocument = documentBuilder.newDocument();
+ context.getBean(WebServiceTemplate.class).sendSourceAndReceiveToResult(
+ new DOMSource(request),
+ new SoapActionCallback("http://www.example.com/echo"),
+ new DOMResult(responseDocument));
+ Element response = responseDocument.getDocumentElement();
+ assertEquals("urn:test", response.getNamespaceURI());
+ assertEquals("Echo", response.getLocalName());
+ assertEquals("Hello", response.getTextContent());
+ }
+}
Propchange: webservices/axiom/trunk/testing/spring-ws-testsuite/src/main/java/org/apache/axiom/ts/springws/scenario/soapaction/SoapActionTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: webservices/axiom/trunk/testing/spring-ws-testsuite/src/main/resources/org/apache/axiom/ts/springws/scenario/soapaction/client.xml
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/testing/spring-ws-testsuite/src/main/resources/org/apache/axiom/ts/springws/scenario/soapaction/client.xml?rev=1648892&view=auto
==============================================================================
--- webservices/axiom/trunk/testing/spring-ws-testsuite/src/main/resources/org/apache/axiom/ts/springws/scenario/soapaction/client.xml (added)
+++ webservices/axiom/trunk/testing/spring-ws-testsuite/src/main/resources/org/apache/axiom/ts/springws/scenario/soapaction/client.xml Thu Jan 1 17:08:13 2015
@@ -0,0 +1,27 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ Licensed to the Apache Software Foundation (ASF) under one
+ ~ or more contributor license agreements. See the NOTICE file
+ ~ distributed with this work for additional information
+ ~ regarding copyright ownership. The ASF licenses this file
+ ~ to you under the Apache License, Version 2.0 (the
+ ~ "License"); you may not use this file except in compliance
+ ~ with the License. You may obtain a copy of the License at
+ ~
+ ~ http://www.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ Unless required by applicable law or agreed to in writing,
+ ~ software distributed under the License is distributed on an
+ ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ ~ KIND, either express or implied. See the License for the
+ ~ specific language governing permissions and limitations
+ ~ under the License.
+ -->
+<beans xmlns="http://www.springframework.org/schema/beans"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd">
+ <bean class="org.springframework.ws.client.core.WebServiceTemplate">
+ <constructor-arg ref="messageFactory"/>
+ <property name="defaultUri" value="http://localhost:${port}/"/>
+ </bean>
+</beans>
Propchange: webservices/axiom/trunk/testing/spring-ws-testsuite/src/main/resources/org/apache/axiom/ts/springws/scenario/soapaction/client.xml
------------------------------------------------------------------------------
svn:eol-style = native
Added: webservices/axiom/trunk/testing/spring-ws-testsuite/src/main/resources/org/apache/axiom/ts/springws/scenario/soapaction/server.xml
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/testing/spring-ws-testsuite/src/main/resources/org/apache/axiom/ts/springws/scenario/soapaction/server.xml?rev=1648892&view=auto
==============================================================================
--- webservices/axiom/trunk/testing/spring-ws-testsuite/src/main/resources/org/apache/axiom/ts/springws/scenario/soapaction/server.xml (added)
+++ webservices/axiom/trunk/testing/spring-ws-testsuite/src/main/resources/org/apache/axiom/ts/springws/scenario/soapaction/server.xml Thu Jan 1 17:08:13 2015
@@ -0,0 +1,30 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ Licensed to the Apache Software Foundation (ASF) under one
+ ~ or more contributor license agreements. See the NOTICE file
+ ~ distributed with this work for additional information
+ ~ regarding copyright ownership. The ASF licenses this file
+ ~ to you under the Apache License, Version 2.0 (the
+ ~ "License"); you may not use this file except in compliance
+ ~ with the License. You may obtain a copy of the License at
+ ~
+ ~ http://www.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ Unless required by applicable law or agreed to in writing,
+ ~ software distributed under the License is distributed on an
+ ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ ~ KIND, either express or implied. See the License for the
+ ~ specific language governing permissions and limitations
+ ~ under the License.
+ -->
+<beans xmlns="http://www.springframework.org/schema/beans"
+ xmlns:context="http://www.springframework.org/schema/context"
+ xmlns:sws="http://www.springframework.org/schema/web-services"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="
+ http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
+ http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd
+ http://www.springframework.org/schema/web-services http://www.springframework.org/schema/web-services/web-services-2.0.xsd">
+ <context:component-scan base-package="org.apache.axiom.ts.springws.scenario.soapaction"/>
+ <sws:annotation-driven/>
+</beans>
Propchange: webservices/axiom/trunk/testing/spring-ws-testsuite/src/main/resources/org/apache/axiom/ts/springws/scenario/soapaction/server.xml
------------------------------------------------------------------------------
svn:eol-style = native