-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Parameter names of web service methods should be camelcase - Add a default logger to the service template - Redirect log output to System.out (with debug level) - Add shared utility class for easily access SOAP headers - Move AbstractIAService.java to shared classes Signed-off-by: Michael Wurster <miwurster@googlemail.com>
- Loading branch information
Showing
9 changed files
with
291 additions
and
233 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
94 changes: 94 additions & 0 deletions
94
...y.generators.ia/src/main/java/org/eclipse/winery/generators/ia/jaxws/AbstractService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2018 Contributors to the Eclipse Foundation | ||
* | ||
* See the NOTICE file(s) distributed with this work for additional | ||
* information regarding copyright ownership. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0, or the Apache Software License 2.0 | ||
* which is available at https://www.apache.org/licenses/LICENSE-2.0. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 | ||
*******************************************************************************/ | ||
|
||
package org.eclipse.winery.generators.ia.jaxws; | ||
|
||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map.Entry; | ||
|
||
import javax.annotation.Resource; | ||
import javax.xml.ws.WebServiceContext; | ||
|
||
import org.eclipse.winery.highlevelrestapi.HighLevelRestApi; | ||
|
||
import org.apache.cxf.headers.Header; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.w3c.dom.Node; | ||
|
||
/** | ||
* Abstract class providing common functionality for JAX-WS web services. | ||
*/ | ||
public abstract class AbstractService { | ||
|
||
private static final Logger logger = LoggerFactory.getLogger(AbstractService.class); | ||
|
||
@Resource | ||
protected WebServiceContext ctx; | ||
|
||
protected void sendResponse(HashMap<String, String> returnParameters) { | ||
|
||
// Extract headers from message | ||
List<Header> headers = Headers.asList(ctx); | ||
|
||
// 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) { | ||
logger.warn("No 'ReplyTo' header found! Therefore, print reply message:\n{}", builder.toString()); | ||
} else { | ||
HighLevelRestApi.Post(replyTo, builder.toString(), ""); | ||
} | ||
} | ||
} |
53 changes: 53 additions & 0 deletions
53
...se.winery.generators.ia/src/main/java/org/eclipse/winery/generators/ia/jaxws/Headers.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2018 Contributors to the Eclipse Foundation | ||
* | ||
* See the NOTICE file(s) distributed with this work for additional | ||
* information regarding copyright ownership. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0, or the Apache Software License 2.0 | ||
* which is available at https://www.apache.org/licenses/LICENSE-2.0. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 | ||
*******************************************************************************/ | ||
|
||
package org.eclipse.winery.generators.ia.jaxws; | ||
|
||
import java.util.ArrayList; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import javax.xml.ws.WebServiceContext; | ||
import javax.xml.ws.handler.MessageContext; | ||
|
||
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.Element; | ||
|
||
/** | ||
* Helper class to provide easy access to SOAP headers. | ||
*/ | ||
public final class Headers { | ||
|
||
public static Map<String, String> asMap(final WebServiceContext ctx) { | ||
Map<String, String> headers = new HashMap<>(); | ||
for (Header h : asList(ctx)) { | ||
Element n = (Element) h.getObject(); | ||
headers.put(n.getLocalName(), n.getTextContent()); | ||
} | ||
return headers; | ||
} | ||
|
||
public static List<Header> asList(final WebServiceContext ctx) { | ||
MessageContext messageContext = ctx.getMessageContext(); | ||
if (messageContext instanceof WrappedMessageContext) { | ||
Message message = ((WrappedMessageContext) messageContext).getWrappedMessage(); | ||
return CastUtils.cast((List<?>) message.get(Header.HEADER_LIST)); | ||
} | ||
return new ArrayList<>(); | ||
} | ||
} |
86 changes: 0 additions & 86 deletions
86
...pse.winery.generators.ia/src/main/resources/template/java/AbstractIAService.java.template
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.