Skip to content

Commit aee54ec

Browse files
committed
Initial SOAP Component
0 parents  commit aee54ec

23 files changed

+2778
-0
lines changed

README

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
SOAP Component for SwitchYard
2+
=============================
3+
A barebone implementation that provides the following features:
4+
5+
a) Allows SwitchYard services to be exposed as a WebService.
6+
b) Allows SwitchYard services to invoke externally/internally hosted WebServices.
7+
c) Uses pure JAX-WS Dispatch and Provider APIs.
8+
9+
Test
10+
-----
11+
Includes these usecases:
12+
13+
1. Invoke a oneway WebService
14+
2. Invoke a request-response WebService
15+
3. Invoke the request-response WebService with improper data
16+
17+
|-----------------------------------------------------------------|
18+
| SOAPGateway |
19+
| |-----------------------------| |-----------------------------| |
20+
| | Outbound | | Inbound | |
21+
| | |------------| |----------| | | |----------| |------------| | |
22+
| | | Decomposer | | Composer | | | | Composer | | Decomposer | | |
23+
| | |------------| |----------| | | |----------| |------------| | |
24+
| |-----------------------------| |-----------------------------| |
25+
|-----------------------------------------------------------------|
26+
27+
SwitchYard Request --> Outbound --> Decomposer --> WebService
28+
WebService Response --> Outbound --> Composer --> SwitchYard Service
29+
30+
WebService Client Request --> Inbound --> Composer --> SwitchYard Service
31+
SwitchYard Response --> Inbound --> Decomposer --> WebService
32+
33+
Features to be added
34+
--------------------
35+
SOAP Header processing
36+
HTTP Header/Properties processing
37+
Throttling
38+
39+
40+
Utility classes have been re-used from JBossESB 4.9.
41+

pom.xml

+82
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
~ JBoss, Home of Professional Open Source.
4+
~ Copyright 2010, Red Hat, Inc., and individual contributors
5+
~ as indicated by the @author tags. See the copyright.txt file in the
6+
~ distribution for a full listing of individual contributors.
7+
~
8+
~ This is free software; you can redistribute it and/or modify it
9+
~ under the terms of the GNU Lesser General Public License as
10+
~ published by the Free Software Foundation; either version 2.1 of
11+
~ the License, or (at your option) any later version.
12+
~
13+
~ This software is distributed in the hope that it will be useful,
14+
~ but WITHOUT ANY WARRANTY; without even the implied warranty of
15+
~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16+
~ Lesser General Public License for more details.
17+
~
18+
~ You should have received a copy of the GNU Lesser General Public
19+
~ License along with this software; if not, write to the Free
20+
~ Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
21+
~ 02110-1301 USA, or see the FSF site: http://www.fsf.org.
22+
-->
23+
24+
<project xmlns="http://maven.apache.org/POM/4.0.0"
25+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
26+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
27+
<modelVersion>4.0.0</modelVersion>
28+
29+
<parent>
30+
<groupId>org.switchyard</groupId>
31+
<artifactId>core-parent</artifactId>
32+
<version>1.0-SNAPSHOT</version>
33+
</parent>
34+
35+
<groupId>org.switchyard</groupId>
36+
<artifactId>component-soap</artifactId>
37+
<name>Switchyard: SOAP Component</name>
38+
<version>1.0-SNAPSHOT</version>
39+
40+
<!-- Properties -->
41+
<properties>
42+
<version.switchyard>1.0-SNAPSHOT</version.switchyard>
43+
<version.javassist>3.12.1.GA</version.javassist>
44+
<version.log4j>1.2.16</version.log4j>
45+
<version.woodstox>4.0.9</version.woodstox>
46+
<version.wsdl4j>1.6.2</version.wsdl4j>
47+
</properties>
48+
49+
<dependencies>
50+
<dependency>
51+
<groupId>org.switchyard</groupId>
52+
<artifactId>core-api</artifactId>
53+
<version>${version.switchyard}</version>
54+
</dependency>
55+
<dependency>
56+
<groupId>org.switchyard</groupId>
57+
<artifactId>core-runtime</artifactId>
58+
<version>${version.switchyard}</version>
59+
</dependency>
60+
<dependency>
61+
<groupId>org.codehaus.woodstox</groupId>
62+
<artifactId>woodstox-core-lgpl</artifactId>
63+
<version>${version.woodstox}</version>
64+
</dependency>
65+
<dependency>
66+
<groupId>wsdl4j</groupId>
67+
<artifactId>wsdl4j</artifactId>
68+
<version>${version.wsdl4j}</version>
69+
</dependency>
70+
<dependency>
71+
<groupId>javassist</groupId>
72+
<artifactId>javassist</artifactId>
73+
<version>${version.javassist}</version>
74+
</dependency>
75+
<dependency>
76+
<groupId>log4j</groupId>
77+
<artifactId>log4j</artifactId>
78+
<version>${version.log4j}</version>
79+
</dependency>
80+
</dependencies>
81+
82+
</project>

src/main/config/log4jconfig.xml

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
3+
<log4j:configuration xmlns:log4j='http://jakarta.apache.org/log4j/'>
4+
5+
<appender name="STDOUT" class="org.apache.log4j.ConsoleAppender">
6+
<layout class="org.apache.log4j.PatternLayout">
7+
<param name="ConversionPattern"
8+
value="%d{HH:mm:ss,SSS} %-5p [%c{1}] %m%n"/>
9+
</layout>
10+
</appender>
11+
12+
<logger name="org.switchyard">
13+
<level value="INFO"/>
14+
</logger>
15+
16+
<root>
17+
<level value="ERROR"/>
18+
<appender-ref ref="STDOUT"/>
19+
</root>
20+
21+
</log4j:configuration>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*
2+
* JBoss, Home of Professional Open Source.
3+
* Copyright 2010, Red Hat, Inc., and individual contributors
4+
* as indicated by the @author tags. See the copyright.txt file in the
5+
* distribution for a full listing of individual contributors.
6+
*
7+
* This is free software; you can redistribute it and/or modify it
8+
* under the terms of the GNU Lesser General Public License as
9+
* published by the Free Software Foundation; either version 2.1 of
10+
* the License, or (at your option) any later version.
11+
*
12+
* This software is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15+
* Lesser General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU Lesser General Public
18+
* License along with this software; if not, write to the Free
19+
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20+
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21+
*/
22+
23+
package org.switchyard.soap;
24+
25+
import javax.xml.soap.SOAPMessage;
26+
import javax.xml.ws.Provider;
27+
28+
29+
/**
30+
* This is the abstract base class for a SOAP messages.
31+
* @author <a href="mailto:[email protected]">Magesh Kumar B</a>
32+
*/
33+
public abstract class BaseWebService implements Provider<SOAPMessage> {
34+
private InboundHandler _serviceConsumer;
35+
36+
protected BaseWebService() {
37+
}
38+
39+
/**
40+
* Sets the service handler.
41+
* @param serviceConsumer the service handler.
42+
*/
43+
public void setConsumer(final InboundHandler serviceConsumer) {
44+
_serviceConsumer = serviceConsumer;
45+
}
46+
47+
/**
48+
* The Webservice implementation method, invokes the service handler.
49+
* @param request the SOAP request
50+
* @return the SOAP response
51+
*/
52+
public SOAPMessage invoke(final SOAPMessage request) {
53+
return _serviceConsumer.invoke(request);
54+
}
55+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
/*
2+
* JBoss, Home of Professional Open Source.
3+
* Copyright 2010, Red Hat, Inc., and individual contributors
4+
* as indicated by the @author tags. See the copyright.txt file in the
5+
* distribution for a full listing of individual contributors.
6+
*
7+
* This is free software; you can redistribute it and/or modify it
8+
* under the terms of the GNU Lesser General Public License as
9+
* published by the Free Software Foundation; either version 2.1 of
10+
* the License, or (at your option) any later version.
11+
*
12+
* This software is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15+
* Lesser General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU Lesser General Public
18+
* License along with this software; if not, write to the Free
19+
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20+
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21+
*/
22+
23+
package org.switchyard.soap;
24+
25+
import java.io.StringWriter;
26+
import java.util.Iterator;
27+
28+
import javax.xml.soap.Node;
29+
import javax.xml.soap.SOAPBody;
30+
import javax.xml.soap.SOAPElement;
31+
import javax.xml.soap.SOAPException;
32+
import javax.xml.soap.SOAPMessage;
33+
import javax.xml.stream.XMLEventWriter;
34+
import javax.xml.transform.stream.StreamResult;
35+
36+
import org.switchyard.Message;
37+
import org.switchyard.MessageBuilder;
38+
import org.switchyard.soap.util.XMLHelper;
39+
40+
/**
41+
* The default implementation of MessageComposer simply copies the SOAP body into
42+
* the Message and SOAP headers into the Message's context.
43+
*/
44+
public class DefaultMessageComposer implements MessageComposer {
45+
46+
/**
47+
* Create a Message from the given SOAP message.
48+
* @param soapMessage the SOAP message to be converted
49+
* @return a Message
50+
* @throws SOAPException If the SOAP message is not correct.
51+
*/
52+
public Message compose(final SOAPMessage soapMessage) throws SOAPException {
53+
Message message = MessageBuilder.newInstance().buildMessage();
54+
55+
final SOAPBody soapBody = soapMessage.getSOAPBody();
56+
if (soapBody == null) {
57+
throw new SOAPException("Missing SOAP body from request");
58+
}
59+
final Iterator children = soapBody.getChildElements();
60+
boolean found = false;
61+
62+
try {
63+
while (children.hasNext()) {
64+
final Node node = (Node) children.next();
65+
if (node instanceof SOAPElement) {
66+
if (found) {
67+
throw new SOAPException("Found multiple SOAPElements in SOAPBody");
68+
}
69+
final StringWriter sw = new StringWriter();
70+
final XMLEventWriter writer = XMLHelper.getXMLEventWriter(new StreamResult(sw));
71+
XMLHelper.readDomNode(node, writer, true);
72+
message.setContent(sw.toString());
73+
found = true;
74+
}
75+
}
76+
} catch (Exception ex) {
77+
throw new SOAPException(ex);
78+
}
79+
80+
if (!found) {
81+
throw new SOAPException("Could not find SOAPElement in SOAPBody");
82+
}
83+
84+
return message;
85+
}
86+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/*
2+
* JBoss, Home of Professional Open Source.
3+
* Copyright 2010, Red Hat, Inc., and individual contributors
4+
* as indicated by the @author tags. See the copyright.txt file in the
5+
* distribution for a full listing of individual contributors.
6+
*
7+
* This is free software; you can redistribute it and/or modify it
8+
* under the terms of the GNU Lesser General Public License as
9+
* published by the Free Software Foundation; either version 2.1 of
10+
* the License, or (at your option) any later version.
11+
*
12+
* This software is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15+
* Lesser General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU Lesser General Public
18+
* License along with this software; if not, write to the Free
19+
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20+
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21+
*/
22+
23+
package org.switchyard.soap;
24+
25+
import javax.xml.soap.SOAPException;
26+
import javax.xml.soap.SOAPMessage;
27+
28+
import org.switchyard.Message;
29+
import org.switchyard.soap.util.SOAPUtil;
30+
import org.w3c.dom.Document;
31+
32+
/**
33+
* The default implementation of MessageDecomposer simply copies the Message body onto SOAP
34+
* and adds SOAP headers from the Message's context.
35+
*/
36+
public class DefaultMessageDecomposer implements MessageDecomposer {
37+
38+
/**
39+
* Extract the SOAPMessage from Message.
40+
* @param message a Message to be converted
41+
* @return the SOAPMessage
42+
* @throws SOAPException If the SOAP message could not be created/formatted.
43+
*/
44+
public SOAPMessage decompose(final Message message) throws SOAPException {
45+
if (SOAPUtil.SOAP_MESSAGE_FACTORY == null) {
46+
throw new SOAPException("Failed to instantiate SOAP Message Factory");
47+
}
48+
49+
final SOAPMessage response = SOAPUtil.SOAP_MESSAGE_FACTORY.createMessage();
50+
if (message != null) {
51+
final Object input = message.getContent();
52+
if (input == null) {
53+
throw new SOAPException("Null response from service");
54+
}
55+
final String soapRes = input.toString();
56+
try {
57+
final Document root = SOAPUtil.parseAsDom(soapRes);
58+
response.getSOAPBody().addDocument(root);
59+
} catch (Exception e) {
60+
throw new SOAPException("Unable to parse SOAP Message", e);
61+
}
62+
}
63+
return response;
64+
}
65+
}

0 commit comments

Comments
 (0)