Search in sources :

Example 31 with SOAPEnvelope

use of javax.xml.soap.SOAPEnvelope in project OpenAM by OpenRock.

the class FSSOAPService method formSOAPError.

/**
     * Forms a SOAP Fault and puts it in the SOAP Message's Body.
     *
     * @param faultcode fault code to be set in SOAPMEssage
     * @param faultString fault string
     * @param detail the details of the fault condition
     * @return <code>SOAPMessage</code> containing the SOAP fault
     */
public SOAPMessage formSOAPError(String faultcode, String faultString, String detail) {
    SOAPMessage msg = null;
    SOAPEnvelope envelope = null;
    SOAPFault sf = null;
    SOAPBody body = null;
    SOAPElement se = null;
    try {
        msg = fac.createMessage();
        envelope = msg.getSOAPPart().getEnvelope();
        body = envelope.getBody();
        sf = body.addFault();
        Name qname = envelope.createName(faultcode, null, IFSConstants.SOAP_URI);
        sf.setFaultCode(qname);
        sf.setFaultString(FSUtils.bundle.getString(faultString));
        if ((detail != null) && !(detail.length() == 0)) {
            Detail det = sf.addDetail();
            se = (SOAPElement) det.addDetailEntry(envelope.createName("Problem"));
            se.addAttribute(envelope.createName("details"), FSUtils.bundle.getString(detail));
        }
    } catch (SOAPException e) {
        FSUtils.debug.error("FSSOAPService.formSOAPError:", e);
        return null;
    }
    return msg;
}
Also used : SOAPBody(javax.xml.soap.SOAPBody) SOAPException(javax.xml.soap.SOAPException) SOAPElement(javax.xml.soap.SOAPElement) SOAPFault(javax.xml.soap.SOAPFault) SOAPEnvelope(javax.xml.soap.SOAPEnvelope) SOAPMessage(javax.xml.soap.SOAPMessage) Detail(javax.xml.soap.Detail) Name(javax.xml.soap.Name)

Example 32 with SOAPEnvelope

use of javax.xml.soap.SOAPEnvelope in project OpenAM by OpenRock.

the class SAMLSOAPReceiver method FormSOAPError.

/**
     * This method forms  a SOAP Fault and puts it in the SOAP Message's
     * Body.
     */
private SOAPMessage FormSOAPError(HttpServletResponse resp, String faultCode, String faultString, String detail) {
    SOAPMessage msg = null;
    SOAPEnvelope envelope = null;
    SOAPFault sf = null;
    SOAPBody body = null;
    SOAPElement se = null;
    try {
        msg = msgFactory.createMessage();
        envelope = msg.getSOAPPart().getEnvelope();
        body = envelope.getBody();
        sf = body.addFault();
        Name qName = envelope.createName(faultCode, null, SOAPConstants.URI_NS_SOAP_ENVELOPE);
        sf.setFaultCode(qName);
        sf.setFaultString(SAMLUtils.bundle.getString(faultString));
        if ((detail != null) && !(detail.length() == 0)) {
            Detail det = sf.addDetail();
            se = (SOAPElement) det.addDetailEntry(envelope.createName("Problem"));
            se.addAttribute(envelope.createName("details"), SAMLUtils.bundle.getString(detail));
        }
    } catch (SOAPException e) {
        SAMLUtils.debug.error("FormSOAPError:", e);
        String[] data = { SAMLUtils.bundle.getString("soapFaultError") };
        LogUtils.error(java.util.logging.Level.INFO, LogUtils.SOAP_FAULT_ERROR, data);
        resp.setStatus(resp.SC_INTERNAL_SERVER_ERROR);
    }
    return msg;
}
Also used : SOAPBody(javax.xml.soap.SOAPBody) SOAPException(javax.xml.soap.SOAPException) SOAPElement(javax.xml.soap.SOAPElement) SOAPFault(javax.xml.soap.SOAPFault) SOAPEnvelope(javax.xml.soap.SOAPEnvelope) SOAPMessage(javax.xml.soap.SOAPMessage) Detail(javax.xml.soap.Detail) Name(javax.xml.soap.Name)

Example 33 with SOAPEnvelope

use of javax.xml.soap.SOAPEnvelope in project OpenAM by OpenRock.

the class SAMLSOAPReceiver method containsFault.

/**
     * containsFault is a utiltiy method to see if msg contains a soapfault.
     */
private boolean containsFault(SOAPMessage msg) {
    try {
        SOAPPart sp = msg.getSOAPPart();
        SOAPEnvelope se = sp.getEnvelope();
        SOAPBody sb = se.getBody();
        return (sb.hasFault());
    } catch (Exception e) {
        if (SAMLUtils.debug.messageEnabled()) {
            SAMLUtils.debug.message("Error in containFault!");
        }
        return false;
    }
}
Also used : SOAPBody(javax.xml.soap.SOAPBody) SOAPPart(javax.xml.soap.SOAPPart) SOAPEnvelope(javax.xml.soap.SOAPEnvelope) ServletException(javax.servlet.ServletException) SOAPException(javax.xml.soap.SOAPException) SAMLRequestVersionTooHighException(com.sun.identity.saml.common.SAMLRequestVersionTooHighException) SAMLRequesterException(com.sun.identity.saml.common.SAMLRequesterException) SAMLRequestVersionTooLowException(com.sun.identity.saml.common.SAMLRequestVersionTooLowException) SAMLException(com.sun.identity.saml.common.SAMLException)

Example 34 with SOAPEnvelope

use of javax.xml.soap.SOAPEnvelope in project tdi-studio-se by Talend.

the class SOAPUtil method invokeSOAP.

public void invokeSOAP(String version, String destination, String soapAction, String soapMessage) throws SOAPException, TransformerException, ParserConfigurationException, FileNotFoundException, UnsupportedEncodingException {
    MessageFactory messageFactory = null;
    if (version.equals(SOAP12)) {
        messageFactory = MessageFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL);
    } else {
        messageFactory = MessageFactory.newInstance();
    }
    SOAPMessage message = messageFactory.createMessage();
    MimeHeaders mimeHeaders = message.getMimeHeaders();
    mimeHeaders.setHeader("SOAPAction", soapAction);
    if (basicAuth) {
        addBasicAuthHeader(mimeHeaders, username, password);
    }
    // Create objects for the message parts
    SOAPPart soapPart = message.getSOAPPart();
    String encoding = getEncoding(soapMessage);
    ByteArrayInputStream stream = new ByteArrayInputStream(soapMessage.getBytes(encoding));
    StreamSource preppedMsgSrc = new StreamSource(stream);
    soapPart.setContent(preppedMsgSrc);
    // InputStream stream = new FileInputStream(new File("d://soap.txt"));
    // StreamSource preppedMsgSrc = new StreamSource(stream);
    // soapPart.setContent(preppedMsgSrc);
    message.saveChanges();
    // Send the message
    SOAPMessage reply = connection.call(message, destination);
    SOAPPart reSoapPart = reply.getSOAPPart();
    if (reSoapPart != null && reSoapPart instanceof SOAPPartImpl) {
        ((SOAPPartImpl) reSoapPart).setSourceCharsetEncoding(encoding);
    }
    SOAPEnvelope reEnvelope = reSoapPart.getEnvelope();
    SOAPHeader reHeader = reEnvelope.getHeader();
    if (reHeader != null) {
        setReHeaderMessage(Doc2StringWithoutDeclare(extractContentAsDocument(reHeader)));
    }
    SOAPBody reBody = reEnvelope.getBody();
    if (reBody.getFault() != null) {
        hasFault = true;
        setReFaultMessage(Doc2StringWithoutDeclare(extractContentAsDocument(reBody)));
        setReBodyMessage(null);
    } else {
        hasFault = false;
        if (reBody.getChildNodes().getLength() < 1) {
            setReBodyMessage(null);
        } else if (reBody.getChildNodes().getLength() == 1 && reBody.getChildNodes().item(0) instanceof javax.xml.soap.Text) {
            setReBodyMessage(null);
        } else {
            setReBodyMessage(Doc2StringWithoutDeclare(extractContentAsDocument(reBody)));
        }
        setReFaultMessage(null);
    }
}
Also used : SOAPPartImpl(com.sun.xml.messaging.saaj.soap.SOAPPartImpl) MessageFactory(javax.xml.soap.MessageFactory) StreamSource(javax.xml.transform.stream.StreamSource) SOAPEnvelope(javax.xml.soap.SOAPEnvelope) SOAPMessage(javax.xml.soap.SOAPMessage) MimeHeaders(javax.xml.soap.MimeHeaders) SOAPBody(javax.xml.soap.SOAPBody) ByteArrayInputStream(java.io.ByteArrayInputStream) SOAPPart(javax.xml.soap.SOAPPart) SOAPHeader(javax.xml.soap.SOAPHeader)

Example 35 with SOAPEnvelope

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

the class TestMustUnderstandHandler method handleMessage.

public boolean handleMessage(SOAPMessageContext ctx) {
    boolean continueProcessing = true;
    try {
        Object b = ctx.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
        boolean outbound = (Boolean) b;
        SOAPMessage msg = ctx.getMessage();
        if (isServerSideHandler()) {
            if (outbound) {
                QName qname = new QName("http://cxf.apache.org/mu", "MU");
                SOAPPart soapPart = msg.getSOAPPart();
                SOAPEnvelope envelope = soapPart.getEnvelope();
                SOAPHeader header = envelope.getHeader();
                if (header == null) {
                    header = envelope.addHeader();
                }
                SOAPHeaderElement headerElement = header.addHeaderElement(envelope.createName("MU", "ns1", qname.getNamespaceURI()));
                // QName soapMustUnderstand = new QName("http://schemas.xmlsoap.org/soap/envelope/",
                // "mustUnderstand");
                Name name = SOAPFactory.newInstance().createName("mustUnderstand", "soap", "http://schemas.xmlsoap.org/soap/envelope/");
                headerElement.addAttribute(name, "1");
            } else {
                getHandlerInfoList(ctx).add(getHandlerId());
            }
        }
    } catch (SOAPException e) {
        e.printStackTrace();
    }
    return continueProcessing;
}
Also used : SOAPHeaderElement(javax.xml.soap.SOAPHeaderElement) QName(javax.xml.namespace.QName) SOAPException(javax.xml.soap.SOAPException) SOAPPart(javax.xml.soap.SOAPPart) SOAPEnvelope(javax.xml.soap.SOAPEnvelope) SOAPMessage(javax.xml.soap.SOAPMessage) SOAPHeader(javax.xml.soap.SOAPHeader) Name(javax.xml.soap.Name) QName(javax.xml.namespace.QName)

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