List of usage examples for javax.xml.soap SOAPEnvelope getBody
public SOAPBody getBody() throws SOAPException;
From source file:com.maxl.java.aips2sqlite.AllDown.java
public void downRefdataPharmaXml(String file_refdata_pharma_xml) { boolean disp = false; ProgressBar pb = new ProgressBar(); try {//from w w w . j a va 2 s. com // Start timer long startTime = System.currentTimeMillis(); if (disp) System.out.print("- Downloading Refdatabase pharma file... "); else { pb.init("- Downloading Refdatabase pharma file... "); pb.start(); } // Create soaprequest SOAPMessage soapRequest = MessageFactory.newInstance().createMessage(); // Set SOAPAction header line MimeHeaders headers = soapRequest.getMimeHeaders(); headers.addHeader("SOAPAction", "http://refdatabase.refdata.ch/Pharma/Download"); // Set SOAP main request part SOAPPart soapPart = soapRequest.getSOAPPart(); SOAPEnvelope envelope = soapPart.getEnvelope(); SOAPBody soapBody = envelope.getBody(); // Construct SOAP request message SOAPElement soapBodyElement1 = soapBody.addChildElement("DownloadArticleInput"); soapBodyElement1.addNamespaceDeclaration("", "http://refdatabase.refdata.ch/"); SOAPElement soapBodyElement2 = soapBodyElement1.addChildElement("ATYPE"); soapBodyElement2.addNamespaceDeclaration("", "http://refdatabase.refdata.ch/Article_in"); soapBodyElement2.addTextNode("ALL"); soapRequest.saveChanges(); // If needed print out soapRequest in a pretty format // System.out.println(prettyFormatSoapXml(soapRequest)); // Create connection to SOAP server SOAPConnectionFactory soapConnectionFactory = SOAPConnectionFactory.newInstance(); SOAPConnection connection = soapConnectionFactory.createConnection(); // wsURL contains service end point String wsURL = "http://refdatabase.refdata.ch/Service/Article.asmx?WSDL"; SOAPMessage soapResponse = connection.call(soapRequest, wsURL); // Extract response Document doc = soapResponse.getSOAPBody().extractContentAsDocument(); String strBody = getStringFromDoc(doc); String xmlBody = prettyFormat(strBody); // Note: parsing the Document tree and using the removeAttribute function is hopeless! xmlBody = xmlBody.replaceAll("xmlns.*?\".*?\" ", ""); long len = writeToFile(xmlBody, file_refdata_pharma_xml); if (!disp) pb.stopp(); long stopTime = System.currentTimeMillis(); System.out.println("\r- Downloading Refdata pharma file... " + len / 1024 + " kB in " + (stopTime - startTime) / 1000.0f + " sec"); connection.close(); } catch (Exception e) { if (!disp) pb.stopp(); System.err.println(" Exception: in 'downRefdataPharmaXml'"); e.printStackTrace(); } }
From source file:com.maxl.java.aips2sqlite.AllDown.java
public void downRefdataPartnerXml(String file_refdata_partner_xml) { boolean disp = false; ProgressBar pb = new ProgressBar(); try {/*from w w w . j a v a 2 s .c o m*/ // Start timer long startTime = System.currentTimeMillis(); if (disp) System.out.print("- Downloading Refdata partner file... "); else { pb.init("- Downloading Refdata partner file... "); pb.start(); } // Create soaprequest SOAPMessage soapRequest = MessageFactory.newInstance().createMessage(); // Set SOAPAction header line MimeHeaders headers = soapRequest.getMimeHeaders(); headers.addHeader("SOAPAction", "http://refdatabase.refdata.ch/Download"); // Set SOAP main request part SOAPPart soapPart = soapRequest.getSOAPPart(); SOAPEnvelope envelope = soapPart.getEnvelope(); SOAPBody soapBody = envelope.getBody(); // Construct SOAP request message SOAPElement soapBodyElement1 = soapBody.addChildElement("DownloadPartnerInput"); soapBodyElement1.addNamespaceDeclaration("", "http://refdatabase.refdata.ch/"); SOAPElement soapBodyElement2 = soapBodyElement1.addChildElement("PTYPE"); soapBodyElement2.addNamespaceDeclaration("", "http://refdatabase.refdata.ch/Partner_in"); soapBodyElement2.addTextNode("ALL"); soapRequest.saveChanges(); // If needed print out soapRequest in a pretty format // System.out.println(prettyFormatSoapXml(soapRequest)); // Create connection to SOAP server SOAPConnectionFactory soapConnectionFactory = SOAPConnectionFactory.newInstance(); SOAPConnection connection = soapConnectionFactory.createConnection(); // wsURL contains service end point String wsURL = "http://refdatabase.refdata.ch/Service/Partner.asmx?WSDL"; SOAPMessage soapResponse = connection.call(soapRequest, wsURL); // Extract response Document doc = soapResponse.getSOAPBody().extractContentAsDocument(); String strBody = getStringFromDoc(doc); String xmlBody = prettyFormat(strBody); // Note: parsing the Document tree and using the removeAttribute function is hopeless! xmlBody = xmlBody.replaceAll("xmlns.*?\".*?\" ", ""); long len = writeToFile(xmlBody, file_refdata_partner_xml); if (!disp) pb.stopp(); long stopTime = System.currentTimeMillis(); System.out.println("\r- Downloading Refdata partner file... " + len / 1024 + " kB in " + (stopTime - startTime) / 1000.0f + " sec"); connection.close(); } catch (Exception e) { if (!disp) pb.stopp(); System.err.println(" Exception: in 'downRefdataPartnerXml'"); e.printStackTrace(); } }
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(); Iterator<?> iterator = sb.getChildElements(); SOAPElement method, parameter; String methodName;//from w ww . j a va2s . c o m 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:com.maxl.java.aips2sqlite.AllDown.java
public void downSwissindexXml(String language, String file_refdata_pharma_xml) { boolean disp = false; ProgressBar pb = new ProgressBar(); try {// w ww .j av a2 s . c o m // Start timer long startTime = System.currentTimeMillis(); if (disp) System.out.print("- Downloading Swissindex (" + language + ") file... "); else { pb.init("- Downloading Swissindex (" + language + ") file... "); pb.start(); } SOAPMessage soapRequest = MessageFactory.newInstance().createMessage(); // Setting SOAPAction header line MimeHeaders headers = soapRequest.getMimeHeaders(); headers.addHeader("SOAPAction", "http://swissindex.e-mediat.net/SwissindexPharma_out_V101/DownloadAll"); SOAPPart soapPart = soapRequest.getSOAPPart(); SOAPEnvelope envelope = soapPart.getEnvelope(); SOAPBody soapBody = envelope.getBody(); // Construct SOAP request message SOAPElement soapBodyElement1 = soapBody.addChildElement("pharmacode"); soapBodyElement1.addNamespaceDeclaration("", "http://swissindex.e-mediat.net/SwissindexPharma_out_V101"); soapBodyElement1.addTextNode("DownloadAll"); SOAPElement soapBodyElement2 = soapBody.addChildElement("lang"); soapBodyElement2.addNamespaceDeclaration("", "http://swissindex.e-mediat.net/SwissindexPharma_out_V101"); if (language.equals("DE")) soapBodyElement2.addTextNode("DE"); else if (language.equals("FR")) soapBodyElement2.addTextNode("FR"); else { System.err.println("down_swissindex_xml: wrong language!"); return; } soapRequest.saveChanges(); SOAPConnectionFactory soapConnectionFactory = SOAPConnectionFactory.newInstance(); SOAPConnection connection = soapConnectionFactory.createConnection(); String wsURL = "https://swissindex.refdata.ch/Swissindex/Pharma/ws_Pharma_V101.asmx?WSDL"; SOAPMessage soapResponse = connection.call(soapRequest, wsURL); Document doc = soapResponse.getSOAPBody().extractContentAsDocument(); String strBody = getStringFromDoc(doc); String xmlBody = prettyFormat(strBody); // Note: parsing the Document tree and using the removeAttribute function is hopeless! xmlBody = xmlBody.replaceAll("xmlns.*?\".*?\" ", ""); long len = writeToFile(xmlBody, file_refdata_pharma_xml); if (!disp) pb.stopp(); long stopTime = System.currentTimeMillis(); System.out.println("\r- Downloading Swissindex (" + language + ") file... " + len / 1024 + " kB in " + (stopTime - startTime) / 1000.0f + " sec"); connection.close(); } catch (Exception e) { if (!disp) pb.stopp(); System.err.println(" Exception: in 'downSwissindexXml'"); e.printStackTrace(); } }
From source file:com.twinsoft.convertigo.engine.translators.WebServiceTranslator.java
private void addElement(SOAPMessage responseMessage, SOAPEnvelope soapEnvelope, Context context, Element elementToAdd, SOAPElement soapElement) throws SOAPException { SOAPElement soapMethodResponseElement = (SOAPElement) soapEnvelope.getBody().getFirstChild(); String targetNamespace = soapMethodResponseElement.getNamespaceURI(); String prefix = soapMethodResponseElement.getPrefix(); String nodeType = elementToAdd.getAttribute("type"); SOAPElement childSoapElement = soapElement; boolean elementAdded = true; boolean bTable = false; if (nodeType.equals("table")) { bTable = true;/*from w w w.j a v a 2 s.c o m*/ /*childSoapElement = soapElement.addChildElement("ArrayOf" + context.transactionName + "_" + tableName + "_Row", ""); if (!context.httpServletRequest.getServletPath().endsWith(".wsl")) { childSoapElement.addAttribute(soapEnvelope.createName("xsi:type"), "soapenc:Array"); }*/ childSoapElement = soapElement.addChildElement(elementToAdd.getNodeName()); } else if (nodeType.equals("row")) { /*String elementType = context.transactionName + "_" + tableName + "_Row"; childSoapElement = soapElement.addChildElement(elementType, "");*/ childSoapElement = soapElement.addChildElement(elementToAdd.getNodeName()); } else if (nodeType.equals("attachment")) { childSoapElement = soapElement.addChildElement(elementToAdd.getNodeName()); if (context.requestedObject instanceof AbstractHttpTransaction) { AttachmentDetails attachment = AttachmentManager.getAttachment(elementToAdd); if (attachment != null) { byte[] raw = attachment.getData(); if (raw != null) childSoapElement.addTextNode(Base64.encodeBase64String(raw)); } /* DON'T WORK YET *\ AttachmentPart ap = responseMessage.createAttachmentPart(new ByteArrayInputStream(raw), elementToAdd.getAttribute("content-type")); ap.setContentId(key); ap.setContentLocation(elementToAdd.getAttribute("url")); responseMessage.addAttachmentPart(ap); \* DON'T WORK YET */ } } else { String elementNodeName = elementToAdd.getNodeName(); String elementNodeNsUri = elementToAdd.getNamespaceURI(); String elementNodePrefix = getPrefix(context.projectName, elementNodeNsUri); XmlSchemaElement xmlSchemaElement = getXmlSchemaElementByName(context.projectName, elementNodeName); boolean isGlobal = xmlSchemaElement != null; if (isGlobal) { elementNodeNsUri = xmlSchemaElement.getQName().getNamespaceURI(); elementNodePrefix = getPrefix(context.projectName, elementNodeNsUri); } // ignore original SOAP message response elements // if ((elementNodeName.toUpperCase().indexOf("SOAP-ENV:") != -1) || ((elementToAdd.getParentNode().getNodeName().toUpperCase().indexOf("SOAP-ENV:") != -1)) || // (elementNodeName.toUpperCase().indexOf("SOAPENV:") != -1) || ((elementToAdd.getParentNode().getNodeName().toUpperCase().indexOf("SOAPENV:") != -1)) || // (elementNodeName.toUpperCase().indexOf("NS0:") != -1) || ((elementToAdd.getParentNode().getNodeName().toUpperCase().indexOf("NS0:") != -1))) { // elementAdded = false; // } if ("http://schemas.xmlsoap.org/soap/envelope/".equals(elementToAdd.getNamespaceURI()) || "http://schemas.xmlsoap.org/soap/envelope/" .equals(elementToAdd.getParentNode().getNamespaceURI()) || elementToAdd.getParentNode().getNodeName().toUpperCase().indexOf("NS0:") != -1 || elementNodeName.toUpperCase().indexOf("NS0:") != -1) { elementAdded = false; } else { if (XsdForm.qualified == context.project.getSchemaElementForm() || isGlobal) { if (elementNodePrefix == null) { childSoapElement = soapElement .addChildElement(soapEnvelope.createName(elementNodeName, prefix, targetNamespace)); } else { childSoapElement = soapElement.addChildElement( soapEnvelope.createName(elementNodeName, elementNodePrefix, elementNodeNsUri)); } } else { childSoapElement = soapElement.addChildElement(elementNodeName); } } } if (elementAdded && elementToAdd.hasAttributes()) { addAttributes(responseMessage, soapEnvelope, context, elementToAdd.getAttributes(), childSoapElement); } if (elementToAdd.hasChildNodes()) { NodeList childNodes = elementToAdd.getChildNodes(); int len = childNodes.getLength(); if (bTable) { /*if (!context.httpServletRequest.getServletPath().endsWith(".wsl")) { childSoapElement.addAttribute(soapEnvelope.createName("soapenc:arrayType"), context.projectName+"_ns:" + context.transactionName + "_" + tableName + "_Row[" + (len - 1) + "]"); }*/ } org.w3c.dom.Node node; Element childElement; for (int i = 0; i < len; i++) { node = childNodes.item(i); switch (node.getNodeType()) { case org.w3c.dom.Node.ELEMENT_NODE: childElement = (Element) node; addElement(responseMessage, soapEnvelope, context, childElement, childSoapElement); break; case org.w3c.dom.Node.CDATA_SECTION_NODE: case org.w3c.dom.Node.TEXT_NODE: String text = node.getNodeValue(); text = (text == null) ? "" : text; childSoapElement.addTextNode(text); break; default: break; } } /*org.w3c.dom.Node node; Element childElement; for (int i = 0 ; i < len ; i++) { node = childNodes.item(i); if (node instanceof Element) { childElement = (Element) node; addElement(responseMessage, soapEnvelope, context, childElement, childSoapElement); } else if (node instanceof CDATASection) { Node textNode = XMLUtils.findChildNode(elementToAdd, org.w3c.dom.Node.CDATA_SECTION_NODE); String text = textNode.getNodeValue(); if (text == null) { text = ""; } childSoapElement.addTextNode(text); } else { Node textNode = XMLUtils.findChildNode(elementToAdd, org.w3c.dom.Node.TEXT_NODE); if (textNode != null) { String text = textNode.getNodeValue(); if (text == null) { text = ""; } childSoapElement.addTextNode(text); } } }*/ } }
From source file:it.cnr.icar.eric.common.SOAPMessenger.java
/** Send a SOAP request to the registry server. Main entry point for * this class. If credentials have been set on the registry connection, * they will be used to sign the request. * * @param requestString/* www. jav a 2 s.c o m*/ * String that will be placed in the body of the * SOAP message to be sent to the server * * @param attachments * HashMap consisting of entries each of which * corresponds to an attachment where the entry key is the ContentId * and the entry value is a javax.activation.DataHandler of the * attachment. A parameter value of null means no attachments. * * @return * RegistryResponseHolder that represents the response from the * server */ @SuppressWarnings("unchecked") public RegistryResponseHolder sendSoapRequest(String requestString, Map<?, ?> attachments) throws JAXRException { boolean logRequests = Boolean.valueOf( CommonProperties.getInstance().getProperty("eric.common.soapMessenger.logRequests", "false")) .booleanValue(); if (logRequests) { PrintStream requestLogPS = null; try { requestLogPS = new PrintStream( new FileOutputStream(java.io.File.createTempFile("SOAPMessenger_requestLog", ".xml"))); requestLogPS.println(requestString); } catch (IOException e) { e.printStackTrace(); } finally { if (requestLogPS != null) { requestLogPS.close(); } } } // ================================================================= // // Remove the XML Declaration, if any // if (requestString.startsWith("<?xml")) { // requestString = requestString.substring(requestString.indexOf("?>")+2).trim(); // } // // StringBuffer soapText = new StringBuffer( // "<soap-env:Envelope xmlns:soap-env=\"http://schemas.xmlsoap.org/soap/envelope/\">"); // // soapText.append("<soap-env:Header>\n"); // // tell server about our superior SOAP Fault capabilities // soapText.append("<"); // soapText.append(BindingUtility.SOAP_CAPABILITY_HEADER_LocalName); // soapText.append(" xmlns='"); // soapText.append(BindingUtility.SOAP_CAPABILITY_HEADER_Namespace); // soapText.append("'>"); // soapText.append(BindingUtility.SOAP_CAPABILITY_ModernFaultCodes); // soapText.append("</"); // soapText.append(BindingUtility.SOAP_CAPABILITY_HEADER_LocalName); // soapText.append(">\n"); // soapText.append("</soap-env:Header>\n"); // soapText.append("<soap-env:Body>\n"); // soapText.append(requestString); // soapText.append("</soap-env:Body>"); // soapText.append("</soap-env:Envelope>"); MessageFactory messageFactory; SOAPMessage message = null; SOAPPart sp = null; SOAPEnvelope se = null; SOAPBody sb = null; SOAPHeader sh = null; if (log.isTraceEnabled()) { log.trace("requestString=\"" + requestString + "\""); } try { messageFactory = MessageFactory.newInstance(); message = messageFactory.createMessage(); sp = message.getSOAPPart(); se = sp.getEnvelope(); sb = se.getBody(); sh = se.getHeader(); /* * <soap-env:Envelope xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/"> * <soap-env:Header> * <capabilities xmlns="urn:freebxml:registry:soap">urn:freebxml:registry:soap:modernFaultCodes</capabilities> * * change with explicit namespace * <ns1:capabilities xmlns:ns1="urn:freebxml:registry:soap">urn:freebxml:registry:soap:modernFaultCodes</ns1:capabilities> */ SOAPHeaderElement capabilityElement = sh .addHeaderElement(se.createName(BindingUtility.SOAP_CAPABILITY_HEADER_LocalName, "ns1", BindingUtility.SOAP_CAPABILITY_HEADER_Namespace)); // capabilityElement.addAttribute( // se.createName("xmlns"), // BindingUtility.SOAP_CAPABILITY_HEADER_Namespace); capabilityElement.setTextContent(BindingUtility.SOAP_CAPABILITY_ModernFaultCodes); /* * body */ // Remove the XML Declaration, if any if (requestString.startsWith("<?xml")) { requestString = requestString.substring(requestString.indexOf("?>") + 2).trim(); } // Generate DOM Document from request xml string DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance(); builderFactory.setNamespaceAware(true); InputStream stream = new ByteArrayInputStream(requestString.getBytes("UTF-8")); // Inject request into body sb.addDocument(builderFactory.newDocumentBuilder().parse(stream)); // Is it never the case that there attachments but no credentials if ((attachments != null) && !attachments.isEmpty()) { addAttachments(message, attachments); } if (credentialInfo == null) { throw new JAXRException(resourceBundle.getString("message.credentialInfo")); } WSS4JSecurityUtilSAML.signSOAPEnvelopeOnClientSAML(se, credentialInfo); SOAPMessage response = send(message); // Check to see if the session has expired // by checking for an error response code // TODO: what error code to we look for? if (isSessionExpired(response)) { credentialInfo.sessionId = null; // sign the SOAPMessage this time // TODO: session - add method to do the signing // signSOAPMessage(msg); // send signed message // SOAPMessage response = send(msg); } // Process the main SOAPPart of the response //check for soapfault and throw RegistryException SOAPFault fault = response.getSOAPBody().getFault(); if (fault != null) { throw createRegistryException(fault); } Reader reader = processResponseBody(response, "Response"); RegistryResponseType ebResponse = null; try { Object obj = BindingUtility.getInstance().getJAXBContext().createUnmarshaller() .unmarshal(new InputSource(reader)); if (obj instanceof JAXBElement<?>) // if Element: take ComplexType from Element obj = ((JAXBElement<RegistryResponseType>) obj).getValue(); ebResponse = (RegistryResponseType) obj; } catch (Exception x) { log.error(CommonResourceBundle.getInstance().getString("message.FailedToUnmarshalServerResponse"), x); throw new JAXRException(resourceBundle.getString("message.invalidServerResponse")); } // Process the attachments of the response if any HashMap<String, Object> responseAttachments = processResponseAttachments(response); return new RegistryResponseHolder(ebResponse, responseAttachments); } catch (SAXException e) { throw new JAXRException(e); } catch (ParserConfigurationException e) { throw new JAXRException(e); } catch (UnsupportedEncodingException x) { throw new JAXRException(x); } catch (MessagingException x) { throw new JAXRException(x); } catch (FileNotFoundException x) { throw new JAXRException(x); } catch (IOException e) { throw new JAXRException(e); } catch (SOAPException x) { x.printStackTrace(); throw new JAXRException(resourceBundle.getString("message.cannotConnect"), x); } catch (TransformerConfigurationException x) { throw new JAXRException(x); } catch (TransformerException x) { throw new JAXRException(x); } }
From source file:com.twinsoft.convertigo.engine.translators.WebServiceTranslator.java
private SOAPElement addSoapElement(Context context, SOAPEnvelope se, SOAPElement soapParent, Node node) throws Exception { String prefix = node.getPrefix(); String namespace = node.getNamespaceURI(); String nodeName = node.getNodeName(); String localName = node.getLocalName(); String value = node.getNodeValue(); boolean includeResponseElement = true; if (context.sequenceName != null) { includeResponseElement = ((Sequence) context.requestedObject).isIncludeResponseElement(); }// w w w .j a v a 2 s . c om SOAPElement soapElement = null; if (node.getNodeType() == Node.ELEMENT_NODE) { Element element = (Element) node; boolean toAdd = true; if (!includeResponseElement && "response".equalsIgnoreCase(localName)) { toAdd = false; } if ("http://schemas.xmlsoap.org/soap/envelope/".equals(element.getParentNode().getNamespaceURI()) || "http://schemas.xmlsoap.org/soap/envelope/".equals(namespace) || nodeName.toLowerCase().endsWith(":envelope") || nodeName.toLowerCase().endsWith(":body") //element.getParentNode().getNodeName().toUpperCase().indexOf("NS0:") != -1 || //nodeName.toUpperCase().indexOf("NS0:") != -1 ) { toAdd = false; } if (toAdd) { if (prefix == null || prefix.equals("")) { soapElement = soapParent.addChildElement(nodeName); } else { soapElement = soapParent.addChildElement(se.createName(localName, prefix, namespace)); } } else { soapElement = soapParent; } if (soapElement != null) { if (soapParent.equals(se.getBody()) && !soapParent.equals(soapElement)) { if (XsdForm.qualified == context.project.getSchemaElementForm()) { if (soapElement.getAttribute("xmlns") == null) { soapElement.addAttribute(se.createName("xmlns"), context.project.getTargetNamespace()); } } } if (element.hasAttributes()) { String attrType = element.getAttribute("type"); if (("attachment").equals(attrType)) { if (context.requestedObject instanceof AbstractHttpTransaction) { AttachmentDetails attachment = AttachmentManager.getAttachment(element); if (attachment != null) { byte[] raw = attachment.getData(); if (raw != null) soapElement.addTextNode(Base64.encodeBase64String(raw)); } /* DON'T WORK YET *\ AttachmentPart ap = responseMessage.createAttachmentPart(new ByteArrayInputStream(raw), element.getAttribute("content-type")); ap.setContentId(key); ap.setContentLocation(element.getAttribute("url")); responseMessage.addAttachmentPart(ap); \* DON'T WORK YET */ } } if (!includeResponseElement && "response".equalsIgnoreCase(localName)) { // do not add attributes } else { NamedNodeMap attributes = element.getAttributes(); int len = attributes.getLength(); for (int i = 0; i < len; i++) { Node item = attributes.item(i); addSoapElement(context, se, soapElement, item); } } } if (element.hasChildNodes()) { NodeList childNodes = element.getChildNodes(); int len = childNodes.getLength(); for (int i = 0; i < len; i++) { Node item = childNodes.item(i); switch (item.getNodeType()) { case Node.ELEMENT_NODE: addSoapElement(context, se, soapElement, item); break; case Node.CDATA_SECTION_NODE: case Node.TEXT_NODE: String text = item.getNodeValue(); text = (text == null) ? "" : text; soapElement.addTextNode(text); break; default: break; } } } } } else if (node.getNodeType() == Node.ATTRIBUTE_NODE) { if (prefix == null || prefix.equals("")) { soapElement = soapParent.addAttribute(se.createName(nodeName), value); } else { soapElement = soapParent.addAttribute(se.createName(localName, prefix, namespace), value); } } return soapElement; }
From source file:org.apache.axis.handlers.HandlerChainImpl.java
public ArrayList getMessageInfo(SOAPMessage message) { ArrayList list = new ArrayList(); try {//from ww w . jav a2 s . c om if (message == null || message.getSOAPPart() == null) return list; SOAPEnvelope env = message.getSOAPPart().getEnvelope(); SOAPBody body = env.getBody(); Iterator it = body.getChildElements(); SOAPElement operation = (SOAPElement) it.next(); list.add(operation.getElementName().toString()); for (Iterator i = operation.getChildElements(); i.hasNext();) { SOAPElement elt = (SOAPElement) i.next(); list.add(elt.getElementName().toString()); } } catch (Exception e) { log.debug("Exception in getMessageInfo : ", e); } return list; }
From source file:org.apache.axis2.jaxws.message.util.impl.SAAJConverterImpl.java
public SOAPEnvelope toSAAJ(org.apache.axiom.soap.SOAPEnvelope omEnvelope) throws WebServiceException { if (log.isDebugEnabled()) { log.debug("Converting OM SOAPEnvelope to SAAJ SOAPEnvelope"); log.debug("The conversion occurs due to " + JavaUtils.stackToString()); }// w ww . java 2 s . c o m SOAPEnvelope soapEnvelope = null; try { // Build the default envelope OMNamespace ns = omEnvelope.getNamespace(); MessageFactory mf = createMessageFactory(ns.getNamespaceURI()); SOAPMessage sm = mf.createMessage(); SOAPPart sp = sm.getSOAPPart(); soapEnvelope = sp.getEnvelope(); // The getSOAPEnvelope() call creates a default SOAPEnvelope with a SOAPHeader and SOAPBody. // The SOAPHeader and SOAPBody are removed (they will be added back in if they are present in the // OMEnvelope). SOAPBody soapBody = soapEnvelope.getBody(); if (soapBody != null) { soapBody.detachNode(); } SOAPHeader soapHeader = soapEnvelope.getHeader(); if (soapHeader != null) { soapHeader.detachNode(); } // We don't know if there is a real OM tree or just a backing XMLStreamReader. // The best way to walk the data is to get the XMLStreamReader and use this // to build the SOAPElements XMLStreamReader reader = omEnvelope.getXMLStreamReader(); NameCreator nc = new NameCreator(soapEnvelope); buildSOAPTree(nc, soapEnvelope, null, reader, false); } catch (WebServiceException e) { throw e; } catch (SOAPException e) { throw ExceptionFactory.makeWebServiceException(e); } return soapEnvelope; }