|
19 | 19 |
|
20 | 20 | package org.killbill.billing.plugin.helloworld; |
21 | 21 |
|
| 22 | +import java.io.ByteArrayOutputStream; |
| 23 | +import java.io.IOException; |
22 | 24 | import java.util.Hashtable; |
23 | 25 | import java.util.Properties; |
24 | | - |
25 | 26 | import javax.servlet.Servlet; |
26 | 27 | import javax.servlet.http.HttpServlet; |
27 | | - |
| 28 | +import javax.xml.namespace.QName; |
| 29 | +import org.killbill.billing.invoice.plugin.api.InvoiceFormatterFactory; |
28 | 30 | import org.killbill.billing.invoice.plugin.api.InvoicePluginApi; |
29 | 31 | import org.killbill.billing.osgi.api.Healthcheck; |
30 | 32 | import org.killbill.billing.osgi.api.OSGIPluginProperties; |
|
38 | 40 | import org.killbill.billing.plugin.core.resources.jooby.PluginAppBuilder; |
39 | 41 | import org.osgi.framework.BundleContext; |
40 | 42 | 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; |
42 | 53 |
|
43 | 54 | public class HelloWorldActivator extends KillbillActivatorBase { |
44 | 55 |
|
@@ -99,6 +110,37 @@ public void start(final BundleContext context) throws Exception { |
99 | 110 | registerServlet(context, httpServlet); |
100 | 111 |
|
101 | 112 | 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())); |
102 | 144 | } |
103 | 145 |
|
104 | 146 | @Override |
|
0 commit comments