Search in sources :

Example 11 with SOAPEnvelope

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

the class NBProviderClientServerTest method encodeRequest.

private SOAPMessage encodeRequest(MessageFactory factory, String value) throws SOAPException {
    SOAPMessage request = factory.createMessage();
    SOAPEnvelope envelope = request.getSOAPPart().getEnvelope();
    request.setProperty("soapaction", "");
    if (value != null) {
        request.getSOAPBody().addBodyElement(envelope.createName(value, "ns1", sayHi.getNamespaceURI()));
    }
    return request;
}
Also used : SOAPEnvelope(javax.xml.soap.SOAPEnvelope) SOAPMessage(javax.xml.soap.SOAPMessage)

Example 12 with SOAPEnvelope

use of javax.xml.soap.SOAPEnvelope in project Payara by payara.

the class BaseAuthConfig method getName.

private static Name getName(SOAPMessage message) {
    Name rvalue = null;
    SOAPPart soap = message.getSOAPPart();
    if (soap != null) {
        try {
            SOAPEnvelope envelope = soap.getEnvelope();
            if (envelope != null) {
                SOAPBody body = envelope.getBody();
                if (body != null) {
                    Iterator it = body.getChildElements();
                    while (it.hasNext()) {
                        Object o = it.next();
                        if (o instanceof SOAPElement) {
                            rvalue = ((SOAPElement) o).getElementName();
                            break;
                        }
                    }
                }
            }
        } catch (SOAPException se) {
            if (logger.isLoggable(Level.FINE)) {
                logger.log(Level.FINE, "WSS: Unable to get SOAP envelope", se);
            }
        }
    }
    return rvalue;
}
Also used : SOAPBody(javax.xml.soap.SOAPBody) SOAPException(javax.xml.soap.SOAPException) SOAPPart(javax.xml.soap.SOAPPart) Iterator(java.util.Iterator) SOAPElement(javax.xml.soap.SOAPElement) SOAPEnvelope(javax.xml.soap.SOAPEnvelope) Name(javax.xml.soap.Name) QName(javax.xml.namespace.QName)

Example 13 with SOAPEnvelope

use of javax.xml.soap.SOAPEnvelope in project jaffa-framework by jaffa-projects.

the class WebServiceInvoker method createSOAPMessage.

/**
 * Generate SOAPMessage based on the input arguments.
 * <p>
 * For example:
 *   <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:j="http://product1.mirotechnologies.com/material/core/StockBalanceFinder">
 *     <SOAP-ENV:Header/>
 *     <SOAP-ENV:Body>
 *       <j:performInquiry>
 *         <arg0>
 *           <part><operator>Equals</operator><values>P1000</values></part>
 *         </arg0>
 *       </j:performInquiry>
 *     </SOAP-ENV:Body>
 *   </SOAP-ENV:Envelope>
 * @param arguments the arguments for the WebService.
 * @return a SOAPMessage.
 * @throws SOAPException if any SOAP error occurs.
 * @throws JAXBException if any XML (un)marshalling error occurs.
 */
protected SOAPMessage createSOAPMessage(Object... arguments) throws SOAPException, JAXBException {
    MessageFactory messageFactory = MessageFactory.newInstance();
    SOAPMessage message = messageFactory.createMessage();
    SOAPPart messagePart = message.getSOAPPart();
    SOAPEnvelope envelope = messagePart.getEnvelope();
    String tns = this.obtainTargetNamespace();
    if (tns != null) {
        envelope.addNamespaceDeclaration(CUSTOM_PREFIX, tns);
    }
    SOAPBody body = message.getSOAPBody();
    SOAPElement operationElement = tns != null ? body.addBodyElement(envelope.createQName(getOperationName(), CUSTOM_PREFIX)) : body.addBodyElement(envelope.createName(getOperationName()));
    // Add authentication
    addAuthorization(message);
    // An arg{i} node will be created for each argument
    if (arguments != null) {
        Annotation[][] parameterAnnotations = null;
        for (Method m : getWebServiceClass().getMethods()) {
            if (m.getName().equals(getOperationName()) && m.getAnnotation(WebMethod.class) != null) {
                parameterAnnotations = m.getParameterAnnotations();
            }
        }
        for (int i = 0; i < arguments.length; i++) {
            Object argument = arguments[i];
            Class argumentClass = argument.getClass();
            String webParamName = null;
            if (parameterAnnotations != null && parameterAnnotations.length > 0) {
                for (Annotation[] annotations : parameterAnnotations) {
                    for (Annotation annotation : annotations) {
                        if (annotation instanceof WebParam) {
                            WebParam webParam = (WebParam) annotation;
                            webParamName = webParam.name();
                            if (log.isDebugEnabled()) {
                                log.debug("webParamName :" + webParamName);
                            }
                        }
                    }
                }
            }
            if (Collection.class.isAssignableFrom(argumentClass)) {
                JAXBContext jc = null;
                Marshaller marshaller = null;
                List list = (List) argument;
                for (Object arrayElement : list) {
                    if (jc == null) {
                        jc = JAXBHelper.obtainJAXBContext(arrayElement.getClass());
                        marshaller = jc.createMarshaller();
                    }
                    if (webParamName != null) {
                        marshaller.marshal(new JAXBElement(new QName(webParamName), arrayElement.getClass(), arrayElement), operationElement);
                    } else {
                        marshaller.marshal(new JAXBElement(new QName("arg0"), arrayElement.getClass(), arrayElement), operationElement);
                    }
                }
            } else if (argumentClass.isArray()) {
                argumentClass = argumentClass.getComponentType();
                JAXBContext jc = JAXBHelper.obtainJAXBContext(argumentClass);
                Marshaller marshaller = jc.createMarshaller();
                for (int j = 0, len = Array.getLength(argument); j < len; j++) {
                    Object arrayElement = Array.get(argument, j);
                    if (webParamName != null) {
                        marshaller.marshal(new JAXBElement(new QName(webParamName), argumentClass, arrayElement), operationElement);
                    } else {
                        marshaller.marshal(new JAXBElement(new QName("arg0"), argumentClass, arrayElement), operationElement);
                    }
                }
            } else {
                JAXBContext jc = JAXBHelper.obtainJAXBContext(argumentClass);
                Marshaller marshaller = jc.createMarshaller();
                if (webParamName != null) {
                    marshaller.marshal(new JAXBElement(new QName(webParamName), argumentClass, argument), operationElement);
                } else {
                    marshaller.marshal(new JAXBElement(new QName("arg0"), argumentClass, argument), operationElement);
                }
            }
        }
    }
    // Save all changes to the Message
    message.saveChanges();
    if (log.isDebugEnabled()) {
        log.debug("Created SOAPMessage: " + message);
        try {
            ByteArrayOutputStream os = new ByteArrayOutputStream();
            message.writeTo(os);
            log.debug("Contents of SOAPMessage: " + os.toString());
        } catch (Exception e) {
        // do nothing
        }
    }
    return message;
}
Also used : Marshaller(javax.xml.bind.Marshaller) MessageFactory(javax.xml.soap.MessageFactory) QName(javax.xml.namespace.QName) JAXBContext(javax.xml.bind.JAXBContext) SOAPEnvelope(javax.xml.soap.SOAPEnvelope) Method(java.lang.reflect.Method) WebMethod(javax.jws.WebMethod) JAXBElement(javax.xml.bind.JAXBElement) ByteArrayOutputStream(java.io.ByteArrayOutputStream) SOAPMessage(javax.xml.soap.SOAPMessage) Annotation(java.lang.annotation.Annotation) SOAPException(javax.xml.soap.SOAPException) JAXBException(javax.xml.bind.JAXBException) SOAPFaultException(javax.xml.ws.soap.SOAPFaultException) SOAPBody(javax.xml.soap.SOAPBody) WebParam(javax.jws.WebParam) SOAPPart(javax.xml.soap.SOAPPart) SOAPElement(javax.xml.soap.SOAPElement) NodeList(org.w3c.dom.NodeList) List(java.util.List)

Example 14 with SOAPEnvelope

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

the class XMLABaseComponent method discover.

/**
 * discover
 *
 * @param request
 * @param discoverUrl
 * @param restrictions
 * @param properties
 * @param rh
 * @throws XMLAException
 */
private void discover(final String request, final URL discoverUrl, final Map restrictions, final Map properties, final Rowhandler rh) throws XMLAException {
    try {
        SOAPConnection connection = scf.createConnection();
        SOAPMessage msg = mf.createMessage();
        MimeHeaders mh = msg.getMimeHeaders();
        // $NON-NLS-1$ //$NON-NLS-2$
        mh.setHeader("SOAPAction", "\"urn:schemas-microsoft-com:xml-analysis:Discover\"");
        SOAPPart soapPart = msg.getSOAPPart();
        SOAPEnvelope envelope = soapPart.getEnvelope();
        // $NON-NLS-1$//$NON-NLS-2$
        envelope.addNamespaceDeclaration("xsi", "http://www.w3.org/2001/XMLSchema-instance");
        // $NON-NLS-1$ //$NON-NLS-2$
        envelope.addNamespaceDeclaration("xsd", "http://www.w3.org/2001/XMLSchema");
        SOAPBody body = envelope.getBody();
        // $NON-NLS-1$//$NON-NLS-2$
        Name nDiscover = envelope.createName("Discover", "", XMLABaseComponent.XMLA_URI);
        SOAPElement eDiscover = body.addChildElement(nDiscover);
        eDiscover.setEncodingStyle(XMLABaseComponent.ENCODING_STYLE);
        // $NON-NLS-1$//$NON-NLS-2$
        Name nPara = envelope.createName("RequestType", "", XMLABaseComponent.XMLA_URI);
        SOAPElement eRequestType = eDiscover.addChildElement(nPara);
        eRequestType.addTextNode(request);
        // add the parameters
        if (restrictions != null) {
            addParameterList(envelope, eDiscover, "Restrictions", "RestrictionList", // $NON-NLS-1$ //$NON-NLS-2$
            restrictions);
        }
        // $NON-NLS-1$//$NON-NLS-2$
        addParameterList(envelope, eDiscover, "Properties", "PropertyList", properties);
        msg.saveChanges();
        debug(// $NON-NLS-1$
        Messages.getInstance().getString("XMLABaseComponent.DEBUG_0006_DISCOVER_REQUEST") + request);
        logSoapMsg(msg);
        // run the call
        SOAPMessage reply = connection.call(msg, discoverUrl);
        debug(// $NON-NLS-1$
        Messages.getInstance().getString("XMLABaseComponent.DEBUG_0007_DISCOVER_RESPONSE") + request);
        logSoapMsg(reply);
        errorCheck(reply);
        SOAPElement eRoot = findDiscoverRoot(reply);
        // $NON-NLS-1$ //$NON-NLS-2$
        Name nRow = envelope.createName("row", "", XMLABaseComponent.ROWS_URI);
        Iterator itRow = eRoot.getChildElements(nRow);
        while (itRow.hasNext()) {
            // RowLoop
            SOAPElement eRow = (SOAPElement) itRow.next();
            rh.handleRow(eRow, envelope);
        }
        // RowLoop
        connection.close();
    } catch (UnsupportedOperationException e) {
        throw new XMLAException(e);
    } catch (SOAPException e) {
        throw new XMLAException(e);
    }
}
Also used : 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) SOAPConnection(javax.xml.soap.SOAPConnection) SOAPEnvelope(javax.xml.soap.SOAPEnvelope) SOAPMessage(javax.xml.soap.SOAPMessage) Name(javax.xml.soap.Name)

Example 15 with SOAPEnvelope

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

the class XMLABaseComponent method soapFault.

/**
 * check SOAP reply for Error, return fault Code
 *
 * @param reply   the message to check
 * @param aReturn ArrayList containing faultcode,faultstring,faultactor
 */
private boolean soapFault(final SOAPMessage reply, final String[] faults) throws SOAPException {
    SOAPPart sp = reply.getSOAPPart();
    SOAPEnvelope envelope = sp.getEnvelope();
    SOAPBody body = envelope.getBody();
    if (!body.hasFault()) {
        return false;
    }
    SOAPFault fault = body.getFault();
    faults[0] = fault.getFaultCode();
    faults[1] = fault.getFaultString();
    faults[2] = fault.getFaultActor();
    // probably not neccessary with Microsoft;
    Detail detail = fault.getDetail();
    if (detail == null) {
        return true;
    }
    // $NON-NLS-1$
    String detailMsg = "";
    Iterator it = detail.getDetailEntries();
    for (; it.hasNext(); ) {
        DetailEntry det = (DetailEntry) it.next();
        Iterator ita = det.getAllAttributes();
        for (boolean cont = false; ita.hasNext(); cont = true) {
            Name name = (Name) ita.next();
            if (cont) {
                // $NON-NLS-1$
                detailMsg += "; ";
            }
            detailMsg += name.getLocalName();
            // $NON-NLS-1$
            detailMsg += " = ";
            detailMsg += det.getAttributeValue(name);
        }
    }
    faults[3] = detailMsg;
    return true;
}
Also used : SOAPBody(javax.xml.soap.SOAPBody) DetailEntry(javax.xml.soap.DetailEntry) SOAPPart(javax.xml.soap.SOAPPart) Iterator(java.util.Iterator) SOAPFault(javax.xml.soap.SOAPFault) SOAPEnvelope(javax.xml.soap.SOAPEnvelope) Detail(javax.xml.soap.Detail) 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