List of usage examples for javax.xml.soap SOAPEnvelope createName
public abstract Name createName(String localName) throws SOAPException;
From source file:eu.planets_project.tb.gui.backing.admin.wsclient.util.WSClient.java
/** * Builds a hierarchy of SOAPElements given a complex value JDOM Element * * @param envelope The SOAP Envelope * @param rootElem The root SOAP Element to build content for * @param jdomElem A JDOM Element that represents a complex value * @param isRPC Pass true when building for RPC encoded messages * * @throws SOAPException//from w ww .j a v a 2 s. co m */ protected static void buildSoapElement(SOAPEnvelope envelope, SOAPElement soapElem, Element jdomElem, boolean isRPC) throws SOAPException { // If the source node has text use its value String elemText = jdomElem.getText(); if (elemText != null) { if (isRPC == true) { // Set the type attribute for this element String type = jdomElem.getAttributeValue("type"); if (type != null) { soapElem.addAttribute(envelope.createName(XSI_NAMESPACE_PREFIX + ":type"), XSD_NAMESPACE_PREFIX + ":" + type); } } // Add the element text value soapElem.addTextNode(elemText); } // If the source node has attributes add the attribute values List attrs = jdomElem.getAttributes(); if (attrs != null) { Iterator attrIter = attrs.iterator(); while (attrIter.hasNext()) { // Get the attribute to add Attribute attr = (Attribute) attrIter.next(); // Create a name for the attribute Name attrName = envelope.createName(attr.getName(), attr.getNamespacePrefix(), attr.getNamespaceURI()); // Add the attribute and its value to the element soapElem.addAttribute(attrName, attr.getValue()); } } // Build children List children = jdomElem.getChildren(); if (children != null) { Iterator childIter = children.iterator(); while (childIter.hasNext()) { Element jdomChildElem = (Element) childIter.next(); // Create a new SOAPElement as a child of the current one //SOAPElement soapChildElem = soapElem.addChildElement(jdomChildElem.getName()); SOAPElement soapChildElem = soapElem.addChildElement(jdomChildElem.getName(), jdomChildElem.getNamespacePrefix(), jdomChildElem.getNamespaceURI()); // Build it buildSoapElement(envelope, soapChildElem, jdomChildElem, isRPC); } } }
From source file:com.googlecode.ddom.frontend.saaj.SOAPElementTest.java
/** * Test that {@link SOAPElement#getAttributeValue(Name)} returns <code>null</code> if the * requested attribute doesn't exist.// w w w . ja v a 2s . co m * * @throws Exception */ @Validated @Test public void testGetAttributeValueByNameNonExisting() throws Exception { SOAPEnvelope envelope = saajUtil.createSOAP11Envelope(); SOAPBody body = envelope.addBody(); SOAPElement element = body.addChildElement("test", "p", "urn:test"); assertNull(element.getAttributeValue(envelope.createName("attr"))); }
From source file:com.googlecode.ddom.frontend.saaj.SOAPElementTest.java
@Validated @Test// ww w. j a v a2 s. c om public void testAddAttributeFromNameWithoutNamespace() throws Exception { SOAPEnvelope envelope = saajUtil.createSOAP11Envelope(); SOAPBody body = envelope.addBody(); SOAPElement element = body.addChildElement(new QName("urn:test", "test")); SOAPElement retValue = element.addAttribute(envelope.createName("attr"), "value"); assertSame(element, retValue); Attr attr = element.getAttributeNodeNS(null, "attr"); assertNull(attr.getNamespaceURI()); String localName = attr.getLocalName(); if (localName != null) { assertEquals("attr", attr.getLocalName()); } assertNull(attr.getPrefix()); assertEquals("value", attr.getValue()); }
From source file:com.googlecode.ddom.frontend.saaj.SOAPElementTest.java
/** * Test the behavior of {@link SOAPElement#getAttributeValue(Name)} for an attribute without * namespace./*from ww w . j a v a 2s .co m*/ * * @throws Exception */ @Validated @Test public void testGetAttributeValueByNameWithoutNamespace() throws Exception { SOAPEnvelope envelope = saajUtil.createSOAP11Envelope(); SOAPBody body = envelope.addBody(); SOAPElement element = body.addChildElement("test", "p", "urn:test"); element.setAttributeNS(null, "attr", "value"); assertEquals("value", element.getAttributeValue(envelope.createName("attr"))); }
From source file:com.twinsoft.convertigo.engine.translators.WebServiceTranslator.java
public void buildInputDocument(Context context, Object inputData) throws Exception { Engine.logBeans.debug("[WebServiceTranslator] Making input document"); HttpServletRequest request = (HttpServletRequest) inputData; SOAPMessage requestMessage = (SOAPMessage) request .getAttribute(WebServiceServlet.REQUEST_MESSAGE_ATTRIBUTE); SOAPPart sp = requestMessage.getSOAPPart(); SOAPEnvelope se = sp.getEnvelope(); SOAPBody sb = se.getBody();// ww w . ja v a 2 s . c om Iterator<?> iterator = sb.getChildElements(); SOAPElement method, parameter; String methodName; InputDocumentBuilder inputDocumentBuilder = new InputDocumentBuilder(context); while (iterator.hasNext()) { List<RequestableVariable> variableList = null; // jmc 12/06/26 Object element = iterator.next(); if (element instanceof SOAPElement) { method = (SOAPElement) element; methodName = method.getElementName().getLocalName(); Engine.logBeans.debug("[WebServiceTranslator] Requested web service name: " + methodName); int i = methodName.indexOf("__"); // for statefull transaction, don't replace the project if (context.project == null || !context.project.getName().equals(context.projectName)) { context.project = Engine.theApp.databaseObjectsManager.getProjectByName(context.projectName); } String connectorName = null; if (i == -1) { context.connectorName = null; context.sequenceName = methodName; } else { connectorName = methodName.substring(0, i); context.transactionName = methodName.substring(i + 2); } if ((connectorName != null) && (!connectorName.equals(context.connectorName))) { Engine.logBeans.debug("Connector name differs from previous one; requiring new session"); context.isNewSession = true; context.connectorName = connectorName; Engine.logBeans.debug("[WebServiceTranslator] The connector is overridden to \"" + context.connectorName + "\"."); } Engine.logBeans.debug("[WebServiceTranslator] Connector: " + (context.connectorName == null ? "(default)" : context.connectorName)); Engine.logBeans.debug("[WebServiceTranslator] Transaction: " + context.transactionName); //Connector connector = (context.connectorName == null ? context.project.getDefaultConnector() : context.project.getConnectorByName(context.connectorName)); //Transaction transaction = (context.transactionName == null ? connector.getDefaultTransaction() : connector.getTransactionByName(context.transactionName)); RequestableObject requestable = null; if (context.sequenceName != null) { requestable = context.project.getSequenceByName(context.sequenceName); variableList = ((Sequence) requestable).getVariablesList(); } else if (context.connectorName != null) { if (context.transactionName != null) { requestable = context.project.getConnectorByName(context.connectorName) .getTransactionByName(context.transactionName); if (requestable instanceof TransactionWithVariables) { variableList = ((TransactionWithVariables) requestable).getVariablesList(); } } } Iterator<?> iterator2 = method.getChildElements(); String parameterName, parameterValue; while (iterator2.hasNext()) { element = iterator2.next(); if (element instanceof SOAPElement) { parameter = (SOAPElement) element; parameterName = parameter.getElementName().getLocalName(); parameterValue = parameter.getValue(); if (parameterValue == null) { parameterValue = ""; } if (variableList != null) { // jmc 12/06/26 hide hidden variables in sequences String str = (String) Visibility.Logs.replaceVariables(variableList, "" + parameterName + "=\"" + parameterValue + "\""); Engine.logBeans.debug(" Parameter: " + str); } else Engine.logBeans.debug(" Parameter: " + parameterName + "=\"" + parameterValue + "\""); // Handle convertigo parameters if (parameterName.startsWith("__")) { webServiceServletRequester.handleParameter(parameterName, parameterValue); } // Common parameter handling if (inputDocumentBuilder.handleSpecialParameter(parameterName, parameterValue)) { // handled } // Compatibility for Convertigo 2.x else if (parameterName.equals("context")) { // Just ignore it } else { SOAPElement soapArrayElement = null; Iterator<?> iterator3; String href = parameter.getAttributeValue(se.createName("href")); String arrayType = parameter.getAttributeValue(se.createName("soapenc:arrayType")); if (arrayType == null) { iterator3 = parameter.getAllAttributes(); while (iterator3.hasNext()) { element = iterator3.next(); if (element instanceof Name) { String s = ((Name) element).getQualifiedName(); if (s.equals("soapenc:arrayType")) { arrayType = s; break; } } } } // Array (Microsoft .net) if (href != null) { Engine.logBeans.debug("Deserializing Microsoft .net array"); iterator3 = sb.getChildElements(); while (iterator3.hasNext()) { element = iterator3.next(); if (element instanceof SOAPElement) { soapArrayElement = (SOAPElement) element; String elementId = soapArrayElement.getAttributeValue(se.createName("id")); if (elementId != null) { if (href.equals("#" + elementId)) { iterator3 = soapArrayElement.getChildElements(); while (iterator3.hasNext()) { element = iterator3.next(); if (element instanceof SOAPElement) { break; } } break; } } } } // Find the element with href id iterator3 = sb.getChildElements(); while (iterator3.hasNext()) { element = iterator3.next(); if (element instanceof SOAPElement) { soapArrayElement = (SOAPElement) element; String elementId = soapArrayElement.getAttributeValue(se.createName("id")); if (elementId != null) { if (href.equals("#" + elementId)) { break; } } } } } // Array (Java/Axis) else if (arrayType != null) { Engine.logBeans.debug("Deserializing Java/Axis array"); soapArrayElement = parameter; } // If the node has children nodes, we assume it is an array. else if (parameter.getChildElements().hasNext()) { if (isSoapArray((IVariableContainer) requestable, parameterName)) { Engine.logBeans.debug("Deserializing array"); soapArrayElement = parameter; } } // Deserializing array if (soapArrayElement != null) { iterator3 = soapArrayElement.getChildElements(); while (iterator3.hasNext()) { element = iterator3.next(); if (element instanceof SOAPElement) { soapArrayElement = (SOAPElement) element; parameterValue = soapArrayElement.getValue(); if (parameterValue == null) parameterValue = ""; handleSimpleVariable(context.inputDocument, soapArrayElement, parameterName, parameterValue, inputDocumentBuilder.transactionVariablesElement); } } } // Deserializing simple variable else { handleSimpleVariable(context.inputDocument, parameter, parameterName, parameterValue, inputDocumentBuilder.transactionVariablesElement); } } } } if (Engine.logBeans.isDebugEnabled()) { String soapMessage = SOAPUtils.toString(requestMessage, request.getCharacterEncoding()); if (requestable instanceof TransactionWithVariables) Engine.logBeans.debug("[WebServiceTranslator] SOAP message received:\n" + Visibility.Logs.replaceVariables( ((TransactionWithVariables) (requestable)).getVariablesList(), request)); else if (requestable instanceof Sequence) Engine.logBeans.debug("[WebServiceTranslator] SOAP message received:\n" + Visibility.Logs .replaceVariables(((Sequence) (requestable)).getVariablesList(), request)); else Engine.logBeans.debug("[WebServiceTranslator] SOAP message received:\n" + soapMessage); } break; } } Engine.logBeans.debug("[WebServiceTranslator] SOAP message analyzed"); Engine.logBeans.debug("[WebServiceTranslator] Input document created"); }
From source file:org.jbpm.bpel.integration.soap.SoapUtil.java
public static void copyChildElement(SOAPElement parent, Element source) throws SOAPException { String localName = source.getLocalName(); String prefix = source.getPrefix(); String namespaceURI = source.getNamespaceURI(); Name targetName;//from w ww. ja v a 2 s. c om SOAPEnvelope envelope = findEnvelope(parent); if (prefix == null || prefix.length() == 0) { // source has no prefix, distinguish between no namespace and default namespace if (namespaceURI == null || namespaceURI.length() == 0) { // no namespace targetName = envelope.createName(localName); if (traceEnabled) log.trace("appended element: " + localName); } else { // default namespace, look for existing prefix at target prefix = getPrefix(namespaceURI, parent); // no prefix for that namespace? if (prefix == null) { prefix = XmlUtil.generatePrefix(DEFAULT_NAMESPACE_PREFIX, source); } // BPEL-195 source maps prefix to another URI? else if (!namespaceURI.equals(source.getAttributeNS(BpelConstants.NS_XMLNS, prefix))) { prefix = XmlUtil.generatePrefix(prefix, source); } targetName = envelope.createName(localName, prefix, namespaceURI); if (traceEnabled) log.trace("added child element: {" + namespaceURI + '}' + prefix + ':' + localName); } } else { // source has prefix targetName = envelope.createName(localName, prefix, namespaceURI); if (traceEnabled) log.trace("added child element: {" + namespaceURI + '}' + prefix + ':' + localName); } SOAPElement target; if (parent instanceof SOAPBody) { /* * jboss-ws4ee throws ClassCastException upon calling the remote endpoint if child elements * other than SOAPBodyElements are added to SOAPBody */ SOAPBody body = (SOAPBody) parent; target = body.addBodyElement(targetName); } else target = parent.addChildElement(targetName); // namespaces copyNamespaces(target, source); ensureOwnNamespaceDeclared(target); // attributes copyAttributes(target, source); // child nodes copyChildNodes(target, source); }
From source file:org.jbpm.bpel.integration.soap.SoapUtilTest.java
public void testCopyChildNodes_soapDom() throws Exception { String xml = "<lunch xmlns:produce='urn:example:produce'" + " xmlns='urn:example:meal'>" + " <time>1200</time>" + " <produce:lettuce>0.1lb</produce:lettuce>" + " <fish:fillet xmlns:fish='urn:example:fish'>0.25lb</fish:fillet>" + " <padding xmlns=''/>" + "</lunch>"; Element source = XmlUtil.parseText(xml); SOAPMessage soapMessage = MessageFactory.newInstance().createMessage(); SOAPEnvelope envelope = soapMessage.getSOAPPart().getEnvelope(); SOAPElement target = envelope.getBody().addBodyElement(envelope.createName("detail")); // perform the copy SoapUtil.copyChildNodes(target, source); // qualified, prefixless element SOAPElement time = SoapUtil.getElement(target, "urn:example:meal", "time"); assertEquals(SoapUtil.DEFAULT_NAMESPACE_PREFIX, time.getPrefix()); // qualified, prefixed element SOAPElement lettuce = SoapUtil.getElement(target, "urn:example:produce", "lettuce"); assertEquals("produce", lettuce.getPrefix()); // parent qualified, prefixed element SOAPElement fillet = SoapUtil.getElement(target, "urn:example:fish", "fillet"); assertEquals("fish", fillet.getPrefix()); // local element SOAPElement padding = SoapUtil.getElement(target, "padding"); assertNull(padding.getPrefix());//from ww w . j a v a2s .co m assertNull(padding.getNamespaceURI()); }
From source file:org.jbpm.bpel.integration.soap.SoapUtilTest.java
public void testCopy_soapDom_qualifiedNoPrefix() throws Exception { String xml = "<ReverseAndConcatNames xmlns='http://my.namespace'>" + " <firstName>Martin</firstName>" + " <secondName>Steinle</secondName>" + "</ReverseAndConcatNames>"; Element source = XmlUtil.parseText(xml); SOAPMessage soapMessage = MessageFactory.newInstance().createMessage(); SOAPEnvelope envelope = soapMessage.getSOAPPart().getEnvelope(); SOAPElement target = envelope.getBody().addBodyElement(envelope.createName("detail")); // perform the copy SoapUtil.copy(target, source);/*from ww w . jav a 2s . c om*/ assertEquals("http://my.namespace", target.getNamespaceURI(SoapUtil.DEFAULT_NAMESPACE_PREFIX)); // qualified elements SOAPElement firstName = SoapUtil.getElement(target, "http://my.namespace", "firstName"); assertEquals("Martin", firstName.getValue()); SOAPElement secondName = SoapUtil.getElement(target, "http://my.namespace", "secondName"); assertEquals("Steinle", secondName.getValue()); }
From source file:test.functional.TestJAXMSamples.java
public void testJWSFault() throws Exception { try {/*from w w w. ja v a2 s.co m*/ SOAPConnectionFactory scFactory = SOAPConnectionFactory.newInstance(); SOAPConnection con = scFactory.createConnection(); MessageFactory factory = MessageFactory.newInstance(); SOAPMessage message = factory.createMessage(); SOAPEnvelope envelope = message.getSOAPPart().getEnvelope(); SOAPBody body = envelope.getBody(); Name bodyName = envelope.createName("echo"); SOAPBodyElement bodyElement = body.addBodyElement(bodyName); Name name = envelope.createName("arg0"); SOAPElement symbol = bodyElement.addChildElement(name); symbol.addTextNode("Hello"); URLEndpoint endpoint = new URLEndpoint("http://localhost:8080/jws/FaultTest.jws"); SOAPMessage response = con.call(message, endpoint); SOAPBody respBody = response.getSOAPPart().getEnvelope().getBody(); assertTrue(respBody.hasFault()); } catch (javax.xml.soap.SOAPException e) { Throwable t = e.getCause(); if (t != null) { t.printStackTrace(); if (t instanceof AxisFault) { AxisFault af = (AxisFault) t; if ((af.detail instanceof SocketException) || (af.getFaultCode().getLocalPart().equals("HTTP"))) { System.out.println("Connect failure caused testJWSFault to be skipped."); return; } } throw new Exception("Fault returned from test: " + t); } else { e.printStackTrace(); throw new Exception("Exception returned from test: " + e); } } catch (Throwable t) { t.printStackTrace(); throw new Exception("Fault returned from test: " + t); } }