Example usage for javax.xml.soap SOAPConstants URI_NS_SOAP_ENVELOPE

List of usage examples for javax.xml.soap SOAPConstants URI_NS_SOAP_ENVELOPE

Introduction

In this page you can find the example usage for javax.xml.soap SOAPConstants URI_NS_SOAP_ENVELOPE.

Prototype

String URI_NS_SOAP_ENVELOPE

To view the source code for javax.xml.soap SOAPConstants URI_NS_SOAP_ENVELOPE.

Click Source Link

Document

The namespace identifier for the SOAP 1.1 envelope, All SOAPElements in this namespace are defined by the SOAP 1.1 specification.

Usage

From source file:de.drv.dsrv.spoc.web.webservice.spring.SpocMessageDispatcherServlet.java

private void createExtraErrorAndWriteResponse(final HttpServletResponse httpServletResponse,
        final String errorText)
        throws SOAPException, JAXBException, DatatypeConfigurationException, IOException {

    final MessageFactory factory = MessageFactory.newInstance();
    final SOAPMessage message = factory.createMessage();
    final SOAPBody body = message.getSOAPBody();

    final SOAPFault fault = body.addFault();
    final QName faultName = new QName(SOAPConstants.URI_NS_SOAP_ENVELOPE, FaultCode.CLIENT.toString());
    fault.setFaultCode(faultName);//  w w w.  j a  v  a2s .c  o  m
    fault.setFaultString(this.soapFaultString);

    final Detail detail = fault.addDetail();

    final ExtraJaxbMarshaller extraJaxbMarshaller = new ExtraJaxbMarshaller();
    final ExtraErrorReasonType reason = ExtraErrorReasonType.INVALID_REQUEST;
    final ExtraErrorType extraError = ExtraHelper.generateError(reason, this.extraErrorCode, errorText);
    extraJaxbMarshaller.marshalExtraError(extraError, detail);

    // Schreibt die SOAPMessage in einen String.
    final ByteArrayOutputStream out = new ByteArrayOutputStream();
    message.writeTo(out);
    // Das Encoding, in dem sich die Message rausschreibt, kann man als
    // Property abfragen.
    final Object encodingProperty = message.getProperty(SOAPMessage.CHARACTER_SET_ENCODING);
    String soapMessageEncoding = "UTF-8";
    if (encodingProperty != null) {
        soapMessageEncoding = encodingProperty.toString();
    }
    final String errorXml = out.toString(soapMessageEncoding);

    httpServletResponse.setStatus(HttpServletResponse.SC_OK);
    httpServletResponse.setContentType("text/xml");
    httpServletResponse.getWriter().write(errorXml);
    httpServletResponse.getWriter().flush();
    httpServletResponse.getWriter().close();
}

From source file:de.drv.dsrv.spoc.web.webservice.jax.ExtraSchemaValidationHandler.java

private boolean handleException(final SOAPBody soapBody, final String errorText,
        final ExtraErrorReasonType reason) {

    try {/*from  w ww. jav a  2  s .c o m*/
        // Bisherigen Inhalt des SOAP-Bodys entfernen
        soapBody.removeContents();

        // SOAP-Fault erzeugen
        final SOAPFault fault = soapBody.addFault();
        fault.setFaultString(this.soapFaultString);
        fault.setFaultCode(new QName(SOAPConstants.URI_NS_SOAP_ENVELOPE, SOAP_FAULT_CODE));

        final ExtraJaxbMarshaller extraJaxbMarshaller = new ExtraJaxbMarshaller();
        final ExtraErrorType extraError = ExtraHelper.generateError(reason, this.extraErrorCode, errorText);
        extraJaxbMarshaller.marshalExtraError(extraError, fault.addDetail());

        return false;
    } catch (final Exception e) {
        LOG.error("Fehler bei Exception-Behandlung.", e);
        throw new WebServiceException(resourceBundle.getString(Messages.ERROR_NON_EXTRA_TEXT));
    }
}

From source file:org.jasig.portal.security.provider.saml.SAMLDelegatedAuthenticationService.java

private Document createSOAPFaultDocument(String faultString) throws SOAPException {
    MessageFactory factory = MessageFactory.newInstance();
    SOAPMessage message = factory.createMessage();
    SOAPPart sp = message.getSOAPPart();
    SOAPEnvelope se = sp.getEnvelope();
    se.setPrefix(SOAP_PREFIX);/*from  w ww  .ja va  2 s .  c  o  m*/
    se.getHeader().detachNode();
    se.addHeader();
    se.getBody().detachNode();
    SOAPBody body = se.addBody();
    SOAPFault fault = body.addFault();
    Name faultCode = se.createName("Client", null, SOAPConstants.URI_NS_SOAP_ENVELOPE);
    fault.setFaultCode(faultCode);
    fault.setFaultString(faultString);
    return se.getOwnerDocument();
}

From source file:org.jbpm.bpel.integration.soap.SoapUtilTest.java

public void testRemoveAttributes_soap() throws Exception {
    String xml = "<soap:Envelope xmlns:soap='" + SOAPConstants.URI_NS_SOAP_ENVELOPE + "'>"
            + " <soap:Body xmlns:fish='urn:example:fish'>"
            + "  <lunch time='1200' produce:lettuce='0.1lb' fish:fillet='0.25lb' "
            + "   xmlns:produce='urn:example:produce' />" + " </soap:Body>" + "</soap:Envelope>";
    ByteArrayInputStream sourceStream = new ByteArrayInputStream(xml.getBytes());
    SOAPMessage soapMessage = MessageFactory.newInstance().createMessage(null, sourceStream);
    SOAPElement element = SoapUtil.getElement(soapMessage.getSOAPBody(), "lunch");
    // remove the attributes
    SoapUtil.removeAttributes(element);//  w  w  w  .ja  v a  2 s .  c o m
    // verify remotion with the dom & saaj apis
    assertFalse(element.hasAttribute("time"));
    assertFalse(element.hasAttributeNS("urn:example:produce", "lettuce"));
    assertFalse(element.hasAttributeNS("urn:example:fish", "fillet"));
    // namespaces should still be there
    // prefixed declaration
    assertEquals("produce", SoapUtil.getPrefix("urn:example:produce", element));
    // parent prefixed declaration
    assertEquals("fish", SoapUtil.getPrefix("urn:example:fish", element));
}

From source file:org.jbpm.bpel.integration.soap.SoapUtilTest.java

public void testRemoveChildNodes_soap() throws Exception {
    String xml = "<soap:Envelope xmlns:soap='" + SOAPConstants.URI_NS_SOAP_ENVELOPE + "'>"
            + " <soap:Body xmlns:fish='urn:example:fish'>" + "  <meal:lunch xmlns:produce='urn:example:produce'"
            + "   xmlns:meal='urn:example:meal'>" + "   <time>1200</time>"
            + "   <produce:lettuce>0.1lb</produce:lettuce>"
            + "   <fish:fillet xmlns:fish='urn:example:fish'>0.25lb</fish:fillet>" + "  </meal:lunch>"
            + " </soap:Body>" + "</soap:Envelope>";
    ByteArrayInputStream sourceStream = new ByteArrayInputStream(xml.getBytes());
    SOAPMessage soapMessage = MessageFactory.newInstance().createMessage(null, sourceStream);
    SOAPElement element = SoapUtil.getElement(soapMessage.getSOAPBody(), "urn:example:meal", "lunch");
    // remove the child nodes
    element.removeContents();//  w  w  w.  j  a  v a2 s .  co m
    // verify remotion
    assertFalse(element.getChildElements().hasNext());
}

From source file:org.jbpm.bpel.integration.soap.SoapUtilTest.java

public void testRemoveNamespaces_soap() throws Exception {
    String xml = "<soap:Envelope xmlns:soap='" + SOAPConstants.URI_NS_SOAP_ENVELOPE + "'>"
            + " <soap:Body xmlns:fish='urn:example:fish'>"
            + "  <lunch time='1200' produce:lettuce='0.1lb' fish:fillet='0.25lb' "
            + "   xmlns:produce='urn:example:produce' />" + " </soap:Body>" + "</soap:Envelope>";
    ByteArrayInputStream sourceStream = new ByteArrayInputStream(xml.getBytes());
    SOAPMessage soapMessage = MessageFactory.newInstance().createMessage(null, sourceStream);
    SOAPElement element = SoapUtil.getElement(soapMessage.getSOAPBody(), "lunch");
    // remove namespaces
    SoapUtil.removeNamespaces(element);//from w w w .  jav a  2  s  . c  om
    // verify remotion
    assertFalse(element.getNamespacePrefixes().hasNext());
    // attributes should still be there
    // qualified attributes
    assertEquals("0.1lb", element.getAttributeNS("urn:example:produce", "lettuce"));
    assertEquals("0.25lb", element.getAttributeNS("urn:example:fish", "fillet"));
    // local attribute
    assertEquals("1200", element.getAttribute("time"));
}

From source file:org.jbpm.bpel.integration.soap.SoapUtilTest.java

public void testCopyVisibleNamespaces_soapDom_targetMatch() throws Exception {
    String xml = "<part xmlns:produce='urn:example:produce'>"
            + " <lunch produce:lettuce='0.1lb' fish:fillet='0.25lb' "
            + "  xmlns:fish='urn:example:fish' xmlns='urn:example:meal'/>" + "</part>";
    Element source = XmlUtil.getElement(XmlUtil.parseText(xml), "urn:example:meal", "lunch");

    String targetXml = "<soap:Envelope xmlns:soap='" + SOAPConstants.URI_NS_SOAP_ENVELOPE + "'>"
            + " <soap:Body>"
            + "  <other:Operation xmlns:produce='urn:example:produce' xmlns:meal='urn:example:meal'"
            + "   xmlns:other='urn:example:other'>" + "   <lunch />" + "  </other:Operation>" + " </soap:Body>"
            + "</soap:Envelope>";
    SOAPMessage soapMessage = parseSoap(targetXml);
    SOAPElement operation = SoapUtil.getElement(soapMessage.getSOAPBody(), "urn:example:other", "Operation");
    SOAPElement target = SoapUtil.getElement(operation, "lunch");

    // in the WS4EE stack, target contains the *visible* namespace after parsing
    target.removeNamespaceDeclaration("produce");
    target.removeNamespaceDeclaration("meal");

    // perform the copy
    SoapUtil.copyVisibleNamespaces(target, source);
    List prefixes = IteratorUtils.toList(target.getNamespacePrefixes());

    // prefixed declaration
    assertTrue(prefixes.contains("fish"));
    assertEquals("urn:example:fish", target.getNamespaceURI("fish"));
    // parent prefixed declaration
    assertFalse(prefixes.contains("produce"));
    assertEquals("urn:example:produce", target.getNamespaceURI("produce"));
    // default declaration (reassigned)
    assertFalse(prefixes.contains("meal"));
    assertEquals("urn:example:meal", target.getNamespaceURI("meal"));
}

From source file:org.jbpm.bpel.integration.soap.SoapUtilTest.java

public void testCopyAttributes_domSoap() throws Exception {
    String xml = "<soap:Envelope xmlns:soap='" + SOAPConstants.URI_NS_SOAP_ENVELOPE + "'>"
            + " <soap:Body xmlns:fish='urn:example:fish'>"
            + "  <lunch time='1200' produce:lettuce='0.1lb' fish:fillet='0.25lb' "
            + "   xmlns:produce='urn:example:produce' />" + " </soap:Body>" + "</soap:Envelope>";
    SOAPMessage soapMessage = parseSoap(xml);
    SOAPElement source = SoapUtil.getElement(soapMessage.getSOAPBody(), "lunch");
    Element target = XmlUtil.createElement("detail");
    // perform the copy
    SoapUtil.copyAttributes(target, source);
    // qualified attributes
    assertEquals("0.1lb", target.getAttributeNS("urn:example:produce", "lettuce"));
    assertEquals("0.25lb", target.getAttributeNS("urn:example:fish", "fillet"));
    // local attribute
    assertEquals("1200", target.getAttribute("time"));
}

From source file:org.jbpm.bpel.integration.soap.SoapUtilTest.java

public void testCopyNamespaces_domSoap() throws Exception {
    String xml = "<soap:Envelope xmlns:soap='" + SOAPConstants.URI_NS_SOAP_ENVELOPE + "'>"
            + " <soap:Body xmlns:produce='urn:example:produce'>"
            + "  <meal:lunch produce:lettuce='0.1lb' fish:fillet='0.25lb' "
            + "   xmlns:fish='urn:example:fish' xmlns:meal='urn:example:meal'/>" + " </soap:Body>"
            + "</soap:Envelope>";
    SOAPMessage soapMessage = parseSoap(xml);
    SOAPElement source = SoapUtil.getElement(soapMessage.getSOAPBody(), "urn:example:meal", "lunch");
    Element target = XmlUtil.createElement("detail");

    // perform the copy
    SoapUtil.copyNamespaces(target, source);

    // prefixed declaration
    assertEquals("urn:example:fish", XmlUtil.getNamespaceURI("fish", target));
    assertEquals("urn:example:meal", XmlUtil.getNamespaceURI("meal", target));
    // parent prefixed declaration
    assertNull(XmlUtil.getNamespaceURI("produce", target));
    assertNull(XmlUtil.getNamespaceURI("soap", target));
}

From source file:org.jbpm.bpel.integration.soap.SoapUtilTest.java

public void testCopyVisibleNamespaces_domSoap() throws Exception {
    String xml = "<soap:Envelope xmlns:soap='" + SOAPConstants.URI_NS_SOAP_ENVELOPE + "'>"
            + " <soap:Body xmlns:produce='urn:example:produce'>"
            + "  <meal:lunch produce:lettuce='0.1lb' fish:fillet='0.25lb' xmlns=''"
            + "   xmlns:fish='urn:example:fish' xmlns:meal='urn:example:meal'/>" + " </soap:Body>"
            + "</soap:Envelope>";
    SOAPMessage soapMessage = parseSoap(xml);
    SOAPElement source = SoapUtil.getElement(soapMessage.getSOAPBody(), "urn:example:meal", "lunch");
    Element target = XmlUtil.createElement("detail");

    // perform the copy
    SoapUtil.copyVisibleNamespaces(target, source);

    // prefixed declaration
    assertEquals("urn:example:fish", XmlUtil.getNamespaceURI("fish", target));
    assertEquals("urn:example:meal", XmlUtil.getNamespaceURI("meal", target));
    // parent prefixed declaration
    assertEquals("urn:example:produce", XmlUtil.getNamespaceURI("produce", target));
    assertEquals(SOAPConstants.URI_NS_SOAP_ENVELOPE, XmlUtil.getNamespaceURI("soap", target));
}