Skip to content

Commit 6b300f5

Browse files
committed
CXF workaround for jakartaee/saaj-api#43
Signed-off-by: Pierre-Alexandre Meyer <[email protected]>
1 parent 082b044 commit 6b300f5

File tree

2 files changed

+95
-3
lines changed

2 files changed

+95
-3
lines changed

pom.xml

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,36 @@
6363
<groupId>com.google.inject</groupId>
6464
<artifactId>guice</artifactId>
6565
</dependency>
66+
<dependency>
67+
<groupId>com.sun.xml.messaging.saaj</groupId>
68+
<artifactId>saaj-impl</artifactId>
69+
<version>3.0.1</version>
70+
</dependency>
71+
<dependency>
72+
<groupId>jakarta.annotation</groupId>
73+
<artifactId>jakarta.annotation-api</artifactId>
74+
<version>2.1.1</version>
75+
</dependency>
6676
<dependency>
6777
<groupId>jakarta.servlet</groupId>
6878
<artifactId>jakarta.servlet-api</artifactId>
6979
<scope>provided</scope>
7080
</dependency>
81+
<dependency>
82+
<groupId>jakarta.xml.bind</groupId>
83+
<artifactId>jakarta.xml.bind-api</artifactId>
84+
<version>3.0.1</version>
85+
</dependency>
86+
<dependency>
87+
<groupId>jakarta.xml.soap</groupId>
88+
<artifactId>jakarta.xml.soap-api</artifactId>
89+
<version>3.0.1</version>
90+
</dependency>
91+
<dependency>
92+
<groupId>jakarta.xml.ws</groupId>
93+
<artifactId>jakarta.xml.ws-api</artifactId>
94+
<version>3.0.1</version>
95+
</dependency>
7196
<dependency>
7297
<groupId>javax.inject</groupId>
7398
<artifactId>javax.inject</artifactId>
@@ -77,11 +102,36 @@
77102
<artifactId>joda-time</artifactId>
78103
<scope>provided</scope>
79104
</dependency>
105+
<dependency>
106+
<groupId>org.apache.cxf</groupId>
107+
<artifactId>cxf-core</artifactId>
108+
<version>4.0.3</version>
109+
</dependency>
110+
<dependency>
111+
<groupId>org.apache.cxf</groupId>
112+
<artifactId>cxf-rt-bindings-soap</artifactId>
113+
<version>4.0.3</version>
114+
</dependency>
115+
<dependency>
116+
<groupId>org.apache.cxf</groupId>
117+
<artifactId>cxf-rt-frontend-jaxws</artifactId>
118+
<version>4.0.3</version>
119+
</dependency>
120+
<dependency>
121+
<groupId>org.apache.cxf</groupId>
122+
<artifactId>cxf-rt-transports-http</artifactId>
123+
<version>4.0.3</version>
124+
</dependency>
80125
<dependency>
81126
<groupId>org.apache.felix</groupId>
82127
<artifactId>org.apache.felix.framework</artifactId>
83128
<scope>provided</scope>
84129
</dependency>
130+
<dependency>
131+
<groupId>org.glassfish.jaxb</groupId>
132+
<artifactId>jaxb-runtime</artifactId>
133+
<version>3.0.1</version>
134+
</dependency>
85135
<dependency>
86136
<groupId>org.jooby</groupId>
87137
<artifactId>jooby</artifactId>

src/main/java/org/killbill/billing/plugin/helloworld/HelloWorldActivator.java

Lines changed: 45 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,14 @@
1919

2020
package org.killbill.billing.plugin.helloworld;
2121

22+
import java.io.ByteArrayOutputStream;
23+
import java.io.IOException;
2224
import java.util.Hashtable;
2325
import java.util.Properties;
24-
2526
import javax.servlet.Servlet;
2627
import javax.servlet.http.HttpServlet;
27-
28+
import javax.xml.namespace.QName;
29+
import org.killbill.billing.invoice.plugin.api.InvoiceFormatterFactory;
2830
import org.killbill.billing.invoice.plugin.api.InvoicePluginApi;
2931
import org.killbill.billing.osgi.api.Healthcheck;
3032
import org.killbill.billing.osgi.api.OSGIPluginProperties;
@@ -38,7 +40,16 @@
3840
import org.killbill.billing.plugin.core.resources.jooby.PluginAppBuilder;
3941
import org.osgi.framework.BundleContext;
4042
import org.osgi.util.tracker.ServiceTracker;
41-
import org.killbill.billing.invoice.plugin.api.InvoiceFormatterFactory;
43+
import jakarta.xml.soap.MessageFactory;
44+
import jakarta.xml.soap.SOAPBody;
45+
import jakarta.xml.soap.SOAPElement;
46+
import jakarta.xml.soap.SOAPEnvelope;
47+
import jakarta.xml.soap.SOAPException;
48+
import jakarta.xml.soap.SOAPMessage;
49+
import jakarta.xml.soap.SOAPPart;
50+
import jakarta.xml.ws.Dispatch;
51+
import jakarta.xml.ws.Service;
52+
import jakarta.xml.ws.soap.SOAPBinding;
4253

4354
public class HelloWorldActivator extends KillbillActivatorBase {
4455

@@ -99,6 +110,37 @@ public void start(final BundleContext context) throws Exception {
99110
registerServlet(context, httpServlet);
100111

101112
registerHandlers();
113+
114+
final ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
115+
Thread.currentThread().setContextClassLoader(this.getClass().getClassLoader());
116+
try {
117+
soap();
118+
} finally {
119+
Thread.currentThread().setContextClassLoader(contextClassLoader);
120+
}
121+
}
122+
123+
private void soap() throws SOAPException, IOException {
124+
String endpointAddress = "http://www.dneonline.com/calculator.asmx";
125+
MessageFactory factory = MessageFactory.newInstance();
126+
SOAPMessage request = factory.createMessage();
127+
SOAPPart soapPart = request.getSOAPPart();
128+
SOAPEnvelope envelope = soapPart.getEnvelope();
129+
SOAPBody body = envelope.getBody();
130+
SOAPElement operation = body.addChildElement("Add", "", "http://tempuri.org/");
131+
operation.addChildElement("intA").addTextNode("5");
132+
operation.addChildElement("intB").addTextNode("7");
133+
request.saveChanges();
134+
QName serviceName = new QName("http://tempuri.org/", "Calculator");
135+
QName portName = new QName("http://tempuri.org/", "CalculatorSoap");
136+
Service service = Service.create(serviceName);
137+
service.addPort(portName, SOAPBinding.SOAP11HTTP_BINDING, endpointAddress);
138+
Dispatch<SOAPMessage> dispatch = service.createDispatch(portName, SOAPMessage.class, Service.Mode.MESSAGE);
139+
System.out.println("Sending 'Add' request to the public Calculator service...");
140+
SOAPMessage response = dispatch.invoke(request);
141+
ByteArrayOutputStream out = new ByteArrayOutputStream();
142+
response.writeTo(out);
143+
System.out.println("\nSOAP Response:\n" + new String(out.toByteArray()));
102144
}
103145

104146
@Override

0 commit comments

Comments
 (0)