From c0604184b2aa8cff924ca783ec6b36f1f5988775 Mon Sep 17 00:00:00 2001 From: Zhaoxing Date: Tue, 8 Aug 2017 14:02:53 +0800 Subject: init code Change-Id: Icd0948118397b256da70dfbcbbec5520dc5eafd4 Signed-off-by: Zhaoxing --- .../bpel4restlight/util/Bpel4RestLightUtil.java | 113 +++++++++++++++++++++ 1 file changed, 113 insertions(+) create mode 100644 wso2/wso2bpel-ext/wso2bpel-core/BPEL4RESTLight/src/main/java/de/unistuttgart/iaas/bpel/extensions/bpel4restlight/util/Bpel4RestLightUtil.java (limited to 'wso2/wso2bpel-ext/wso2bpel-core/BPEL4RESTLight/src/main/java/de/unistuttgart/iaas/bpel/extensions/bpel4restlight/util/Bpel4RestLightUtil.java') diff --git a/wso2/wso2bpel-ext/wso2bpel-core/BPEL4RESTLight/src/main/java/de/unistuttgart/iaas/bpel/extensions/bpel4restlight/util/Bpel4RestLightUtil.java b/wso2/wso2bpel-ext/wso2bpel-core/BPEL4RESTLight/src/main/java/de/unistuttgart/iaas/bpel/extensions/bpel4restlight/util/Bpel4RestLightUtil.java new file mode 100644 index 0000000..1c9d7d1 --- /dev/null +++ b/wso2/wso2bpel-ext/wso2bpel-core/BPEL4RESTLight/src/main/java/de/unistuttgart/iaas/bpel/extensions/bpel4restlight/util/Bpel4RestLightUtil.java @@ -0,0 +1,113 @@ +/** + * Copyright 2011 IAAS University of Stuttgart
+ *
+ * + * @author uwe.breitenbuecher@iaas.uni-stuttgart.de + * + */ +package de.unistuttgart.iaas.bpel.extensions.bpel4restlight.util; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.apache.ode.bpel.common.FaultException; +import org.apache.ode.bpel.runtime.extension.ExtensionContext; +import org.w3c.dom.Element; +import org.w3c.dom.Node; + +import de.unistuttgart.iaas.bpel.extensions.bpel4restlight.Bpel4RestLightOperation; +import de.unistuttgart.iaas.bpel.extensions.bpel4restlight.MethodAttribute; +import de.unistuttgart.iaas.xml.DomXmlConverter; + + +public class Bpel4RestLightUtil { + protected static final Log log = LogFactory.getLog(Bpel4RestLightUtil.class); + /** + * This function extracts the requestPayload specified in the passed + * element. This requestPayload is either the content contained in a special + * BPEL-Variable which is referenced by name by a special attribute of the + * passed element or the content contained in the first child node of the + * passed element + * + * @param context ExtensionContext + * @param element Element from which the requestPayload has to be extracted + * @return RequestPayload as String + * @throws FaultException + */ + public static String extractRequestPayload(ExtensionContext context, Element element) throws FaultException { + + String requestPayload = ""; + + String requestPayloadVariableName = getMethodAttributeValue(element, MethodAttribute.REQUESTPAYLOADVARIABLE); + + if (requestPayloadVariableName != null && requestPayloadVariableName != "") { + Node requestVariableNode = context.readVariable(requestPayloadVariableName); + if (requestVariableNode.getLocalName().equals("temporary-simple-type-wrapper")) { + Bpel4RestLightOperation.wrapper = "temporary-simple-type-wrapper"; + requestPayload = DomXmlConverter.nodeToString(requestVariableNode, "temporary-simple-type-wrapper"); + } else { + requestPayload = DomXmlConverter.nodeToString(requestVariableNode, null); + } + log.debug("The pure request variable as String: \n" + DomXmlConverter.nodeToString(requestVariableNode, null) + "\n"); + } + + return requestPayload; + } + + public static String extractAcceptHeader(ExtensionContext context, Element element) throws FaultException { + return getMethodAttributeValue(element, MethodAttribute.ACCEPTHEADER); + } + + public static String extractContentTypeHeader(ExtensionContext context, Element element) throws FaultException { + return getMethodAttributeValue(element, MethodAttribute.CONTENTTYPE); + } + + /** + * This function extracts special predefined attributes (see + * {@link MethodAttribute}) from a passed DOM-Element + * + * @param element Element containing the requested Attribute-Value + * @param methodAttribute Attribute whose content has to be returned + * @return Value / Content of the attribute + */ + public static String getMethodAttributeValue(Element element, MethodAttribute methodAttribute) { + + String result = ""; + + switch (methodAttribute) { + + case REQUESTURI: + result = element.getAttribute("uri"); + + if (result == null || "".equals(result)) { + result = element.getAttribute("requestUri"); + } + break; + case REQUESTPAYLOADVARIABLE: + result = element.getAttribute("request"); + + if (result == null || "".equals(result)) { + result = element.getAttribute("requestPayload"); + } + break; + case RESPONSEPAYLOADVARIABLE: + result = element.getAttribute("response"); + + if (result == null || "".equals(result)) { + result = element.getAttribute("responsePayload"); + } + break; + case STATUSCODEVARIABLE: + result = element.getAttribute("statusCode"); + break; + case ACCEPTHEADER: + result = element.getAttribute("accept"); + break; + case CONTENTTYPE: + result = element.getAttribute("contentType"); + break; + } + + return result; + } + +} -- cgit 1.2.3-korg