diff options
Diffstat (limited to 'winery/org.eclipse.winery.generators.ia/src/main/resources/template/java')
2 files changed, 103 insertions, 0 deletions
diff --git a/winery/org.eclipse.winery.generators.ia/src/main/resources/template/java/AbstractIAService.java.template b/winery/org.eclipse.winery.generators.ia/src/main/resources/template/java/AbstractIAService.java.template new file mode 100644 index 0000000..4d4d2a4 --- /dev/null +++ b/winery/org.eclipse.winery.generators.ia/src/main/resources/template/java/AbstractIAService.java.template @@ -0,0 +1,86 @@ +package IA_PACKAGE; + +import java.util.HashMap; +import java.util.List; +import java.util.Map.Entry; + +import javax.annotation.Resource; +import javax.xml.ws.WebServiceContext; + +import org.apache.cxf.headers.Header; +import org.apache.cxf.helpers.CastUtils; +import org.apache.cxf.jaxws.context.WrappedMessageContext; +import org.apache.cxf.message.Message; +import org.w3c.dom.Node; + +import org.eclipse.winery.highlevelrestapi.HighLevelRestApi; + +public abstract class AbstractIAService { + + @Resource + private WebServiceContext context; + + protected void sendResponse (HashMap<String,String> returnParameters) { + + // Extract message + WrappedMessageContext wrappedContext = (WrappedMessageContext) context.getMessageContext(); + Message message = wrappedContext.getWrappedMessage(); + + // Extract headers from message + List<Header> headers = CastUtils.cast((List<?>) message.get(Header.HEADER_LIST)); + + // Find ReplyTo and MessageID SOAP Header + String replyTo = null; + String messageID = null; + for (Header iter : headers) { + + Object headerObject = iter.getObject(); + + // Unmarshall to org.w3c.dom.Node + if (headerObject instanceof Node) { + Node node = (Node) headerObject; + String localPart = iter.getName().getLocalPart(); + String content = node.getTextContent(); + + // Extract ReplyTo Header value + if ("ReplyTo".equals(localPart)) { + replyTo = content; + } + + // Extract MessageID Header value + if ("MessageID".equals(localPart)) { + messageID = content; + } + } + } + + // Create asynchronous SOAP Response Message + StringBuilder builder = new StringBuilder(); + + builder.append("<soapenv:Envelope xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/' xmlns:sch='http://siserver.org/schema'>"); + builder.append(" <soapenv:Header/>"); + builder.append(" <soapenv:Body>"); + builder.append(" <sch:invokeResponse>"); + builder.append(" <sch:MessageID>" + messageID + "</sch:MessageID>"); + + // Insert return parameters into asynchronous SOAP Response Message + for (Entry<String, String> paramIter : returnParameters.entrySet()) { + + String key = paramIter.getKey(); + String value = paramIter.getValue(); + + builder.append(" <" + key + ">" + value + "</" + key +">"); + } + + builder.append(" </sch:invokeResponse>"); + builder.append(" </soapenv:Body>"); + builder.append("</soapenv:Envelope>"); + + // Send SOAP Response Message back to requester + if(replyTo == null) { + System.err.println("No 'ReplyTo' header found!\nTherefore, reply message is printed here:\n" + builder.toString()); + } else { + HighLevelRestApi.Post(replyTo, builder.toString(), ""); + } + } +} diff --git a/winery/org.eclipse.winery.generators.ia/src/main/resources/template/java/TemplateService.java.template b/winery/org.eclipse.winery.generators.ia/src/main/resources/template/java/TemplateService.java.template new file mode 100644 index 0000000..692905e --- /dev/null +++ b/winery/org.eclipse.winery.generators.ia/src/main/resources/template/java/TemplateService.java.template @@ -0,0 +1,17 @@ +package IA_PACKAGE; + +import java.util.HashMap; + +import javax.jws.Oneway; +import javax.jws.WebMethod; +import javax.jws.WebParam; +import javax.jws.WebService; +import javax.jws.soap.SOAPBinding; +import javax.xml.bind.annotation.XmlElement; + +@WebService +public class IA_CLASS_NAME extends AbstractIAService { + +GENERATED_WEBSERVICE_METHODS + +}
\ No newline at end of file |