Search in sources :

Example 26 with SOAPConnection

use of javax.xml.soap.SOAPConnection in project jbossws-cxf by jbossws.

the class ProviderPayloadTestCase method testProviderMessage.

@Test
@RunAsClient
public void testProviderMessage() throws Exception {
    String reqEnvStr = "<env:Envelope xmlns:env='http://schemas.xmlsoap.org/soap/envelope/'>" + "  <env:Body>" + reqString + "</env:Body>" + "</env:Envelope>";
    MessageFactory msgFactory = MessageFactory.newInstance();
    SOAPConnection con = SOAPConnectionFactory.newInstance().createConnection();
    SOAPMessage reqMsg = msgFactory.createMessage(null, new ByteArrayInputStream(reqEnvStr.getBytes()));
    URL epURL = baseURL;
    SOAPMessage resMsg = con.call(reqMsg, epURL);
    SOAPEnvelope resEnv = resMsg.getSOAPPart().getEnvelope();
    SOAPHeader soapHeader = resEnv.getHeader();
    if (soapHeader != null)
        soapHeader.detachNode();
    Node responseBody = DOMUtils.getFirstChildElement(resEnv.getBody());
    assertEquals("wrong namespace: " + responseBody.getNamespaceURI(), "http://org.jboss.ws/provider", responseBody.getNamespaceURI());
    assertEquals("wrong localPart: " + responseBody.getLocalName(), "somePayload", responseBody.getLocalName());
    String responseString = DOMUtils.getTextContent(responseBody);
    assertEquals("wrong content: " + responseString, "Hello:Inbound:LogicalSourceHandler:Outbound:LogicalSourceHandler", responseString);
}
Also used : MessageFactory(javax.xml.soap.MessageFactory) ByteArrayInputStream(java.io.ByteArrayInputStream) Node(org.w3c.dom.Node) SOAPConnection(javax.xml.soap.SOAPConnection) SOAPEnvelope(javax.xml.soap.SOAPEnvelope) SOAPMessage(javax.xml.soap.SOAPMessage) URL(java.net.URL) SOAPHeader(javax.xml.soap.SOAPHeader) RunAsClient(org.jboss.arquillian.container.test.api.RunAsClient) Test(org.junit.Test) JBossWSTest(org.jboss.wsf.test.JBossWSTest)

Example 27 with SOAPConnection

use of javax.xml.soap.SOAPConnection in project jbossws-cxf by jbossws.

the class JBWS3945TestCase method testSOAP12SoapFaultExceptionOnHTTP400UsingSAAJ.

@Test
@RunAsClient
public void testSOAP12SoapFaultExceptionOnHTTP400UsingSAAJ() throws Exception {
    try {
        // <soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope"><soap:Body><ns2:throwSoapFaultException xmlns:ns2="http://server.exception.samples.jaxws.ws.test.jboss.org/"/></soap:Body></soap:Envelope>
        SOAPConnectionFactory conFac = SOAPConnectionFactory.newInstance();
        SOAPConnection con = conFac.createConnection();
        MessageFactory msgFactory = MessageFactory.newInstance();
        SOAPMessage msg = msgFactory.createMessage();
        msg.getSOAPBody().addBodyElement(new QName(targetNS, "throwSoapFaultException"));
        SOAPMessage response = con.call(msg, new URL(targetEndpoint + "Servlet"));
        Element el = (Element) response.getSOAPBody().getChildElements().next();
        assertEquals("Fault", el.getLocalName());
    } catch (Exception e) {
        fail(e);
    }
}
Also used : SOAPConnectionFactory(javax.xml.soap.SOAPConnectionFactory) MessageFactory(javax.xml.soap.MessageFactory) QName(javax.xml.namespace.QName) Element(org.w3c.dom.Element) SOAPConnection(javax.xml.soap.SOAPConnection) SOAPMessage(javax.xml.soap.SOAPMessage) URL(java.net.URL) WebServiceException(javax.xml.ws.WebServiceException) SOAPFaultException(javax.xml.ws.soap.SOAPFaultException) RunAsClient(org.jboss.arquillian.container.test.api.RunAsClient) Test(org.junit.Test) JBossWSTest(org.jboss.wsf.test.JBossWSTest)

Example 28 with SOAPConnection

use of javax.xml.soap.SOAPConnection in project pentaho-platform by pentaho.

the class XMLABaseComponent method executeQuery.

/**
 * Execute query
 *
 * @param query   - MDX to be executed
 * @param catalog
 * @param handler Callback handler
 * @throws XMLAException
 */
public boolean executeQuery(final String query, final String catalog) throws XMLAException {
    Object[][] columnHeaders = null;
    Object[][] rowHeaders = null;
    Object[][] data = null;
    int columnCount = 0;
    int rowCount = 0;
    SOAPConnection connection = null;
    SOAPMessage reply = null;
    try {
        connection = scf.createConnection();
        SOAPMessage msg = mf.createMessage();
        MimeHeaders mh = msg.getMimeHeaders();
        // $NON-NLS-1$
        mh.setHeader("SOAPAction", XMLABaseComponent.EXECUTE_ACTION);
        SOAPPart soapPart = msg.getSOAPPart();
        SOAPEnvelope envelope = soapPart.getEnvelope();
        envelope.setEncodingStyle(XMLABaseComponent.ENCODING_STYLE);
        SOAPBody body = envelope.getBody();
        // $NON-NLS-1$//$NON-NLS-2$
        Name nEx = envelope.createName("Execute", "", XMLABaseComponent.XMLA_URI);
        SOAPElement eEx = body.addChildElement(nEx);
        eEx.setEncodingStyle(XMLABaseComponent.ENCODING_STYLE);
        // add the parameters
        // COMMAND parameter
        // <Command>
        // <Statement>select [Measures].members on Columns from
        // Sales</Statement>
        // </Command>
        // $NON-NLS-1$ //$NON-NLS-2$
        Name nCom = envelope.createName("Command", "", XMLABaseComponent.XMLA_URI);
        SOAPElement eCommand = eEx.addChildElement(nCom);
        // $NON-NLS-1$ //$NON-NLS-2$
        Name nSta = envelope.createName("Statement", "", XMLABaseComponent.XMLA_URI);
        SOAPElement eStatement = eCommand.addChildElement(nSta);
        eStatement.addTextNode(query);
        // <Properties>
        // <PropertyList>
        // <DataSourceInfo>Provider=MSOLAP;Data
        // Source=local</DataSourceInfo>
        // <Catalog>Foodmart 2000</Catalog>
        // <Format>Multidimensional</Format>
        // <AxisFormat>TupleFormat</AxisFormat> oder "ClusterFormat"
        // </PropertyList>
        // </Properties>
        Map paraList = new HashMap();
        // $NON-NLS-1$
        paraList.put("DataSourceInfo", dataSource);
        // $NON-NLS-1$
        paraList.put("Catalog", catalog);
        // $NON-NLS-1$ //$NON-NLS-2$
        paraList.put("Format", "Multidimensional");
        // $NON-NLS-1$ //$NON-NLS-2$
        paraList.put("AxisFormat", "TupleFormat");
        // $NON-NLS-1$ //$NON-NLS-2$
        addParameterList(envelope, eEx, "Properties", "PropertyList", paraList);
        msg.saveChanges();
        // $NON-NLS-1$
        debug("Request for Execute");
        logSoapMsg(msg);
        // run the call
        reply = connection.call(msg, url);
        // $NON-NLS-1$
        debug("Reply from Execute");
        logSoapMsg(reply);
        // error check
        errorCheck(reply);
        // process the reply
        SOAPElement eRoot = findExecRoot(reply);
        // for each axis, get the positions (tuples)
        // $NON-NLS-1$ //$NON-NLS-2$
        Name name = envelope.createName("Axes", "", XMLABaseComponent.MDD_URI);
        SOAPElement eAxes = selectSingleNode(eRoot, name);
        if (eAxes == null) {
            // $NON-NLS-1$
            throw new XMLAException("Excecute result has no Axes element");
        }
        // $NON-NLS-1$ //$NON-NLS-2$
        name = envelope.createName("Axis", "", XMLABaseComponent.MDD_URI);
        Iterator itAxis = eAxes.getChildElements(name);
        AxisLoop: for (int iOrdinal = 0; itAxis.hasNext(); ) {
            SOAPElement eAxis = (SOAPElement) itAxis.next();
            // $NON-NLS-1$
            name = envelope.createName("name");
            String axisName = eAxis.getAttributeValue(name);
            int axisOrdinal;
            if (axisName.equals("SlicerAxis")) {
                // $NON-NLS-1$
                continue;
            } else {
                axisOrdinal = iOrdinal++;
            }
            // $NON-NLS-1$//$NON-NLS-2$
            name = envelope.createName("Tuples", "", XMLABaseComponent.MDD_URI);
            SOAPElement eTuples = selectSingleNode(eAxis, name);
            if (eTuples == null) {
                // what else?
                continue AxisLoop;
            }
            // $NON-NLS-1$//$NON-NLS-2$
            name = envelope.createName("Tuple", "", XMLABaseComponent.MDD_URI);
            Iterator itTuple = eTuples.getChildElements(name);
            // loop over tuples
            int positionOrdinal = 0;
            while (itTuple.hasNext()) {
                // TupleLoop
                SOAPElement eTuple = (SOAPElement) itTuple.next();
                if ((axisOrdinal == XMLABaseComponent.AXIS_COLUMNS) && (columnHeaders == null)) {
                    // $NON-NLS-1$
                    columnCount = getChildCount(envelope, eTuples, "Tuple");
                    // $NON-NLS-1$
                    columnHeaders = new Object[getChildCount(envelope, eTuple, "Member")][columnCount];
                } else if ((axisOrdinal == XMLABaseComponent.AXIS_ROWS) && (rowHeaders == null)) {
                    // $NON-NLS-1$
                    rowCount = getChildCount(envelope, eTuples, "Tuple");
                    // $NON-NLS-1$
                    rowHeaders = new Object[rowCount][getChildCount(envelope, eTuple, "Member")];
                }
                int index = 0;
                // $NON-NLS-1$//$NON-NLS-2$
                name = envelope.createName("Member", "", XMLABaseComponent.MDD_URI);
                Iterator itMember = eTuple.getChildElements(name);
                while (itMember.hasNext()) {
                    // MemberLoop
                    SOAPElement eMem = (SOAPElement) itMember.next();
                    // loop over children nodes
                    String caption = null;
                    Iterator it = eMem.getChildElements();
                    InnerLoop: while (it.hasNext()) {
                        Node n = (Node) it.next();
                        if (!(n instanceof SOAPElement)) {
                            continue InnerLoop;
                        }
                        SOAPElement el = (SOAPElement) n;
                        String enam = el.getElementName().getLocalName();
                        if (enam.equals("Caption")) {
                            // $NON-NLS-1$
                            caption = el.getValue();
                        }
                    }
                    if (axisOrdinal == XMLABaseComponent.AXIS_COLUMNS) {
                        columnHeaders[index][positionOrdinal] = caption;
                    } else if (axisOrdinal == XMLABaseComponent.AXIS_ROWS) {
                        rowHeaders[positionOrdinal][index] = caption;
                    }
                    ++index;
                }
                // MemberLoop
                ++positionOrdinal;
            }
        // TupleLoop
        }
        // AxisLoop
        data = new Object[rowCount][columnCount];
        // loop over cells in result set
        // $NON-NLS-1$//$NON-NLS-2$
        name = envelope.createName("CellData", "", XMLABaseComponent.MDD_URI);
        SOAPElement eCellData = selectSingleNode(eRoot, name);
        // $NON-NLS-1$//$NON-NLS-2$
        name = envelope.createName("Cell", "", XMLABaseComponent.MDD_URI);
        Iterator itSoapCell = eCellData.getChildElements(name);
        while (itSoapCell.hasNext()) {
            // CellLoop
            SOAPElement eCell = (SOAPElement) itSoapCell.next();
            // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
            name = envelope.createName("CellOrdinal", "", "");
            String cellOrdinal = eCell.getAttributeValue(name);
            int ordinal = Integer.parseInt(cellOrdinal);
            // $NON-NLS-1$//$NON-NLS-2$
            name = envelope.createName("Value", "", XMLABaseComponent.MDD_URI);
            Object value = selectSingleNode(eCell, name).getValue();
            int rowLoc = ordinal / columnCount;
            int columnLoc = ordinal % columnCount;
            data[rowLoc][columnLoc] = value;
        }
        // CellLoop
        MemoryResultSet resultSet = new MemoryResultSet();
        MemoryMetaData metaData = new MemoryMetaData(columnHeaders, rowHeaders);
        resultSet.setMetaData(metaData);
        for (Object[] element : data) {
            resultSet.addRow(element);
        }
        rSet = resultSet;
        if (resultSet != null) {
            if (getResultOutputName() != null) {
                setOutputValue(getResultOutputName(), resultSet);
            }
            return true;
        }
        return false;
    } catch (SOAPException se) {
        throw new XMLAException(se);
    } finally {
        if (connection != null) {
            try {
                connection.close();
            } catch (SOAPException e) {
                // log and ignore
                // $NON-NLS-1$
                error("?", e);
            }
        }
    }
}
Also used : HashMap(java.util.HashMap) Node(javax.xml.soap.Node) SOAPConnection(javax.xml.soap.SOAPConnection) MemoryMetaData(org.pentaho.commons.connection.memory.MemoryMetaData) SOAPEnvelope(javax.xml.soap.SOAPEnvelope) SOAPMessage(javax.xml.soap.SOAPMessage) Name(javax.xml.soap.Name) MimeHeaders(javax.xml.soap.MimeHeaders) SOAPBody(javax.xml.soap.SOAPBody) SOAPException(javax.xml.soap.SOAPException) SOAPPart(javax.xml.soap.SOAPPart) SOAPElement(javax.xml.soap.SOAPElement) Iterator(java.util.Iterator) HashMap(java.util.HashMap) Map(java.util.Map) MemoryResultSet(org.pentaho.commons.connection.memory.MemoryResultSet)

Aggregations

SOAPConnection (javax.xml.soap.SOAPConnection)28 SOAPMessage (javax.xml.soap.SOAPMessage)28 URL (java.net.URL)16 MessageFactory (javax.xml.soap.MessageFactory)13 Test (org.junit.Test)12 SOAPConnectionFactory (javax.xml.soap.SOAPConnectionFactory)11 SOAPElement (javax.xml.soap.SOAPElement)11 RunAsClient (org.jboss.arquillian.container.test.api.RunAsClient)11 JBossWSTest (org.jboss.wsf.test.JBossWSTest)11 QName (javax.xml.namespace.QName)10 SOAPException (javax.xml.soap.SOAPException)8 ByteArrayInputStream (java.io.ByteArrayInputStream)6 IOException (java.io.IOException)5 SOAPEnvelope (javax.xml.soap.SOAPEnvelope)5 ByteArrayOutputStream (java.io.ByteArrayOutputStream)4 AttachmentPart (javax.xml.soap.AttachmentPart)4 SOAPBody (javax.xml.soap.SOAPBody)4 SOAPFactory (javax.xml.soap.SOAPFactory)3 Node (org.w3c.dom.Node)3 FSException (com.sun.identity.federation.common.FSException)2