Search in sources :

Example 41 with SOAPEnvelope

use of javax.xml.soap.SOAPEnvelope 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)

Example 42 with SOAPEnvelope

use of javax.xml.soap.SOAPEnvelope in project cxf by apache.

the class TestSOAPHandler method handleMessage.

public boolean handleMessage(SOAPMessageContext ctx) {
    try {
        SOAPMessage msg = ctx.getMessage();
        /*
             * System.out.println("-----------soap---------");
             * msg.writeTo(System.out);
             * System.out.println("-----------soap---------");
             */
        SOAPEnvelope env = msg.getSOAPPart().getEnvelope();
        SOAPBody body = env.getBody();
        Iterator<?> it = body.getChildElements();
        while (it.hasNext()) {
            Object elem = it.next();
            if (elem instanceof SOAPElement) {
                Iterator<?> it2 = ((SOAPElement) elem).getChildElements();
                while (it2.hasNext()) {
                    Object elem2 = it2.next();
                    if (elem2 instanceof SOAPElement) {
                        String value = ((SOAPElement) elem2).getValue();
                        if (value != null && (value.indexOf("Milestone-0") >= 0 || value.indexOf("TestGreetMeResponseServerLogicalHandler") >= 0)) {
                            value = value + "ServerSOAPHandler";
                            ((SOAPElement) elem2).setValue(value);
                        }
                    }
                }
            }
        }
        msg.saveChanges();
    /*
             * System.out.println("-----------soapaf---------");
             * msg.writeTo(System.out);
             * System.out.println("-----------soapaf---------");
             */
    } catch (Exception e) {
        e.printStackTrace();
    }
    return true;
}
Also used : SOAPBody(javax.xml.soap.SOAPBody) SOAPElement(javax.xml.soap.SOAPElement) SOAPEnvelope(javax.xml.soap.SOAPEnvelope) SOAPMessage(javax.xml.soap.SOAPMessage)

Example 43 with SOAPEnvelope

use of javax.xml.soap.SOAPEnvelope in project cxf by apache.

the class TestMtomProviderImpl method invoke.

public SOAPMessage invoke(final SOAPMessage request) {
    try {
        System.out.println("=== Received client request ===");
        // create the SOAPMessage
        SOAPMessage message = MessageFactory.newInstance().createMessage();
        SOAPPart part = message.getSOAPPart();
        SOAPEnvelope envelope = part.getEnvelope();
        SOAPBody body = envelope.getBody();
        SOAPBodyElement testResponse = body.addBodyElement(envelope.createName("testXopResponse", null, "http://cxf.apache.org/mime/types"));
        SOAPElement name = testResponse.addChildElement("name", null, "http://cxf.apache.org/mime/types");
        name.setTextContent("return detail + call detail");
        SOAPElement attachinfo = testResponse.addChildElement("attachinfo", null, "http://cxf.apache.org/mime/types");
        SOAPElement include = attachinfo.addChildElement("Include", "xop", "http://www.w3.org/2004/08/xop/include");
        int fileSize = 0;
        try (InputStream pre = this.getClass().getResourceAsStream("/wsdl/mtom_xop.wsdl")) {
            for (int i = pre.read(); i != -1; i = pre.read()) {
                fileSize++;
            }
        }
        int count = 50;
        byte[] data = new byte[fileSize * count];
        for (int x = 0; x < count; x++) {
            this.getClass().getResourceAsStream("/wsdl/mtom_xop.wsdl").read(data, fileSize * x, fileSize);
        }
        DataHandler dh = new DataHandler(new ByteArrayDataSource(data, "application/octet-stream"));
        // create the image attachment
        AttachmentPart attachment = message.createAttachmentPart(dh);
        attachment.setContentId("mtom_xop.wsdl");
        message.addAttachmentPart(attachment);
        System.out.println("Adding attachment: " + attachment.getContentId() + ":" + attachment.getSize());
        // add the reference to the image attachment
        include.addAttribute(envelope.createName("href"), "cid:" + attachment.getContentId());
        return message;
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}
Also used : InputStream(java.io.InputStream) AttachmentPart(javax.xml.soap.AttachmentPart) SOAPEnvelope(javax.xml.soap.SOAPEnvelope) DataHandler(javax.activation.DataHandler) SOAPMessage(javax.xml.soap.SOAPMessage) SOAPBody(javax.xml.soap.SOAPBody) SOAPPart(javax.xml.soap.SOAPPart) SOAPElement(javax.xml.soap.SOAPElement) ByteArrayDataSource(javax.mail.util.ByteArrayDataSource) SOAPBodyElement(javax.xml.soap.SOAPBodyElement)

Example 44 with SOAPEnvelope

use of javax.xml.soap.SOAPEnvelope in project narayana by jbosstm.

the class InstanceIdentifierHandler method handleMessageOutbound.

/**
 * check for an arjuna context attached to the message context and, if found, install its identifier as the value
 * of a soap message header element
 * @param context
 * @return
 * @throws ProtocolException
 */
protected boolean handleMessageOutbound(SOAPMessageContext context) throws ProtocolException {
    try {
        ArjunaContext arjunaContext = ArjunaContext.getCurrentContext(context);
        if (arjunaContext != null) {
            InstanceIdentifier instanceIdentifier = arjunaContext.getInstanceIdentifier();
            // insert a header into the current message containing the instance identifier as a text element
            final SOAPMessage soapMessage = context.getMessage();
            final SOAPEnvelope soapEnvelope = soapMessage.getSOAPPart().getEnvelope();
            SOAPHeader soapHeader = soapEnvelope.getHeader();
            if (soapHeader == null) {
                soapHeader = soapEnvelope.addHeader();
            }
            final SOAPHeaderElement headerElement = soapHeader.addHeaderElement(ArjunaConstants.WSARJ_ELEMENT_INSTANCE_IDENTIFIER_QNAME);
            headerElement.setValue(instanceIdentifier.getInstanceIdentifier());
            headerElement.setMustUnderstand(true);
        }
    } catch (Exception se) {
        throw new ProtocolException(se);
    }
    return true;
}
Also used : SOAPHeaderElement(javax.xml.soap.SOAPHeaderElement) ProtocolException(javax.xml.ws.ProtocolException) InstanceIdentifier(com.arjuna.webservices11.wsarj.InstanceIdentifier) SOAPEnvelope(javax.xml.soap.SOAPEnvelope) ArjunaContext(com.arjuna.webservices11.wsarj.ArjunaContext) SOAPMessage(javax.xml.soap.SOAPMessage) SOAPHeader(javax.xml.soap.SOAPHeader) ProtocolException(javax.xml.ws.ProtocolException)

Example 45 with SOAPEnvelope

use of javax.xml.soap.SOAPEnvelope in project narayana by jbosstm.

the class JaxBaseHeaderContextProcessor method handleOutboundMessage.

/**
 * Handle the request.
 *
 * @param soapMessage The current message context.
 * @param mustUnderstand Value of MustUnderstand attribute.
 * @return whether the message was handled
 */
public boolean handleOutboundMessage(final SOAPMessage soapMessage, boolean mustUnderstand) {
    if (soapMessage == null) {
        return true;
    }
    try {
        /*
             * There should either be an Atomic Transaction *or* a Business Activity
             * associated with the thread.
             */
        final TransactionManager transactionManager = TransactionManagerFactory.transactionManager();
        final com.arjuna.mw.wst11.BusinessActivityManager businessActivityManager = BusinessActivityManagerFactory.businessActivityManager();
        final Context atContext;
        if (transactionManager != null) {
            final TxContextImple txContext = (TxContextImple) transactionManager.currentTransaction();
            atContext = (txContext == null ? null : txContext.context());
        } else {
            atContext = null;
        }
        final Context baContext;
        if (businessActivityManager != null) {
            final com.arjuna.mwlabs.wst11.ba.context.TxContextImple txContext = (com.arjuna.mwlabs.wst11.ba.context.TxContextImple) businessActivityManager.currentTransaction();
            baContext = (txContext == null ? null : txContext.context());
        } else {
            baContext = null;
        }
        final CoordinationContextType coordinationContext;
        if (baContext != null) {
            coordinationContext = baContext.getCoordinationContext();
        } else if (atContext != null) {
            coordinationContext = atContext.getCoordinationContext();
        } else {
            coordinationContext = null;
        }
        if (coordinationContext != null) {
            final SOAPEnvelope env = soapMessage.getSOAPPart().getEnvelope();
            SOAPHeader header = env.getHeader();
            if (header == null) {
                header = env.addHeader();
            }
            final Name name = env.createName(CoordinationConstants.WSCOOR_ELEMENT_COORDINATION_CONTEXT, CoordinationConstants.WSCOOR_PREFIX, CoordinationConstants.WSCOOR_NAMESPACE);
            final SOAPHeaderElement headerElement = header.addHeaderElement(name);
            headerElement.addNamespaceDeclaration(CoordinationConstants.WSCOOR_PREFIX, CoordinationConstants.WSCOOR_NAMESPACE);
            headerElement.setMustUnderstand(mustUnderstand);
            CoordinationContextHelper.serialise(coordinationContext, headerElement);
        }
    } catch (final Throwable th) {
        wstxLogger.i18NLogger.warn_mw_wst11_client_JaxHC11P_1("com.arjuna.mw.wst11.client.JaxBaseHeaderContextProcessor.handleRequest()", th);
    }
    return true;
}
Also used : TxContext(com.arjuna.mw.wst.TxContext) Context(com.arjuna.mw.wsc11.context.Context) SOAPHeaderElement(javax.xml.soap.SOAPHeaderElement) SOAPEnvelope(javax.xml.soap.SOAPEnvelope) TxContextImple(com.arjuna.mwlabs.wst11.at.context.TxContextImple) Name(javax.xml.soap.Name) TransactionManager(com.arjuna.mw.wst11.TransactionManager) CoordinationContextType(org.oasis_open.docs.ws_tx.wscoor._2006._06.CoordinationContextType) SOAPHeader(javax.xml.soap.SOAPHeader)

Aggregations

SOAPEnvelope (javax.xml.soap.SOAPEnvelope)59 SOAPMessage (javax.xml.soap.SOAPMessage)34 SOAPException (javax.xml.soap.SOAPException)31 SOAPBody (javax.xml.soap.SOAPBody)24 SOAPPart (javax.xml.soap.SOAPPart)24 SOAPElement (javax.xml.soap.SOAPElement)22 SOAPHeader (javax.xml.soap.SOAPHeader)16 Name (javax.xml.soap.Name)13 SOAPHeaderElement (javax.xml.soap.SOAPHeaderElement)13 Iterator (java.util.Iterator)12 QName (javax.xml.namespace.QName)12 WebServiceException (javax.xml.ws.WebServiceException)10 ProtocolException (javax.xml.ws.ProtocolException)7 SOAPMessageContext (javax.xml.ws.handler.soap.SOAPMessageContext)6 CoordinationContextType (org.oasis_open.docs.ws_tx.wscoor._2006._06.CoordinationContextType)6 Detail (javax.xml.soap.Detail)5 MessageFactory (javax.xml.soap.MessageFactory)5 SOAPConnection (javax.xml.soap.SOAPConnection)5 SOAPFault (javax.xml.soap.SOAPFault)5 Test (org.junit.Test)5