diff options
author | 2016-08-31 16:47:33 +0800 | |
---|---|---|
committer | 2016-08-31 16:47:33 +0800 | |
commit | fa49e78cc199526a9e33b59c5194f8e3bf0f0952 (patch) | |
tree | 3478e867a8f304266dbceca6e992cceca410ede4 /winery/org.eclipse.winery.generators.ia/src/main/resources/template/java/AbstractIAService.java.template | |
parent | 159d40f0011559c8f82338b29dca1bffd700f2c8 (diff) |
Add winery source code
Change-Id: I1c5088121d79b71098c3cba1996c6f784737532e
Issue-id: TOSCA-49
Signed-off-by: huangjian <huang.jian12@zte.com.cn>
Diffstat (limited to 'winery/org.eclipse.winery.generators.ia/src/main/resources/template/java/AbstractIAService.java.template')
-rw-r--r-- | winery/org.eclipse.winery.generators.ia/src/main/resources/template/java/AbstractIAService.java.template | 86 |
1 files changed, 86 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(), ""); + } + } +} |