⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 httpmethodconverter.java

📁 bpel执行引擎用来执行bpel业务流程
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
                // if the part has an element name, we must take the first element                if (part.getElementName() != null) {                    partValue = DOMUtils.getFirstChildElement(partValue);                }                String xmlString = DOMUtils.domToString(partValue);                requestEntity = new ByteArrayRequestEntity(xmlString.getBytes(), contentType);            } else {                // should not happen because of HttpBindingValidator, but never say never                throw new IllegalArgumentException("Unsupported content-type!");            }            // cast safely, PUT and POST are subclasses of EntityEnclosingMethod            final EntityEnclosingMethod enclosingMethod = (EntityEnclosingMethod) method;            enclosingMethod.setRequestEntity(requestEntity);            enclosingMethod.setContentChunked(params.getBooleanParameter(Properties.PROP_HTTP_REQUEST_CHUNK, false));        } else {            // should not happen because of HttpBindingValidator, but never say never            throw new IllegalArgumentException("Unsupported HTTP method: " + verb);        }        // link params together        method.getParams().setDefaults(params);        method.setPath(completeUri); // assumes that the path is properly encoded (URL safe).        method.setQueryString(queryPath);        // headers        setHttpRequestHeaders(method, partValues, opBinding.getOperation().getInput().getMessage(), opBinding.getBindingInput());        return method;    }    /**     * Go through the list of {@linkplain Namespaces.ODE_HTTP_EXTENSION_NS}{@code :header} elements included in the input binding. For each of them, set the HTTP Request Header with the static value defined by the attribute {@linkplain Namespaces.ODE_HTTP_EXTENSION_NS}{@code :value},     *  or the part value mentionned in the attribute {@linkplain Namespaces.ODE_HTTP_EXTENSION_NS}{@code :part}.     */    public void setHttpRequestHeaders(HttpMethod method, Map<String, Element> partValues, Message inputMessage, BindingInput bindingInput) {        Collection<UnknownExtensibilityElement> headerBindings = WsdlUtils.getHttpHeaders(bindingInput.getExtensibilityElements());        for (Iterator<UnknownExtensibilityElement> iterator = headerBindings.iterator(); iterator.hasNext();) {            Element binding = iterator.next().getElement();            String headerName = binding.getAttribute("name");            String partName = binding.getAttribute("part");            String value = binding.getAttribute("value");            String headerValue;            if (StringUtils.isNotEmpty(partName)) {                // get the part to be put in the body                Part part = inputMessage.getPart(partName);                Element partValue = partValues.get(part.getName());                // if the part has an element name, we must take the first element                if (part.getElementName() != null) partValue = DOMUtils.getFirstChildElement(partValue);                headerValue = DOMUtils.domToString(partValue);            } else if (StringUtils.isNotEmpty(value)) {                headerValue = value;            } else {                String errMsg = "Invalid binding: missing attribute! Expecting " + new QName(Namespaces.ODE_HTTP_EXTENSION_NS, "part") + " or " + new QName(Namespaces.ODE_HTTP_EXTENSION_NS, "value");                if (log.isErrorEnabled()) {                    log.error(errMsg);                }                throw new RuntimeException(errMsg);            }            method.setRequestHeader(headerName, HttpClientHelper.replaceCRLFwithLWS(headerValue));        }    }    protected Map<String, Element> extractPartElements(Message msgDef, Element message) {        Map<String, Element> partValues = new HashMap<String, Element>();        for (Iterator iterator = msgDef.getParts().values().iterator(); iterator.hasNext();) {            Part part = (Part) iterator.next();            Element partEl = DOMUtils.findChildByName(message, new QName(null, part.getName()));            if (partEl == null)                throw new IllegalArgumentException(msgs.msgOdeMessageMissingRequiredPart(part.getName()));            partValues.put(part.getName(), partEl);        }        return partValues;    }    /**     * Create the element to be associated with this part into the {@link org.apache.ode.bpel.iapi.Message}.     * <br/>An element named with the part name will be returned. the content of this element depends on the part.     * <p/>If the part has a non-null element name, a new element will be created and named accordingly then the text value is inserted in this new element.     * <br/>else the given text content is simply set on the part element.     *     * @param part     * @param textContent     * @return an element named with the part name will be returned     */    public Element createPartElement(Part part, String textContent) {        Document doc = DOMUtils.newDocument();        Element partElement = doc.createElementNS(null, part.getName());        if (part.getElementName() != null) {            Element element = doc.createElementNS(part.getElementName().getNamespaceURI(), part.getElementName().getLocalPart());            element.setTextContent(textContent);            partElement.appendChild(element);        } else {            partElement.setTextContent(textContent);        }        return partElement;    }    /**     * Create the element to be associated with this part into the {@link org.apache.ode.bpel.iapi.Message}.     * <p/>If the part has a non-null element name, the bodyElement is simply appended.     * Else if the bodyElement has a text content, the value is set to the message.     * Else append all nodes of bodyElement to the returned element. Attributes are ignored.     * <p/>     * The name of the returned element is the part name.     *     * @param part     * @param receivedElement     * @return the element to insert "as is" to ODE message     */    public Element createPartElement(Part part, Element receivedElement) {        Document doc = DOMUtils.newDocument();        Element partElement = doc.createElementNS(null, part.getName());        if (part.getElementName() != null) {            partElement.appendChild(doc.importNode(receivedElement, true));        } else {            if (DOMUtils.isEmptyElement(receivedElement)) {                // Append an empty text node.                // Warning! setting an empty string with setTextContent has not effect. See javadoc.                partElement.appendChild(doc.createTextNode(""));            } else {                // No need to make the distinction between simple and complex types, importNode will handle it                // !!! Attributes are ignored                for (int m = 0; m < receivedElement.getChildNodes().getLength(); m++) {                    Node child = receivedElement.getChildNodes().item(m);                    partElement.appendChild(doc.importNode(child, true));                }            }        }        return partElement;    }    /**     * Process the HTTP Response Headers.     * <p/>     * First go through the list of {@linkplain Namespaces.ODE_HTTP_EXTENSION_NS}{@code :header} elements included in the output binding. For each of them, set the header value as the value of the message part.     * <br/>Then add all HTTP headers as header part in the message. The name of the header would be the part name.     *     * @param odeMessage     * @param method     * @param messageDef     * @param bindingOutput     */    public void extractHttpResponseHeaders(org.apache.ode.bpel.iapi.Message odeMessage, HttpMethod method, Message messageDef, BindingOutput bindingOutput) {        Collection<UnknownExtensibilityElement> headerBindings = WsdlUtils.getHttpHeaders(bindingOutput.getExtensibilityElements());        // iterate through the list of header bindings        // and set the message parts accordingly        for (Iterator<UnknownExtensibilityElement> iterator = headerBindings.iterator(); iterator.hasNext();) {            Element binding = iterator.next().getElement();            String partName = binding.getAttribute("part");            String headerName = binding.getAttribute("name");            Part part = messageDef.getPart(partName);            if (StringUtils.isNotEmpty(partName)) {                odeMessage.setPart(partName, createPartElement(part, method.getRequestHeader(headerName).getValue()));            } else {                String errMsg = "Invalid binding: missing required attribute! Part name: " + new QName(Namespaces.ODE_HTTP_EXTENSION_NS, "part");                if (log.isErrorEnabled()) log.error(errMsg);                throw new RuntimeException(errMsg);            }        }        // also add all HTTP headers into the messade as header parts        Header[] reqHeaders = method.getResponseHeaders();        for (int i = 0; i < reqHeaders.length; i++) {            Header h = reqHeaders[i];            odeMessage.setHeaderPart(h.getName(), h.getValue());        }    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -