2 * Copyright 2011 IAAS University of Stuttgart <br>
5 * @author uwe.breitenbuecher@iaas.uni-stuttgart.de
8 package de.unistuttgart.iaas.bpel.extensions.bpel4restlight.util;
10 import org.apache.commons.logging.Log;
11 import org.apache.commons.logging.LogFactory;
12 import org.apache.ode.bpel.common.FaultException;
13 import org.apache.ode.bpel.runtime.extension.ExtensionContext;
14 import org.w3c.dom.Element;
15 import org.w3c.dom.Node;
17 import de.unistuttgart.iaas.bpel.extensions.bpel4restlight.Bpel4RestLightOperation;
18 import de.unistuttgart.iaas.bpel.extensions.bpel4restlight.MethodAttribute;
19 import de.unistuttgart.iaas.xml.DomXmlConverter;
22 public class Bpel4RestLightUtil {
23 protected static final Log log = LogFactory.getLog(Bpel4RestLightUtil.class);
25 * This function extracts the requestPayload specified in the passed
26 * element. This requestPayload is either the content contained in a special
27 * BPEL-Variable which is referenced by name by a special attribute of the
28 * passed element or the content contained in the first child node of the
31 * @param context ExtensionContext
32 * @param element Element from which the requestPayload has to be extracted
33 * @return RequestPayload as String
34 * @throws FaultException
36 public static String extractRequestPayload(ExtensionContext context, Element element) throws FaultException {
38 String requestPayload = "";
40 String requestPayloadVariableName = getMethodAttributeValue(element, MethodAttribute.REQUESTPAYLOADVARIABLE);
42 if (requestPayloadVariableName != null && requestPayloadVariableName != "") {
43 Node requestVariableNode = context.readVariable(requestPayloadVariableName);
44 if (requestVariableNode.getLocalName().equals("temporary-simple-type-wrapper")) {
45 Bpel4RestLightOperation.wrapper = "temporary-simple-type-wrapper";
46 requestPayload = DomXmlConverter.nodeToString(requestVariableNode, "temporary-simple-type-wrapper");
48 requestPayload = DomXmlConverter.nodeToString(requestVariableNode, null);
50 log.debug("The pure request variable as String: \n" + DomXmlConverter.nodeToString(requestVariableNode, null) + "\n");
53 return requestPayload;
56 public static String extractAcceptHeader(ExtensionContext context, Element element) throws FaultException {
57 return getMethodAttributeValue(element, MethodAttribute.ACCEPTHEADER);
60 public static String extractContentTypeHeader(ExtensionContext context, Element element) throws FaultException {
61 return getMethodAttributeValue(element, MethodAttribute.CONTENTTYPE);
65 * This function extracts special predefined attributes (see
66 * {@link MethodAttribute}) from a passed DOM-Element
68 * @param element Element containing the requested Attribute-Value
69 * @param methodAttribute Attribute whose content has to be returned
70 * @return Value / Content of the attribute
72 public static String getMethodAttributeValue(Element element, MethodAttribute methodAttribute) {
76 switch (methodAttribute) {
79 result = element.getAttribute("uri");
81 if (result == null || "".equals(result)) {
82 result = element.getAttribute("requestUri");
85 case REQUESTPAYLOADVARIABLE:
86 result = element.getAttribute("request");
88 if (result == null || "".equals(result)) {
89 result = element.getAttribute("requestPayload");
92 case RESPONSEPAYLOADVARIABLE:
93 result = element.getAttribute("response");
95 if (result == null || "".equals(result)) {
96 result = element.getAttribute("responsePayload");
99 case STATUSCODEVARIABLE:
100 result = element.getAttribute("statusCode");
103 result = element.getAttribute("accept");
106 result = element.getAttribute("contentType");