List of usage examples for org.w3c.dom Element setTextContent
public void setTextContent(String textContent) throws DOMException;
From source file:org.apache.ode.axis2.httpbinding.HttpHelper.java
/** * Convert a <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec6.html#sec6.1">HTTP status line</a> into an xml element like this: * <p/>//from w w w.j av a2 s .co m * < Status-line> * < HTTP-Version>HTTP/1.1< /HTTP-Version> * < Status-Code>200< /Status-Code> * < Reason-Phrase>Success - The action was successfully received, understood, and accepted< /Reason-Phrase> * < /Status-line></br> * * @param statusLine - the {@link org.apache.commons.httpclient.StatusLine} instance to be converted * @param doc - the document to use to create new nodes * @return an Element */ public static Element statusLineToElement(Document doc, StatusLine statusLine) { Element statusLineEl = doc.createElementNS(null, "Status-Line"); Element versionEl = doc.createElementNS(null, "HTTP-Version"); Element codeEl = doc.createElementNS(null, "Status-Code"); Element reasonEl = doc.createElementNS(null, "Reason-Phrase"); Element originalEl = doc.createElementNS(null, "original"); // wiring doc.appendChild(statusLineEl); statusLineEl.appendChild(versionEl); statusLineEl.appendChild(codeEl); statusLineEl.appendChild(reasonEl); statusLineEl.appendChild(originalEl); // values versionEl.setTextContent(statusLine.getHttpVersion()); codeEl.setTextContent(String.valueOf(statusLine.getStatusCode())); reasonEl.setTextContent(statusLine.getReasonPhrase()); // the line as received, not parsed originalEl.setTextContent(statusLine.toString()); return statusLineEl; }
From source file:org.apache.ode.axis2.httpbinding.HttpHelper.java
/** * Build a "details" element that looks like this: * * @param method/* w w w . ja v a 2 s . c o m*/ * @return * @throws IOException */ public static Element prepareDetailsElement(HttpMethod method) { Header h = method.getResponseHeader("Content-Type"); String receivedType = h != null ? h.getValue() : null; boolean bodyIsXml = receivedType != null && HttpUtils.isXml(receivedType); Document doc = DOMUtils.newDocument(); Element detailsEl = doc.createElementNS(null, "details"); Element statusLineEl = statusLineToElement(doc, method.getStatusLine()); detailsEl.appendChild(statusLineEl); // set the body if any try { final String body = method.getResponseBodyAsString(); if (StringUtils.isNotEmpty(body)) { Element bodyEl = doc.createElementNS(null, "responseBody"); detailsEl.appendChild(bodyEl); // first, try to parse the body as xml // if it fails, put it as string in the body element boolean exceptionDuringParsing = false; if (bodyIsXml) { try { Element parsedBodyEl = DOMUtils.stringToDOM(body); bodyEl.appendChild(doc.importNode(parsedBodyEl, true)); } catch (Exception e) { String errmsg = "Unable to parse the response body as xml. Body will be inserted as string."; if (log.isDebugEnabled()) log.debug(errmsg, e); exceptionDuringParsing = true; } } if (!bodyIsXml || exceptionDuringParsing) { bodyEl.setTextContent(body); } } } catch (IOException e) { if (log.isWarnEnabled()) log.warn("Exception while loading response body", e); } return detailsEl; }
From source file:org.apache.ode.axis2.httpbinding.HttpMethodConverter.java
/** * 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/*from w ww . j a v a 2 s . com*/ * @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; }
From source file:org.apache.ode.axis2.httpbinding.HttpMethodConverterTest.java
public void testGetTag() throws Exception { String uri = ((HTTPAddress) deliciousPort.getExtensibilityElements().get(0)).getLocationURI(); String expectedUri = uri + "/tag/java"; Element msgEl;//from www .j a va2 s. c om { Document odeMsg = DOMUtils.newDocument(); msgEl = odeMsg.createElementNS(null, "message"); Element partEl = odeMsg.createElementNS(null, "TagPart"); partEl.setTextContent("java"); odeMsg.appendChild(msgEl); msgEl.appendChild(partEl); } MockMessageExchange odeMex = new MockMessageExchange(); odeMex.op = deliciousBinding.getBindingOperation("getTag", null, null).getOperation(); odeMex.req = new MockMessage(msgEl); odeMex.epr = new MockEPR(uri); HttpMethod httpMethod = deliciousBuilder.createHttpRequest(odeMex, new DefaultHttpParams()); assertTrue("GET".equalsIgnoreCase(httpMethod.getName())); assertTrue(expectedUri.equalsIgnoreCase(httpMethod.getURI().toString())); }
From source file:org.apache.ode.bpel.engine.BpelEngineImpl.java
public void sendMyRoleFault(BpelProcess process, JobDetails we, int causeCode) { MessageExchange mex = (MessageExchange) getMessageExchange(we.getMexId()); if (!(mex instanceof MyRoleMessageExchange)) { return;//w w w . java 2 s .c o m } QName faultQName = null; OConstants constants = process.getOProcess().constants; if (constants != null) { Document document = DOMUtils.newDocument(); Element faultElement = document.createElementNS(Namespaces.SOAP_ENV_NS, "Fault"); Element faultDetail = document.createElementNS(Namespaces.ODE_EXTENSION_NS, "fault"); faultElement.appendChild(faultDetail); switch (causeCode) { case InvalidProcessException.TOO_MANY_PROCESSES_CAUSE_CODE: faultQName = constants.qnTooManyProcesses; faultDetail.setTextContent("The total number of processes in use is over the limit."); break; case InvalidProcessException.TOO_HUGE_PROCESSES_CAUSE_CODE: faultQName = constants.qnTooHugeProcesses; faultDetail.setTextContent("The total size of processes in use is over the limit"); break; case InvalidProcessException.TOO_MANY_INSTANCES_CAUSE_CODE: faultQName = constants.qnTooManyInstances; faultDetail.setTextContent("No more instances of the process allowed at start at this time."); break; case InvalidProcessException.RETIRED_CAUSE_CODE: // we're invoking a target process, trying to see if we can retarget the message // to the current version (only applies when it's a new process creation) for (BpelProcess activeProcess : _activeProcesses.values()) { if (activeProcess.getConf().getState().equals(org.apache.ode.bpel.iapi.ProcessState.ACTIVE) && activeProcess.getConf().getType().equals(process.getConf().getType())) { we.setProcessId(activeProcess._pid); ((MyRoleMessageExchangeImpl) mex)._process = activeProcess; process.handleJobDetails(we); return; } } faultQName = constants.qnRetiredProcess; faultDetail.setTextContent("The process you're trying to instantiate has been retired."); break; case InvalidProcessException.DEFAULT_CAUSE_CODE: default: faultQName = constants.qnUnknownFault; break; } MexDaoUtil.setFaulted((MessageExchangeImpl) mex, faultQName, faultElement); } }
From source file:org.apache.ode.bpel.engine.CustomProcessProperties.java
public static Node stringToNode(String s) { Document d = DOMUtils.newDocument(); Element e = d.createElement("value"); e.setTextContent(s); d.appendChild(e);/*www . ja v a 2 s . c o m*/ return d.getDocumentElement(); }
From source file:org.apache.ode.bpel.engine.ODEProcess.java
/** * Entry point for message exchanges aimed at the my role. * * @param mexdao Message Exchange DAO./*w w w .jav a2 s. c o m*/ */ void invokeProcess(final MessageExchangeDAO mexdao) { InvocationStyle istyle = mexdao.getInvocationStyle(); ConstantsModel constants = null; _hydrationLatch.latch(1); try { // The following check is mostly for sanity purposes. MexImpls should prevent this from // happening. PartnerLinkMyRoleImpl target = getMyRoleForService(mexdao.getCallee()); constants = target._process.getProcessModel().getConstantsModel(); Status oldstatus = mexdao.getStatus(); if (target == null) { String errmsg = __msgs.msgMyRoleRoutingFailure(mexdao.getMessageExchangeId()); __log.error(errmsg); MexDaoUtil.setFailed(mexdao, MessageExchange.FailureType.UNKNOWN_ENDPOINT, errmsg); onMyRoleMexAck(mexdao, oldstatus); return; } Operation op = target._plinkDef.getMyRoleOperation(mexdao.getOperation()); if (op == null) { String errmsg = __msgs.msgMyRoleRoutingFailure(mexdao.getMessageExchangeId()); __log.error(errmsg); MexDaoUtil.setFailed(mexdao, MessageExchange.FailureType.UNKNOWN_OPERATION, errmsg); onMyRoleMexAck(mexdao, oldstatus); return; } mexdao.setPattern((op.getOutput() == null) ? MessageExchangePattern.REQUEST_ONLY : MessageExchangePattern.REQUEST_RESPONSE); if (!processInterceptors(mexdao, InterceptorInvoker.__onProcessInvoked)) { __log.debug( "Aborting processing of mex " + mexdao.getMessageExchangeId() + " due to interceptors."); onMyRoleMexAck(mexdao, oldstatus); return; } // "Acknowledge" any one-way invokes if (op.getOutput() == null) { if (__log.isDebugEnabled()) { __log.debug("Acknowledge one-way invokes...."); } mexdao.setStatus(Status.ACK); mexdao.setAckType(AckType.ONEWAY); onMyRoleMexAck(mexdao, oldstatus); } mexdao.setProcess(getProcessDAO()); markused(); CorrelationStatus cstatus = target.invokeMyRole(mexdao); if (cstatus == null) { ; // do nothing } else if (cstatus == CorrelationStatus.CREATE_INSTANCE) { doInstanceWork(mexdao.getInstance().getInstanceId(), new Callable<Void>() { public Void call() { executeCreateInstance(mexdao); return null; } }); } else if (cstatus == CorrelationStatus.MATCHED) { // This should not occur for in-memory processes, since they are technically not allowed to // have any <receive>/<pick> elements that are not start activities. if (isInMemory()) __log.warn("In-memory process " + _pid + " is participating in a non-createinstance exchange!"); // We don't like to do the work in the same TX that did the matching, since this creates fertile // conditions for deadlock in the correlation tables. However if invocation style is transacted, // we need to do the work right then and there. if (mexdao.getInstance().getState() == ProcessState.STATE_TERMINATED) { throw new InvalidInstanceException("Trying to invoke terminated process instance", InvalidInstanceException.TERMINATED_CAUSE_CODE); } if (op.getOutput() != null) { // If the invoked operation is request-response type it's not good to store the request in // database until suspended instance is resumed. It's good to throw and exception in this case. // Then the client will know that this process is suspended. if (mexdao.getInstance().getState() == ProcessState.STATE_SUSPENDED) { throw new InvalidInstanceException("Trying to invoke suspended instance", InvalidInstanceException.SUSPENDED_CAUSE_CODE); } } if (istyle == InvocationStyle.TRANSACTED) { doInstanceWork(mexdao.getInstance().getInstanceId(), new Callable<Void>() { public Void call() { executeContinueInstanceMyRoleRequestReceived(mexdao); return null; } }); } else if (istyle == InvocationStyle.P2P_TRANSACTED) /* transact p2p invoke in the same thread */ { executeContinueInstanceMyRoleRequestReceived(mexdao); } else /* non-transacted style */ { WorkEvent we = new WorkEvent(); we.setType(WorkEvent.Type.MYROLE_INVOKE); we.setIID(mexdao.getInstance().getInstanceId()); we.setMexId(mexdao.getMessageExchangeId()); // Could be different to this pid when routing to an older version we.setProcessId(mexdao.getInstance().getProcess().getProcessId()); scheduleWorkEvent(we, null); } } else if (cstatus == CorrelationStatus.QUEUED) { ; // do nothing } } catch (InvalidProcessException ipe) { QName faultQName = null; if (constants != null) { Document document = DOMUtils.newDocument(); Element faultElement = document.createElementNS(Namespaces.SOAP_ENV_NS, "Fault"); Element faultDetail = document.createElementNS(Namespaces.ODE_EXTENSION_NS, "fault"); faultElement.appendChild(faultDetail); switch (ipe.getCauseCode()) { case InvalidProcessException.DUPLICATE_CAUSE_CODE: faultQName = constants.getDuplicateInstance(); faultDetail.setTextContent("Found a duplicate instance with the same message key"); break; case InvalidProcessException.RETIRED_CAUSE_CODE: faultQName = constants.getRetiredProcess(); faultDetail.setTextContent("The process you're trying to instantiate has been retired"); break; case InvalidProcessException.DEFAULT_CAUSE_CODE: default: faultQName = constants.getUnknownFault(); break; } MexDaoUtil.setFaulted(mexdao, faultQName, faultElement); } } catch (InvalidInstanceException iie) { QName faultQname = null; if (constants != null) { Document document = DOMUtils.newDocument(); Element faultElement = document.createElementNS(Namespaces.SOAP_ENV_NS, "Fault"); Element faultDetail = document.createElementNS(Namespaces.ODE_EXTENSION_NS, "fault"); faultElement.appendChild(faultDetail); switch (iie.getCauseCode()) { case InvalidInstanceException.TERMINATED_CAUSE_CODE: faultQname = new QName("ode", "TerminatedInstance"); faultDetail.setTextContent(iie.getMessage()); break; case InvalidInstanceException.SUSPENDED_CAUSE_CODE: faultQname = new QName("ode", "SuspendedInstance"); faultDetail.setTextContent(iie.getMessage()); break; default: faultQname = constants.getUnknownFault(); break; } MexDaoUtil.setFaulted(mexdao, faultQname, faultElement); } } catch (BpelEngineException bee) { QName faultQname = null; Document document = DOMUtils.newDocument(); Element faultElement = document.createElementNS(Namespaces.SOAP_ENV_NS, "Fault"); Element faultDetail = document.createElementNS(Namespaces.ODE_EXTENSION_NS, "fault"); faultElement.appendChild(faultDetail); faultQname = new QName("ode", "BpelEngineException"); faultDetail.setTextContent(bee.getMessage()); MexDaoUtil.setFaulted(mexdao, faultQname, faultElement); } finally { _hydrationLatch.release(1); // If we did not get an ACK during this method, then mark this MEX as needing an ASYNC wake-up if (mexdao.getStatus() != Status.ACK) mexdao.setStatus(Status.ASYNC); assert mexdao.getStatus() == Status.ACK || mexdao.getStatus() == Status.ASYNC; } }
From source file:org.apache.ode.bpel.epr.WSAEndpoint.java
public void setSessionId(String sessionId) { NodeList idList = _eprElmt.getElementsByTagNameNS(Namespaces.ODE_SESSION_NS, "session"); if (idList.getLength() > 0) idList.item(0).setTextContent(sessionId); else {/*from w w w. j a v a2 s . c o m*/ Element sessElmt = _eprElmt.getOwnerDocument().createElementNS(Namespaces.ODE_SESSION_NS, "session"); sessElmt.setTextContent(sessionId); _eprElmt.appendChild(sessElmt); } // and the same for the intalio header idList = _eprElmt.getElementsByTagNameNS(Namespaces.INTALIO_SESSION_NS, "session"); if (idList.getLength() > 0) idList.item(0).setTextContent(sessionId); else { Element sessElmt = _eprElmt.getOwnerDocument().createElementNS(Namespaces.INTALIO_SESSION_NS, "session"); sessElmt.setTextContent(sessionId); _eprElmt.appendChild(sessElmt); } }
From source file:org.apache.ode.bpel.epr.WSAEndpoint.java
public void setUrl(String url) { NodeList addrList = _eprElmt.getElementsByTagNameNS(Namespaces.WS_ADDRESSING_NS, "Address"); if (addrList.getLength() > 0) addrList.item(0).setTextContent(url); else {/* w ww .j a v a 2 s .co m*/ Element addrElmt = _eprElmt.getOwnerDocument().createElementNS(Namespaces.WS_ADDRESSING_NS, "Address"); addrElmt.setTextContent(url); _eprElmt.appendChild(addrElmt); } }
From source file:org.apache.ode.bpel.epr.WSAEndpoint.java
public void fromMap(Map eprMap) { Document doc = DOMUtils.newDocument(); Element serviceRef = doc.createElementNS(SERVICE_REF_QNAME.getNamespaceURI(), SERVICE_REF_QNAME.getLocalPart()); doc.appendChild(serviceRef);/* w ww. j av a 2 s. c om*/ _eprElmt = doc.createElementNS(Namespaces.WS_ADDRESSING_NS, "EndpointReference"); serviceRef.appendChild(_eprElmt); Element addrElmt = doc.createElementNS(Namespaces.WS_ADDRESSING_NS, "Address"); addrElmt.setTextContent((String) eprMap.get(ADDRESS)); if (eprMap.get(SESSION) != null) { Element sessElmt = doc.createElementNS(Namespaces.ODE_SESSION_NS, "session"); sessElmt.setTextContent((String) eprMap.get(SESSION)); _eprElmt.appendChild(sessElmt); // and the same for the (deprecated) intalio namespace for backward compatibility sessElmt = doc.createElementNS(Namespaces.INTALIO_SESSION_NS, "session"); sessElmt.setTextContent((String) eprMap.get(SESSION)); _eprElmt.appendChild(sessElmt); } if (eprMap.get(SERVICE_QNAME) != null) { Element metadataElmt = doc.createElementNS(Namespaces.WS_ADDRESSING_NS, "Metadata"); _eprElmt.appendChild(metadataElmt); Element serviceElmt = doc.createElementNS(Namespaces.WS_ADDRESSING_WSDL_NS, "ServiceName"); metadataElmt.appendChild(serviceElmt); QName serviceQName = (QName) eprMap.get(SERVICE_QNAME); serviceElmt.setAttribute("xmlns:servicens", serviceQName.getNamespaceURI()); serviceElmt.setTextContent("servicens:" + serviceQName.getLocalPart()); serviceElmt.setAttribute("EndpointName", (String) eprMap.get(PORT_NAME)); } _eprElmt.appendChild(addrElmt); if (__log.isDebugEnabled()) __log.debug("Constructed a new WSAEndpoint: " + DOMUtils.domToString(_eprElmt)); }