Search in sources :

Example 36 with SOAPEnvelope

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

the class HandlerInvocationTest method testServerEndpointRemoteFault.

@Test
public void testServerEndpointRemoteFault() throws PingException {
    TestHandler<LogicalMessageContext> handler1 = new TestHandler<LogicalMessageContext>(false);
    TestHandler<LogicalMessageContext> handler2 = new TestHandler<LogicalMessageContext>(false) {

        public boolean handleFault(LogicalMessageContext ctx) {
            super.handleFault(ctx);
            try {
                Boolean outbound = (Boolean) ctx.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
                if (!outbound) {
                    LogicalMessage msg = ctx.getMessage();
                    String payload = convertDOMToString(msg.getPayload());
                    assertTrue(payload.indexOf("<faultstring>" + "servant throws SOAPFaultException" + "</faultstring>") > -1);
                }
            } catch (Exception e) {
                e.printStackTrace();
                fail(e.toString());
            }
            return true;
        }

        private String convertDOMToString(Source s) throws TransformerException {
            StringWriter stringWriter = new StringWriter();
            StreamResult streamResult = new StreamResult(stringWriter);
            TransformerFactory transformerFactory = TransformerFactory.newInstance();
            transformerFactory.setFeature(javax.xml.XMLConstants.FEATURE_SECURE_PROCESSING, true);
            Transformer transformer = transformerFactory.newTransformer();
            transformer.setOutputProperty(OutputKeys.INDENT, "no");
            transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2");
            transformer.setOutputProperty(OutputKeys.METHOD, "xml");
            transformer.transform(s, streamResult);
            return stringWriter.toString();
        }
    };
    TestSOAPHandler soapHandler1 = new TestSOAPHandler(false);
    TestSOAPHandler soapHandler2 = new TestSOAPHandler(false) {

        public boolean handleFault(SOAPMessageContext ctx) {
            super.handleFault(ctx);
            try {
                Boolean outbound = (Boolean) ctx.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
                if (!outbound) {
                    SOAPEnvelope env = ctx.getMessage().getSOAPPart().getEnvelope();
                    assertTrue("expected SOAPFault in SAAJ model", env.getBody().hasFault());
                }
            } catch (Exception e) {
                e.printStackTrace();
                fail(e.toString());
            }
            return true;
        }
    };
    addHandlersToChain((BindingProvider) handlerTest, handler1, handler2, soapHandler1, soapHandler2);
    try {
        handlerTest.pingWithArgs("servant throw SOAPFaultException");
        fail("did not get expected Exception");
    } catch (SOAPFaultException sfe) {
    // expected
    }
    assertEquals(1, handler1.getHandleMessageInvoked());
    assertEquals(1, handler2.getHandleMessageInvoked());
    assertEquals(1, soapHandler1.getHandleMessageInvoked());
    assertEquals(1, soapHandler2.getHandleMessageInvoked());
    assertEquals(1, handler2.getHandleFaultInvoked());
    assertEquals(1, handler1.getHandleFaultInvoked());
    assertEquals(1, soapHandler1.getHandleFaultInvoked());
    assertEquals(1, soapHandler2.getHandleFaultInvoked());
    assertEquals(1, handler1.getCloseInvoked());
    assertEquals(1, handler2.getCloseInvoked());
    assertEquals(1, soapHandler1.getCloseInvoked());
    assertEquals(1, soapHandler2.getCloseInvoked());
    assertTrue(handler2.getInvokeOrderOfClose() < handler1.getInvokeOrderOfClose());
}
Also used : LogicalMessageContext(javax.xml.ws.handler.LogicalMessageContext) TransformerFactory(javax.xml.transform.TransformerFactory) Transformer(javax.xml.transform.Transformer) StreamResult(javax.xml.transform.stream.StreamResult) SOAPFaultException(javax.xml.ws.soap.SOAPFaultException) SOAPEnvelope(javax.xml.soap.SOAPEnvelope) PingException(org.apache.handler_test.PingException) ProtocolException(javax.xml.ws.ProtocolException) SOAPFaultException(javax.xml.ws.soap.SOAPFaultException) TransformerException(javax.xml.transform.TransformerException) WebServiceException(javax.xml.ws.WebServiceException) Source(javax.xml.transform.Source) StringWriter(java.io.StringWriter) SOAPMessageContext(javax.xml.ws.handler.soap.SOAPMessageContext) LogicalMessage(javax.xml.ws.LogicalMessage) HandlerTest(org.apache.handler_test.HandlerTest) Test(org.junit.Test)

Example 37 with SOAPEnvelope

use of javax.xml.soap.SOAPEnvelope in project coprhd-controller by CoprHD.

the class WinRMTarget method getSOAPFault.

protected SOAPFault getSOAPFault(String content) {
    try {
        Document doc = XmlUtils.parseXml(content);
        SOAPEnvelope e = (SOAPEnvelope) SOAPFactory.newInstance().createElement(doc.getDocumentElement());
        SOAPFault fault = e.getBody().getFault();
        return fault;
    } catch (Exception e) {
        return null;
    }
}
Also used : SOAPFault(javax.xml.soap.SOAPFault) SOAPEnvelope(javax.xml.soap.SOAPEnvelope) Document(org.w3c.dom.Document) HttpException(org.apache.http.HttpException) MalformedURLException(java.net.MalformedURLException)

Example 38 with SOAPEnvelope

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

the class XMLABaseComponent method discoverDS.

/**
 * retrieve data source properties
 *
 * @return Map of key/value strings
 * @see DataSourceBrowser
 */
public Map discoverDS() throws XMLAException {
    // Microsoft wants restrictions
    HashMap rHash = new HashMap();
    HashMap pHash = new HashMap();
    // $NON-NLS-1$ //$NON-NLS-2$
    pHash.put("Content", "Data");
    final Map resultMap = new HashMap();
    Rowhandler rh = new Rowhandler() {

        public void handleRow(SOAPElement eRow, SOAPEnvelope envelope) {
            /*
         * <row><DataSourceName>SAP_BW</DataSourceName> <DataSourceDescription>SAP BW Release 3.0A XML f. Analysis
         * Service</DataSourceDescription> <URL>http://155.56.49.46:83/SAP/BW/XML/SOAP/XMLA</URL>
         * <DataSourceInfo>default</DataSourceInfo> <ProviderName>SAP BW</ProviderName> <ProviderType>MDP</ProviderType>
         * <AuthenticationMode>Integrated</AuthenticationMode></row>
         */
            Iterator it = eRow.getChildElements();
            while (it.hasNext()) {
                Object o = it.next();
                if (!(o instanceof SOAPElement)) {
                    // bypass text nodes
                    continue;
                }
                SOAPElement e = (SOAPElement) o;
                String name = e.getElementName().getLocalName();
                String value = e.getValue();
                resultMap.put(name, value);
            }
        }
    };
    // $NON-NLS-1$
    discover("DISCOVER_DATASOURCES", url, rHash, pHash, rh);
    debug(Messages.getInstance().getString("XMLABaseComponent.DEBUG_0005_DISCOVER_DATASOURCE_FOUND") + resultMap.size());
    return resultMap;
}
Also used : HashMap(java.util.HashMap) SOAPElement(javax.xml.soap.SOAPElement) Iterator(java.util.Iterator) SOAPEnvelope(javax.xml.soap.SOAPEnvelope) HashMap(java.util.HashMap) Map(java.util.Map)

Example 39 with SOAPEnvelope

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

the class XMLABaseComponent method findDiscoverRoot.

/**
 * locate "root" in DisoverResponse
 */
private SOAPElement findDiscoverRoot(final SOAPMessage reply) throws SOAPException, XMLAException {
    SOAPPart sp = reply.getSOAPPart();
    SOAPEnvelope envelope = sp.getEnvelope();
    SOAPBody body = envelope.getBody();
    Name childName;
    SOAPElement eResponse = null;
    if (provider == 0) {
        // unknown provider - recognize by prefix of DiscoverResponse
        Iterator itBody = body.getChildElements();
        while (itBody.hasNext()) {
            Node n = (Node) itBody.next();
            if (!(n instanceof SOAPElement)) {
                continue;
            }
            Name name = ((SOAPElement) n).getElementName();
            if (name.getLocalName().equals("DiscoverResponse")) {
                // $NON-NLS-1$
                eResponse = (SOAPElement) n;
                provider = getProviderFromDiscoverResponse(envelope, eResponse);
                break;
            }
        }
        if (eResponse == null) {
            throw new XMLAException(// $NON-NLS-1$
            Messages.getInstance().getString("XMLABaseComponent.ERROR_0013_NO_DISCOVER_RESPONSE"));
        }
    } else {
        if ((provider == XMLABaseComponent.PROVIDER_MICROSOFT) || (provider == XMLABaseComponent.PROVIDER_ESSBASE)) {
            // Microsoft
            // or
            // Essbase
            childName = // $NON-NLS-1$ //$NON-NLS-2$
            envelope.createName("DiscoverResponse", "m", XMLABaseComponent.XMLA_URI);
        } else if ((provider == XMLABaseComponent.PROVIDER_SAP) || (provider == XMLABaseComponent.PROVIDER_MONDRIAN)) {
            // SAP
            // or
            // Mondrian
            childName = // $NON-NLS-1$ //$NON-NLS-2$
            envelope.createName("DiscoverResponse", "", XMLABaseComponent.XMLA_URI);
        } else {
            throw new IllegalArgumentException(Messages.getInstance().getString(// $NON-NLS-1$
            "XMLABaseComponent.ERROR_0014_NO_PROVIDER_SPEC"));
        }
        eResponse = selectSingleNode(body, childName);
        if (eResponse == null) {
            throw new XMLAException(Messages.getInstance().getString(// $NON-NLS-1$
            "XMLABaseComponent.ERROR_0015_NO_DISCOVER_RESPONSE_ELEMENT"));
        }
    }
    SOAPElement eReturn = getDiscoverReturn(envelope, eResponse);
    if (eReturn == null) {
        throw new XMLAException(Messages.getInstance().getString(// $NON-NLS-1$
        "XMLABaseComponent.ERROR_0016_NO_RESULT_RETURN_ELEMENT"));
    }
    SOAPElement eRoot = getDiscoverRoot(envelope, eReturn);
    if (eRoot == null) {
        throw new XMLAException(// $NON-NLS-1$
        Messages.getInstance().getString("XMLABaseComponent.ERROR_0017_NO_RESULT_ROOT_ELEMENT"));
    }
    return eRoot;
}
Also used : SOAPBody(javax.xml.soap.SOAPBody) Node(javax.xml.soap.Node) SOAPPart(javax.xml.soap.SOAPPart) SOAPElement(javax.xml.soap.SOAPElement) Iterator(java.util.Iterator) SOAPEnvelope(javax.xml.soap.SOAPEnvelope) Name(javax.xml.soap.Name)

Example 40 with SOAPEnvelope

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

the class XMLABaseComponent method findExecRoot.

/**
 * locate "root" in ExecuteResponse
 */
private SOAPElement findExecRoot(final SOAPMessage reply) throws SOAPException, XMLAException {
    SOAPPart sp = reply.getSOAPPart();
    SOAPEnvelope envelope = sp.getEnvelope();
    SOAPBody body = envelope.getBody();
    Name name;
    // $NON-NLS-1$//$NON-NLS-2$
    name = envelope.createName("ExecuteResponse", "m", XMLABaseComponent.XMLA_URI);
    SOAPElement eResponse = selectSingleNode(body, name);
    if (eResponse == null) {
        throw new XMLAException(Messages.getInstance().getString(// $NON-NLS-1$
        "XMLABaseComponent.ERROR_0011_NO_EXECUTE_RESPONSE_ELEMENT"));
    }
    // $NON-NLS-1$//$NON-NLS-2$
    name = envelope.createName("return", "m", XMLABaseComponent.XMLA_URI);
    SOAPElement eReturn = selectSingleNode(eResponse, name);
    // $NON-NLS-1$//$NON-NLS-2$
    name = envelope.createName("root", "", XMLABaseComponent.MDD_URI);
    SOAPElement eRoot = selectSingleNode(eReturn, name);
    if (eRoot == null) {
        throw new XMLAException(Messages.getInstance().getString("XMLABaseComponent.ERROR_0012_NO_RESPONSE_ROOT_ELEMENT"));
    }
    // $NON-NLS-1$
    return eRoot;
}
Also used : SOAPBody(javax.xml.soap.SOAPBody) SOAPPart(javax.xml.soap.SOAPPart) SOAPElement(javax.xml.soap.SOAPElement) SOAPEnvelope(javax.xml.soap.SOAPEnvelope) Name(javax.xml.soap.Name)

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