Java Code Examples for javax.xml.soap.SOAPEnvelope#createName()

The following examples show how to use javax.xml.soap.SOAPEnvelope#createName() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: XmlTest.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
private SOAPMessage createMessage(MessageFactory mf) throws SOAPException, IOException {
    SOAPMessage msg = mf.createMessage();
    SOAPEnvelope envelope = msg.getSOAPPart().getEnvelope();
    Name name = envelope.createName("hello", "ex", "http://example.com");
    envelope.getBody().addChildElement(name).addTextNode("THERE!");

    String s = "<root><hello>THERE!</hello></root>";

    AttachmentPart ap = msg.createAttachmentPart(
            new StreamSource(new ByteArrayInputStream(s.getBytes())),
            "text/xml"
    );
    msg.addAttachmentPart(ap);
    msg.saveChanges();

    return msg;
}
 
Example 2
Source File: JRXmlaQueryExecuter.java    From jasperreports with GNU Lesser General Public License v3.0 6 votes vote down vote up
protected void addParameterList(SOAPEnvelope envelope, SOAPElement eParent, String typeName, String listName, Map<String, String> params) throws SOAPException
{
	Name nPara = envelope.createName(typeName, "", XMLA_URI);
	SOAPElement eType = eParent.addChildElement(nPara);
	nPara = envelope.createName(listName, "", XMLA_URI);
	SOAPElement eList = eType.addChildElement(nPara);
	if (params == null)
	{
		return;
	}
	for (Iterator<Map.Entry<String, String>> entryIt = params.entrySet().iterator(); entryIt.hasNext();)
	{
		Map.Entry<String, String> entry = entryIt.next();
		String tag = entry.getKey();
		String value = entry.getValue();
		nPara = envelope.createName(tag, "", XMLA_URI);
		SOAPElement eTag = eList.addChildElement(nPara);
		eTag.addTextNode(value);
	}
}
 
Example 3
Source File: SoapRequestBean.java    From openxds with Apache License 2.0 6 votes vote down vote up
public SOAPMessage onMessage(SOAPMessage msg){
    //handles the response back from the registry
    PrintStream orig = System.out;
    
    try {
        SOAPEnvelope env = msg.getSOAPPart().getEnvelope();
        Name response = env.createName("response");
        env.getBody().getChildElements(response);
        
    } catch (SOAPException ex) {
        ByteArrayOutputStream logarray = new ByteArrayOutputStream();
        ex.printStackTrace(writeErrorlog(logarray));
        logstring = logarray.toString();
        setlogmsg(logstring);  
    }
    
    return msg;
}
 
Example 4
Source File: SOAPGenerator.java    From cougar with Apache License 2.0 5 votes vote down vote up
private static SOAPMessage generateSOAPMessageShell(HttpCallBean httpCallBean) {
	SOAPMessage message = null;
	String secNameSpace = "http://www.betfair.com/security/";
	httpCallBean.setServiceName("Baseline");
	String nameSpace = httpCallBean.getNameSpace();
	
	if(nameSpace==null || nameSpace.equals(""))
	{
		throw new RuntimeException("Namespace error invalid :" + nameSpace);
	}
	
	MessageFactory mf;

	try {
		mf = MessageFactory.newInstance();

		message = mf.createMessage();

		SOAPPart soapPart = message.getSOAPPart();
		SOAPEnvelope envelope = soapPart.getEnvelope();

		envelope.addNamespaceDeclaration("soapenv",
				"http://schemas.xmlsoap.org/soap/envelope/");
		envelope.addNamespaceDeclaration(BAS, nameSpace);

		envelope.addNamespaceDeclaration("sec", secNameSpace);

		// header
		envelope.getHeader().detachNode();
		SOAPHeader soapHeader = envelope.addHeader();

		Name header = envelope.createName("Header", "soapenv",
				"http://schemas.xmlsoap.org/soap/envelope/");

		soapHeader.addHeaderElement(header);
	} catch (Exception e) {
		throw new RuntimeException(e);
	}
	return message;
}
 
Example 5
Source File: Tr064Comm.java    From openhab1-addons with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Sets all required namespaces and prepares the SOAP message to send.
 * Creates skeleton + body data.
 *
 * @param bodyData
 *            is attached to skeleton to form entire SOAP message
 * @return ready to send SOAP message
 */
private SOAPMessage constructTr064Msg(SOAPBodyElement bodyData) {
    SOAPMessage soapMsg = null;

    try {
        MessageFactory msgFac;
        msgFac = MessageFactory.newInstance();
        soapMsg = msgFac.createMessage();
        soapMsg.setProperty(SOAPMessage.WRITE_XML_DECLARATION, "true");
        soapMsg.setProperty(SOAPMessage.CHARACTER_SET_ENCODING, "UTF-8");
        SOAPPart part = soapMsg.getSOAPPart();

        // valid for entire SOAP msg
        String namespace = "s";

        // create suitable fbox envelope
        SOAPEnvelope envelope = part.getEnvelope();
        envelope.setPrefix(namespace);
        envelope.removeNamespaceDeclaration("SOAP-ENV"); // delete standard namespace which was already set
        envelope.addNamespaceDeclaration(namespace, "http://schemas.xmlsoap.org/soap/envelope/");
        Name nEncoding = envelope.createName("encodingStyle", namespace,
                "http://schemas.xmlsoap.org/soap/encoding/");
        envelope.addAttribute(nEncoding, "http://schemas.xmlsoap.org/soap/encoding/");

        // create empty header
        SOAPHeader header = envelope.getHeader();
        header.setPrefix(namespace);

        // create body with command based on parameter
        SOAPBody body = envelope.getBody();
        body.setPrefix(namespace);
        body.addChildElement(bodyData); // bodyData already prepared. Needs only be added

    } catch (Exception e) {
        logger.error("Error creating SOAP message for fbox request with data {}", bodyData);
        e.printStackTrace();
    }

    return soapMsg;
}
 
Example 6
Source File: JRXmlaQueryExecuter.java    From jasperreports with GNU Lesser General Public License v3.0 4 votes vote down vote up
protected SOAPMessage createQueryMessage()
{
	String queryStr = getQueryString();

	if (log.isDebugEnabled())
	{
		log.debug("MDX query: " + queryStr);
	}
	
	try
	{
		MessageFactory mf = MessageFactory.newInstance();
		SOAPMessage message = mf.createMessage();

		MimeHeaders mh = message.getMimeHeaders();
		mh.setHeader("SOAPAction", "\"urn:schemas-microsoft-com:xml-analysis:Execute\"");

		SOAPPart soapPart = message.getSOAPPart();
		SOAPEnvelope envelope = soapPart.getEnvelope();
		SOAPBody body = envelope.getBody();
		Name nEx = envelope.createName("Execute", "", XMLA_URI);

		SOAPElement eEx = body.addChildElement(nEx);

		// add the parameters

		// COMMAND parameter
		// <Command>
		// <Statement>queryStr</Statement>
		// </Command>
		Name nCom = envelope.createName("Command", "", XMLA_URI);
		SOAPElement eCommand = eEx.addChildElement(nCom);
		Name nSta = envelope.createName("Statement", "", XMLA_URI);
		SOAPElement eStatement = eCommand.addChildElement(nSta);
		eStatement.addTextNode(queryStr);

		// <Properties>
		// <PropertyList>
		// <DataSourceInfo>dataSource</DataSourceInfo>
		// <Catalog>catalog</Catalog>
		// <Format>Multidimensional</Format>
		// <AxisFormat>TupleFormat</AxisFormat>
		// </PropertyList>
		// </Properties>
		Map<String, String> paraList = new HashMap<String, String>();
		String datasource = (String) getParameterValue(JRXmlaQueryExecuterFactory.PARAMETER_XMLA_DATASOURCE);
		paraList.put("DataSourceInfo", datasource);
		String catalog = (String) getParameterValue(JRXmlaQueryExecuterFactory.PARAMETER_XMLA_CATALOG);
		paraList.put("Catalog", catalog);
		paraList.put("Format", "Multidimensional");
		paraList.put("AxisFormat", "TupleFormat");
		addParameterList(envelope, eEx, "Properties", "PropertyList", paraList);
		message.saveChanges();

		if (log.isDebugEnabled())
		{
			log.debug("XML/A query message: \n" + prettyPrintSOAP(message.getSOAPPart().getEnvelope()));
		}

		return message;
	}
	catch (SOAPException e)
	{
		throw new JRRuntimeException(e);
	}
}