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:it.govpay.web.handler.MessageLoggingHandlerUtils.java

@SuppressWarnings("unchecked")
public static boolean logToSystemOut(SOAPMessageContext smc, String tipoServizio, int versioneServizio,
        Logger log) {/* w w w .ja  va 2 s .c o m*/
    Boolean outboundProperty = (Boolean) smc.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);

    GpContext ctx = null;
    Message msg = new Message();

    SOAPMessage message = smc.getMessage();
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    try {
        message.writeTo(baos);
        msg.setContent(baos.toByteArray());
    } catch (Exception e) {
        log.error("Exception in handler: " + e);
    }

    Map<String, List<String>> httpHeaders = null;

    if (outboundProperty.booleanValue()) {
        ctx = GpThreadLocal.get();
        httpHeaders = (Map<String, List<String>>) smc.get(MessageContext.HTTP_RESPONSE_HEADERS);
        msg.setType(MessageType.RESPONSE_OUT);
        ctx.getContext().getResponse().setOutDate(new Date());
        ctx.getContext().getResponse().setOutSize(Long.valueOf(baos.size()));
    } else {
        try {
            ctx = new GpContext(smc, tipoServizio, versioneServizio);
            ThreadContext.put("op", ctx.getTransactionId());
            GpThreadLocal.set(ctx);
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            return false;
        }
        httpHeaders = (Map<String, List<String>>) smc.get(MessageContext.HTTP_REQUEST_HEADERS);
        msg.setType(MessageType.REQUEST_IN);
        msg.setContentType(((HttpServletRequest) smc.get(MessageContext.SERVLET_REQUEST)).getContentType());

        ctx.getContext().getRequest().setInDate(new Date());
        ctx.getContext().getRequest().setInSize(Long.valueOf(baos.size()));
    }

    if (httpHeaders != null) {
        for (String key : httpHeaders.keySet()) {
            if (httpHeaders.get(key) != null) {
                if (key == null)
                    msg.addHeader(new Property("Status-line", httpHeaders.get(key).get(0)));
                else if (httpHeaders.get(key).size() == 1)
                    msg.addHeader(new Property(key, httpHeaders.get(key).get(0)));
                else
                    msg.addHeader(new Property(key, ArrayUtils.toString(httpHeaders.get(key))));
            }
        }
    }

    ctx.log(msg);

    return true;
}

From source file:eu.domibus.ebms3.sender.FaultOutHandler.java

/**
 * The {@code handleFault} method is responsible for logging of incoming ebMS3 errors
 *//* w  ww. j  a v  a 2s . c o  m*/
@Override
public boolean handleFault(SOAPMessageContext context) {

    Messaging messaging = this.extractMessaging(context.getMessage());

    FaultOutHandler.LOG.debug("An ebMS3 error was received for message with ebMS3 messageId:"
            + messaging.getSignalMessage().getMessageInfo().getMessageId()
            + ". Please check the database for more detailed information.");
    this.errorLogDao.create(ErrorLogEntry.parse(messaging, MSHRole.SENDING));

    return true;
}

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

public boolean handleFault(SOAPMessageContext context) {
    if (false == LOG.isDebugEnabled()) {
        return true;
    }/*  w w  w.  java 2 s . c o  m*/
    SOAPMessage soapMessage = context.getMessage();
    ByteArrayOutputStream output = new ByteArrayOutputStream();
    try {
        soapMessage.writeTo(output);
    } catch (Exception e) {
        LOG.error("SOAP error: " + e.getMessage());
    }
    String outputStr = output.toString();
    LOG.debug("SOAP fault: " + outputStr);
    return true;
}

From source file:ebay.dts.client.LoggingHandler.java

private void log(SOAPMessageContext messageContext) {
    boolean request = ((Boolean) messageContext.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY)).booleanValue();

    SOAPMessage meg = messageContext.getMessage();

    ByteArrayOutputStream out = new ByteArrayOutputStream();

    try {/*w  w  w . j  a v a2 s  .  c om*/
        meg.writeTo(out);
    } catch (Exception e) {
    }

    if (request) {
        logger.trace("SOAP Request message: " + new String(out.toByteArray()));
    } else {
        logger.trace("SOAP Response message: " + new String(out.toByteArray()));
    }

}

From source file:be.fedict.eid.idp.protocol.ws_federation.sts.WSSecuritySoapHandler.java

private void handleOutboundMessage(SOAPMessageContext context) throws SOAPException {
    SOAPMessage soapMessage = context.getMessage();
    SOAPPart soapPart = soapMessage.getSOAPPart();
    SOAPHeader soapHeader = soapMessage.getSOAPHeader();
    if (null == soapHeader) {
        SOAPEnvelope soapEnvelope = soapPart.getEnvelope();
        soapHeader = soapEnvelope.addHeader();
    }//from   w ww . j  a v a2 s  .  co m

    WSSecHeader wsSecHeader = new WSSecHeader();
    Element securityElement;
    try {
        securityElement = wsSecHeader.insertSecurityHeader(soapPart);
    } catch (WSSecurityException e) {
        throw new SOAPException("WS-Security error: " + e.getMessage(), e);
    }
    soapHeader.removeChild(securityElement);
    soapHeader.appendChild(securityElement);

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

From source file:be.fedict.eid.idp.protocol.ws_federation.sts.WSSecuritySoapHandler.java

private void handleInboundMessage(SOAPMessageContext context) throws SOAPException {
    SOAPMessage soapMessage = context.getMessage();
    SOAPPart soapPart = soapMessage.getSOAPPart();
    SOAPEnvelope soapEnvelope = soapPart.getEnvelope();
    SOAPHeader soapHeader = soapEnvelope.getHeader();
    if (null == soapHeader) {
        return;/*from   w  ww  . ja v  a 2  s. c o m*/
    }
    Iterator<SOAPHeaderElement> headerIterator = soapHeader.examineAllHeaderElements();
    while (headerIterator.hasNext()) {
        SOAPHeaderElement soapHeaderElement = headerIterator.next();
        if (false == WSTrustConstants.WS_SECURITY_NAMESPACE.equals(soapHeaderElement.getNamespaceURI())) {
            continue;
        }
        if (false == "Security".equals(soapHeaderElement.getLocalName())) {
            continue;
        }
        Iterator<SOAPElement> securityElementIterator = soapHeaderElement.getChildElements();
        while (securityElementIterator.hasNext()) {
            SOAPElement securityElement = securityElementIterator.next();
            if (false == WSTrustConstants.SAML2_NAMESPACE.equals(securityElement.getNamespaceURI())) {
                continue;
            }
            if (false == "Assertion".equals(securityElement.getLocalName())) {
                continue;
            }
            LOG.debug("putting SAML token on JAX-WS context");
            context.put(SAML_TOKEN_CONTEXT_ATTRIBUTE, securityElement);
            context.setScope(SAML_TOKEN_CONTEXT_ATTRIBUTE, Scope.APPLICATION);
        }
    }
}

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

private void handleInboundMessage(SOAPMessageContext context) throws SOAPException, TransformerException {
    Element bodyElement = context.getMessage().getSOAPBody();

    /*//from  w w w .j av  a 2s . c o  m
     * First tried this via an xalan XPathAPI expression. But we received
     * some DOM error when using Axis2.
     */
    NodeList nodeList = bodyElement.getElementsByTagNameNS(WSConstants.WSTRUST_NAMESPACE,
            "RequestedSecurityToken");
    Element requestedSecurityTokenElement;
    if (nodeList.getLength() > 0) {
        requestedSecurityTokenElement = (Element) nodeList.item(0).getFirstChild();
    } else {
        requestedSecurityTokenElement = null;
    }

    this.requestedSecurityToken = requestedSecurityTokenElement;
}

From source file:jp.primecloud.auto.nifty.soap.security.SignatureHandler.java

/**
 * {@inheritDoc}//from  w  w w . j  a  v  a2 s.  co m
 */
@Override
public boolean handleFault(SOAPMessageContext context) {
    if (log.isDebugEnabled()) {
        try {
            String envelope = transform(context.getMessage().getSOAPPart());
            log.debug(envelope);
        } catch (TransformerException e) {
            log.warn(e.getMessage());
        }
    }
    return true;
}

From source file:be.e_contract.mycarenet.sts.WSSecuritySOAPHandler.java

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

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

    WSSecTimestamp wsSecTimeStamp = new WSSecTimestamp();
    wsSecTimeStamp.setTimeToLive(60);/*from w  w w .j a  v a 2  s.c  o  m*/
    wsSecTimeStamp.build(soapPart, wsSecHeader);

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

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

@Override
public boolean handleMessage(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 {/*from  w w  w  .  ja v  a2 s . c o  m*/
        soapMessage.writeTo(output);
    } catch (Exception e) {
        LOG.error("SOAP error: " + e.getMessage());
    }
    LOG.debug("SOAP message: " + output.toString());
    return true;
}