Example usage for javax.xml.ws.handler MessageContext MESSAGE_OUTBOUND_PROPERTY

List of usage examples for javax.xml.ws.handler MessageContext MESSAGE_OUTBOUND_PROPERTY

Introduction

In this page you can find the example usage for javax.xml.ws.handler MessageContext MESSAGE_OUTBOUND_PROPERTY.

Prototype

String MESSAGE_OUTBOUND_PROPERTY

To view the source code for javax.xml.ws.handler MessageContext MESSAGE_OUTBOUND_PROPERTY.

Click Source Link

Document

Standard property: message direction, true for outbound messages, false for inbound.

Usage

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

public boolean handleMessage(SOAPMessageContext context) {
    if (false == LOG.isDebugEnabled()) {
        return true;
    }/*from   w  ww.  jav a  2 s .com*/
    Boolean outboundProperty = (Boolean) context.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
    LOG.debug("outbound message: " + outboundProperty);
    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 message: " + outputStr);
    return true;
}

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

@Override
public boolean handleMessage(SOAPMessageContext context) {
    Boolean outboundProperty = (Boolean) context.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
    if (true == outboundProperty.booleanValue()) {
        try {//from  w  w w  .  j av  a  2 s.c o m
            handleOutboundMessage(context);
        } catch (Exception e) {
            throw new ProtocolException(e);
        }
    } else {
        try {
            handleInboundMessage(context);
        } catch (Exception e) {
            throw new ProtocolException(e);
        }
    }
    return true;
}

From source file:com.hiperium.integration.access.control.SoapSignatureHandler.java

@SuppressWarnings("unchecked")
@Override//from  w  w  w . ja  va  2 s . co m
public boolean handleMessage(SOAPMessageContext context) {
    LOGGER.debug("handleMessage - BEGIN");
    // Only message arriving from the client. Not processing responses.
    Boolean outbound = (Boolean) context.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
    if (!outbound) {
        // Get the sessionId from the entire HTTP Message
        StringBuffer sessionIdBuffer = new StringBuffer();
        Map<String, List<String>> map = (Map<String, List<String>>) context
                .get(MessageContext.HTTP_REQUEST_HEADERS);
        for (String session : this.getHTTPHeader(map, CommonsUtil.SESSIONID)) {
            sessionIdBuffer.append(session);
        }
        // Try to get SOAP header values from the SOAP message
        try {
            SOAPMessage msg = context.getMessage();
            if (LOGGER.isDebugEnabled()) {
                System.out.println("REQUEST:");
                msg.writeTo(System.out);
                System.out.println();
            }
            Node node = msg.getSOAPHeader().getFirstChild();

            // Header values
            NodeList nodeList = node.getChildNodes(); // Name, TimeStamp, Signature.
            if (nodeList.getLength() < 3) {
                this.generateFault(msg, "Too few header nodes!");
            }

            // Extract the required attributes.
            Long homeId = Long.valueOf(nodeList.item(0).getFirstChild().getNodeValue());
            String signature = nodeList.item(1).getFirstChild().getNodeValue();
            String timestamp = nodeList.item(2).getFirstChild().getNodeValue();
            if (StringUtils.isBlank(timestamp) || StringUtils.isBlank(signature)) {
                this.generateFault(msg, "Missing header key/value pairs!");
            }

            // Validates that the user Token exists in the DB for valid registered external Application.
            String token = this.securityBusinessDelegate.getHomeGatewayBO().findTokenInSession(homeId,
                    sessionIdBuffer.toString());
            if (StringUtils.isBlank(token)) {
                this.generateFault(msg, homeId.toString().concat(" not registered!"));
            }

            // Generate comparison signature and compare against what's sent.
            byte[] secretBytes = Signature.getBytes(token);
            String localSignature = Signature.createSignature(homeId, timestamp, secretBytes);
            if (!this.verify(signature, localSignature)) {
                this.generateFault(msg, "HMAC signatures do not match.");
            }
        } catch (Exception e) {
            throw new RuntimeException("SOAPException thrown.", e);
        }
    }
    LOGGER.debug("handleMessage - END");
    return true; //continue other handler chain
}

From source file:be.fedict.hsm.client.WSSecuritySOAPHandler.java

@Override
public boolean handleMessage(SOAPMessageContext context) {
    Boolean outboundProperty = (Boolean) context.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
    if (true == outboundProperty.booleanValue()) {
        try {// w  ww  .  j  a  v a 2  s  .  co  m
            handleOutboundMessage(context);
        } catch (Exception e) {
            throw new ProtocolException(e);
        }
    }
    return true;
}

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

public boolean handleMessage(SOAPMessageContext context) {
    if (false == LOG.isDebugEnabled()) {
        return true;
    }/*from   w w w . j  av a2s  . com*/
    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 {
        soapMessage.writeTo(output);
    } catch (Exception e) {
        LOG.error("SOAP error: " + e.getMessage());
    }
    LOG.debug("SOAP message: " + output.toString());
    return true;
}

From source file:com.konakart.bl.modules.ordertotal.thomson.HeaderLoggingHandler.java

/**
 * Outputs the soap msg to the logger/*w  w  w. ja va  2s . c o  m*/
 * 
 * @param context
 */
public void logSoapMsg(SOAPMessageContext context) {
    if (!log.isDebugEnabled()) {
        return;
    }

    Boolean outboundProperty = (Boolean) context.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
    String msgType = null;
    if (outboundProperty.booleanValue()) {
        msgType = "Request:";
    } else {
        msgType = "Response:";
    }

    SOAPMessage message = context.getMessage();
    try {
        TransformerFactory tff = TransformerFactory.newInstance();
        Transformer tf = tff.newTransformer();

        // Set formatting

        tf.setOutputProperty(OutputKeys.INDENT, "yes");
        tf.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2");

        Source sc = message.getSOAPPart().getContent();

        ByteArrayOutputStream streamOut = new ByteArrayOutputStream();
        StreamResult result = new StreamResult(streamOut);
        tf.transform(sc, result);

        if (log.isDebugEnabled()) {
            log.debug(msgType + "\n" + streamOut.toString()
                    + "\n------------------------------------------------------------------------");
        }
    } catch (Exception ex) {
        ex.printStackTrace();
    }
}

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

/**
 * {@inheritDoc}// w w w. ja va2s .c o  m
 */
@Override
public boolean handleMessage(SOAPMessageContext context) {
    Boolean outbound = (Boolean) context.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
    if (outbound != null && outbound.booleanValue()) {
        try {
            Document document = context.getMessage().getSOAPPart();

            WSSecHeader header = new WSSecHeader();
            header.insertSecurityHeader(document);

            WSSecSignature signature = new WSSecSignature();
            signature.setKeyIdentifierType(WSConstants.BST_DIRECT_REFERENCE);
            signature.prepare(document, crypto, header);

            signature.appendBSTElementToHeader(header);
            signature.appendToHeader(header);
            signature.computeSignature();
        } catch (WSSecurityException e) {
            throw new RuntimeException(e);
        }
    }

    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.agiv.security.handler.AuthenticationHandler.java

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

    if (true == outboundProperty.booleanValue()) {
        try {//w  w w.  ja v a 2 s.  co  m
            handleOutboundMessage(context);
        } catch (Exception e) {
            throw new ProtocolException(e);
        }
    }

    return true;
}

From source file:com.profesorfalken.payzen.webservices.sdk.handler.soap.HeaderHandler.java

/**
 * Takes the outgoing SOAP message and modifies it adding the header 
 * information//from w  w  w. j a  v  a2  s . c  o  m
 * 
 * @param smc SOAP message context
 * @return 
 */
@Override
public boolean handleMessage(SOAPMessageContext smc) {

    Boolean outboundProperty = (Boolean) smc.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);

    if (Boolean.TRUE.equals(outboundProperty)) {

        SOAPMessage message = smc.getMessage();

        try {
            SOAPEnvelope envelope = message.getSOAPPart().getEnvelope();

            //Creates header into SOAP envelope
            SOAPHeader header = envelope.getHeader();
            if (header == null) {
                header = envelope.addHeader();
            }

            // Add shopId
            addHeaderField(header, "shopId", this.shopId);

            // Timestamp
            TimeZone tz = TimeZone.getTimeZone("UTC");
            DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
            df.setTimeZone(tz);
            String nowAsISO = df.format(new Date());
            addHeaderField(header, "timestamp", nowAsISO);

            // Mode
            addHeaderField(header, "mode", this.mode);

            // Add requestId
            String requestId = UUID.randomUUID().toString();
            addHeaderField(header, "requestId", requestId);

            // Authentication token
            String tokenString = requestId + nowAsISO;
            addHeaderField(header, "authToken", sign(tokenString, shopKey));

        } catch (SOAPException e) {
            logger.error("Error sending header", e);
        }
    }

    return outboundProperty;

}

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

public boolean handleMessage(SOAPMessageContext context) {
    Boolean outboundProperty = (Boolean) context.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
    if (true == outboundProperty.booleanValue()) {
        try {//from w w w  . ja v a2s  .c om
            handleOutboundMessage(context);
        } catch (SOAPException e) {
            throw new ProtocolException(e);
        }
    } else {
        handleInboundMessage(context);
    }
    return true;
}