Example usage for javax.xml.ws.handler.soap SOAPMessageContext getMessage

List of usage examples for javax.xml.ws.handler.soap SOAPMessageContext getMessage

Introduction

In this page you can find the example usage for javax.xml.ws.handler.soap SOAPMessageContext getMessage.

Prototype

public SOAPMessage getMessage();

Source Link

Document

Gets the SOAPMessage from this message context.

Usage

From source file:be.fedict.hsm.ws.impl.LoggingSOAPHandler.java

@Override
public boolean handleFault(SOAPMessageContext context) {
    Boolean outboundProperty = (Boolean) context.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
    LOG.debug("outbound message: " + outboundProperty);
    SOAPMessage soapMessage = context.getMessage();
    ByteArrayOutputStream output = new ByteArrayOutputStream();
    try {/*w  w  w.j av a 2  s  .  c  om*/
        soapMessage.writeTo(output);
    } catch (Exception e) {
        LOG.error("SOAP error: " + e.getMessage());
    }
    LOG.debug("SOAP fault: " + output.toString());
    return true;
}

From source file:be.fedict.trust.xkms2.LoggingSoapHandler.java

public boolean handleFault(SOAPMessageContext context) {
    Boolean outboundProperty = (Boolean) context.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
    LOG.debug("outbound message: " + outboundProperty);
    SOAPMessage soapMessage = context.getMessage();
    ByteArrayOutputStream output = new ByteArrayOutputStream();
    try {//ww  w .  java 2  s.c  o m
        soapMessage.writeTo(output);
    } catch (Exception e) {
        LOG.error("SOAP error: " + e.getMessage());
    }
    LOG.debug("SOAP message: " + output.toString());
    return true;
}

From source file:be.e_contract.mycarenet.async.SecuritySOAPHandler.java

private void handleOutboundMessage(SOAPMessageContext context) throws SOAPException, WSSecurityException {
    LOG.debug("adding WS-Security header");
    SOAPMessage soapMessage = context.getMessage();
    SOAPPart soapPart = soapMessage.getSOAPPart();

    WSSecHeader wsSecHeader = new WSSecHeader();
    wsSecHeader.insertSecurityHeader(soapPart);

    WSSecUsernameToken usernameToken = new WSSecUsernameToken();
    usernameToken.setUserInfo(this.packageLicenseKey.getUsername(), this.packageLicenseKey.getPassword());
    usernameToken.setPasswordType(WSConstants.PASSWORD_TEXT);
    usernameToken.prepare(soapPart);//  w  ww.ja  va 2s.  c o m
    usernameToken.prependToHeader(wsSecHeader);

    WSSecTimestamp wsSecTimeStamp = new WSSecTimestamp();
    wsSecTimeStamp.build(soapPart, wsSecHeader);

    WSSecurityCrypto crypto = new WSSecurityCrypto(this.sessionKey);
    WSSConfig wssConfig = new WSSConfig();
    wssConfig.setWsiBSPCompliant(false);
    WSSecSignature sign = new WSSecSignature(wssConfig);
    sign.setKeyIdentifierType(WSConstants.BST_DIRECT_REFERENCE);
    sign.prepare(soapPart, crypto, wsSecHeader);
    sign.appendBSTElementToHeader(wsSecHeader);
    Vector<WSEncryptionPart> signParts = new Vector<WSEncryptionPart>();
    signParts.add(new WSEncryptionPart(wsSecTimeStamp.getId()));
    signParts.add(new WSEncryptionPart(usernameToken.getId()));
    SOAPConstants soapConstants = WSSecurityUtil.getSOAPConstants(soapPart.getDocumentElement());
    signParts.add(new WSEncryptionPart(soapConstants.getBodyQName().getLocalPart(),
            soapConstants.getEnvelopeURI(), "Content"));
    sign.addReferencesToSign(signParts, wsSecHeader);
    List<Reference> referenceList = sign.addReferencesToSign(signParts, wsSecHeader);
    sign.computeSignature(referenceList, false, null);
}

From source file:be.e_contract.dssp.client.LoggingSOAPHandler.java

private void logMessage(SOAPMessageContext context) {
    Boolean outboundProperty = (Boolean) context.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
    LOG.debug("outbound message: " + outboundProperty);
    SOAPMessage soapMessage = context.getMessage();
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    try {//from w w  w  .ja  v  a 2  s.co  m
        soapMessage.writeTo(outputStream);
    } catch (Exception e) {
        LOG.error("SOAP error: " + e.getMessage());
    }
    String message = outputStream.toString();
    LOG.debug("SOAP message: " + message);
    if (false == outboundProperty) {
        Map<String, DataHandler> inboundMessageAttachments = (Map<String, DataHandler>) context
                .get(MessageContext.INBOUND_MESSAGE_ATTACHMENTS);
        Set<String> attachmentContentIds = inboundMessageAttachments.keySet();
        LOG.debug("attachment content ids: " + attachmentContentIds);
    }
}

From source file:be.e_contract.mycarenet.common.LoggingHandler.java

private void logMessage(SOAPMessageContext context) {
    Boolean outboundProperty = (Boolean) context.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
    LOG.debug("outbound message: " + outboundProperty);
    SOAPMessage soapMessage = context.getMessage();
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    try {/* ww w.java 2s.co  m*/
        soapMessage.writeTo(outputStream);
    } catch (Exception e) {
        LOG.error("SOAP error: " + e.getMessage());
    }
    String message = outputStream.toString();
    LOG.debug("SOAP message: " + message);
    if (false == outboundProperty) {
        @SuppressWarnings("unchecked")
        Map<String, DataHandler> inboundMessageAttachments = (Map<String, DataHandler>) context
                .get(MessageContext.INBOUND_MESSAGE_ATTACHMENTS);
        Set<String> attachmentContentIds = inboundMessageAttachments.keySet();
        LOG.debug("attachment content ids: " + attachmentContentIds);
    }
}

From source file:be.fedict.eid.dss.ws.LoggingSoapHandler.java

public boolean handleMessage(SOAPMessageContext context) {
    LOG.debug("handle message");
    Boolean outboundProperty = (Boolean) context.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
    LOG.debug("outbound message: " + outboundProperty);
    SOAPMessage soapMessage = context.getMessage();
    ByteArrayOutputStream output = new ByteArrayOutputStream();
    try {/*  w  w  w  .  j a va  2s  .co m*/
        soapMessage.writeTo(output);
    } catch (Exception e) {
        LOG.error("SOAP error: " + e.getMessage());
    }
    LOG.debug("SOAP message: " + output.toString());
    return true;
}

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

private SOAPBody getSoapBody(final SOAPMessageContext context) {
    SOAPBody soapBody = null;/* w w  w  .j a v a2s  .  c om*/
    try {
        final SOAPMessage soapMessage = context.getMessage();
        soapBody = soapMessage.getSOAPBody();
    } catch (final Exception e) {
        LOG.error("Exception beim Auslesen des SOAP-Bodys.", e);
    }
    return soapBody;
}

From source file:be.agiv.security.handler.WSTrustHandler.java

private void handleOutboundMessage(SOAPMessageContext context) throws SOAPException {
    if (null == this.secondaryParametersNodeList) {
        return;//from   w  w  w.ja  v  a2  s  .  c om
    }
    SOAPMessage soapMessage = context.getMessage();
    SOAPPart soapPart = soapMessage.getSOAPPart();
    SOAPBody soapBody = soapMessage.getSOAPBody();
    NodeList nodeList = soapBody.getElementsByTagNameNS(WSConstants.WSTRUST_NAMESPACE, "RequestSecurityToken");
    if (0 == nodeList.getLength()) {
        return;
    }
    SOAPElement requestSecurityTokenElement = (SOAPElement) nodeList.item(0);
    String prefix = requestSecurityTokenElement.getPrefix();
    SOAPElement secondaryParametersElement = requestSecurityTokenElement.addChildElement("SecondaryParameters",
            prefix);
    for (int idx = 0; idx < this.secondaryParametersNodeList.getLength(); idx++) {
        Node node = this.secondaryParametersNodeList.item(idx);
        Node importedNode = soapPart.importNode(node, true);
        secondaryParametersElement.appendChild(importedNode);
    }
}

From source file:be.fedict.eid.dss.client.LoggingSoapHandler.java

public boolean handleMessage(SOAPMessageContext context) {
    LOG.debug("handle message");
    Boolean outboundProperty = (Boolean) context.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
    LOG.debug("outbound message: " + outboundProperty);
    SOAPMessage soapMessage = context.getMessage();
    ByteArrayOutputStream output = new ByteArrayOutputStream();
    try {//from w  w  w.ja v  a 2 s  . c om
        if (this.logToFile) {
            File tmpFile = File.createTempFile(
                    "eid-dss-soap-" + (outboundProperty ? "outbound" : "inbound") + "-", ".xml");
            FileOutputStream fileOutputStream = new FileOutputStream(tmpFile);
            soapMessage.writeTo(fileOutputStream);
            fileOutputStream.close();
            LOG.debug("tmp file: " + tmpFile.getAbsolutePath());
        }
        soapMessage.writeTo(output);
    } catch (Exception e) {
        LOG.error("SOAP error: " + e.getMessage());
    }
    LOG.debug("SOAP message: " + output.toString());
    return true;
}

From source file:be.fedict.trust.client.WSSecurityClientHandler.java

public boolean handleMessage(SOAPMessageContext soapMessageContext) {
    Boolean outboundProperty = (Boolean) soapMessageContext.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);

    SOAPMessage soapMessage = soapMessageContext.getMessage();
    SOAPPart soapPart = soapMessage.getSOAPPart();

    if (false == outboundProperty.booleanValue()) {
        /*/* w ww .j  a  v a 2 s . c o  m*/
         * Validate incoming WS-Security header if present
         */
        return handleInboundDocument(soapPart, soapMessageContext);
    }

    return true;
}