Java Code Examples for org.apache.axis2.context.MessageContext#getTo()

The following examples show how to use org.apache.axis2.context.MessageContext#getTo() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: 103333429.java    From docs-apim with Apache License 2.0 6 votes vote down vote up
/**
    * This is the implementation of the getDigest method and will implement the Extended DOMHASH
    * algorithm based HTTP request identifications. This will consider To address of the request,
    * HTTP headers and XML Payload in generating the digets. So, in effect
    * this will uniquely identify the HTTP request with the same To address, Headers and Payload.
    * 
    * @param msgContext - MessageContext on which the XML node identifier will be generated
    * @return Object representing the DOMHASH value of the normalized XML node
    * @throws CachingException if there is an error in generating the digest key
    *
    * @see org.wso2.caching.digest.DigestGenerator
    *          #getDigest(org.apache.axis2.context.MessageContext) 
    */
   public String getDigest(MessageContext msgContext) throws CachingException {
	OMNode body = msgContext.getEnvelope().getBody();
	String toAddress = null;
	if (msgContext.getTo() != null) {
		toAddress = msgContext.getTo().getAddress();			
	}
	Map<String, String> headers = (Map) msgContext.getProperty(org.apache.axis2.context.MessageContext.TRANSPORT_HEADERS);
    if (body != null) {
    	byte[] digest = null;
    	if (toAddress != null) {
    		digest = getDigest(body, toAddress, headers, MD5_DIGEST_ALGORITHM);
    	} else {
    		digest = getDigest(body, MD5_DIGEST_ALGORITHM);
    	}
        return digest != null ? getStringRepresentation(digest) : null;
    } else {
    	return null;
    }
}
 
Example 2
Source File: REQUESTHASHGenerator.java    From micro-integrator with Apache License 2.0 6 votes vote down vote up
/**
 * This is the implementation of the getDigest method and will implement the Extended DOMHASH algorithm based HTTP
 * request identifications. This will consider To address of the request, HTTP headers and XML Payload in generating
 * the digets. So, in effect this will uniquely identify the HTTP request with the same To address, Headers and
 * Payload.
 *
 * @param msgContext - MessageContext on which the XML node identifier will be generated
 * @return Object representing the DOMHASH value of the normalized XML node
 * @throws CachingException if there is an error in generating the digest key
 * @see org.wso2.caching.digest.DigestGenerator #getDigest(org.apache.axis2.context.MessageContext)
 */
public String getDigest(MessageContext msgContext) throws CachingException {
    OMNode body = msgContext.getEnvelope().getBody();
    String toAddress = null;
    if (msgContext.getTo() != null) {
        toAddress = msgContext.getTo().getAddress();
    }
    Map<String, String> headers = (Map) msgContext.getProperty(
            org.apache.axis2.context.MessageContext.TRANSPORT_HEADERS);
    if (body != null) {
        byte[] digest = null;
        if (toAddress != null) {
            digest = getDigest(body, toAddress, headers, MD5_DIGEST_ALGORITHM);
        } else {
            digest = getDigest(body, MD5_DIGEST_ALGORITHM);
        }
        return digest != null ? getStringRepresentation(digest) : null;
    } else {
        return null;
    }
}
 
Example 3
Source File: EventBrokerUtils.java    From carbon-commons with Apache License 2.0 5 votes vote down vote up
public static String extractTopicFromMessage(MessageContext mc) throws WSEventException {
    String topic = null;
    if (mc.getTo() != null && mc.getTo().getAddress() != null) {
        String toaddress = mc.getTo().getAddress();
        if (toaddress.contains("/publish/")) {
            Matcher matcher = EventingConstants.TO_ADDRESS_PATTERN.matcher(toaddress);
            if (matcher.matches()) {
                topic = matcher.group(1);
            }
        }
    }

    if ((topic == null) || (topic.trim().length() == 0)) {
        try {
            AXIOMXPath topicXPath = new AXIOMXPath(
                    "s11:Header/ns:" + EventingConstants.TOPIC_HEADER_NAME
                            + " | s12:Header/ns:" + EventingConstants.TOPIC_HEADER_NAME);
            topicXPath.addNamespace("s11", "http://schemas.xmlsoap.org/soap/envelope/");
            topicXPath.addNamespace("s12", "http://www.w3.org/2003/05/soap-envelope");
            topicXPath.addNamespace("ns", EventingConstants.TOPIC_HEADER_NS);

            OMElement topicNode = (OMElement) topicXPath.selectSingleNode(mc.getEnvelope());
            if (topicNode != null) {
                topic = topicNode.getText();
            }
        } catch (JaxenException e) {
            throw new WSEventException("can not process the xpath ", e);
        }
    }
    return topic;
}