FileDocCategorySizeDatePackage
MessageLayerClientHandler.javaAPI DocGlassfish v2 API7374Fri May 04 22:36:10 BST 2007com.sun.enterprise.webservice

MessageLayerClientHandler

public class MessageLayerClientHandler extends Object implements javax.xml.rpc.handler.Handler
Client Side Handler to be invoked from the appclient A similiar copy sans appserver specific logging mechanism should be made available to standalone clients to use our WSS infrastructure.
author
Harpreet Singh
version
since

Fields Summary
private static Logger
_logger
public static final String
CLIENT_AUTH_CONFIG
private static final String
CLIENT_AUTH_CONTEXT
private static String
errMsg
private com.sun.enterprise.security.jauth.ClientAuthConfig
config_
private QName[]
qname
private boolean
isAppclientContainer
private QName
serviceName
Constructors Summary
public MessageLayerClientHandler()
Creates a new instance of MessageLayerClientHandler


           
      
	int containerType = Switch.getSwitch().getContainerType();
	if(containerType == Switch.APPCLIENT_CONTAINER){
		isAppclientContainer = true;
	} else{
		isAppclientContainer = false;
	}
    
Methods Summary
public voiddestroy()

        qname = null;
    
public javax.xml.namespace.QName[]getHeaders()

        return qname;
    
public booleanhandleFault(javax.xml.rpc.handler.MessageContext messageContext)

        // no need to do any special processing
        if(_logger.isLoggable(Level.FINE)){
            _logger.log(Level.FINE, "wss-auth-client: ClientHandler does not handle" +
            " SOAP faults");
        }
        return true;
    
public booleanhandleRequest(javax.xml.rpc.handler.MessageContext messageContext)

        boolean retValue;
        if(!isSoapMessageContext(messageContext)){
            // cannot process this, as this is not a soap message context
            throw new JAXRPCException(errMsg);
        }
	if (config_ == null) {
	    return true;
	} 
	  
        // get the ClientAuthContext
	SOAPMessageContext smc = (SOAPMessageContext) messageContext;
	SOAPMessage request = smc.getMessage();
	ClientAuthContext cAC = config_.getAuthContext(null,request);
	if (cAC == null) {
	    return true;
	} 

	smc.setProperty(CLIENT_AUTH_CONTEXT, cAC);
	smc.setProperty(javax.xml.ws.handler.MessageContext.WSDL_SERVICE,
            serviceName);

        try{
	    WebServiceSecurity.secureRequest(smc,cAC,isAppclientContainer);
        } catch(Exception e){
            if (_logger.isLoggable(Level.WARNING)){
                _logger.log(Level.WARNING, "ws.error_secure_request", e);
            }
            throw new JAXRPCException(e);
        }
        return true;
    
public booleanhandleResponse(javax.xml.rpc.handler.MessageContext messageContext)

        boolean retValue;
        if(!isSoapMessageContext(messageContext)){
            // cannot process this, as this is not a soap message context
            throw new JAXRPCException(errMsg);
        }
	if (config_ == null) {
	    return true;
	} 

        // get the ClientAuthContext
        SOAPMessageContext smc = (SOAPMessageContext) messageContext;
	ClientAuthContext cAC = 
	    (ClientAuthContext) smc.getProperty(CLIENT_AUTH_CONTEXT);
	if (cAC == null) {
	    return true;
	} 

        try{
	    retValue = WebServiceSecurity.validateResponse(smc,cAC);
        }catch(Exception e){
            if (_logger.isLoggable(Level.WARNING)){
                _logger.log(Level.WARNING, "ws.error_validate_response", e);
            }
            throw new JAXRPCException(e);
        }
        
        return retValue;
    
public voidinit(javax.xml.rpc.handler.HandlerInfo info)

        // 109 mandates saving qnames in init
        qname = info.getHeaders();
	config_ = (ClientAuthConfig) info.getHandlerConfig().get(CLIENT_AUTH_CONFIG);
        serviceName = (QName)info.getHandlerConfig().get(javax.xml.ws.handler.MessageContext.WSDL_SERVICE);
    
private booleanisSoapMessageContext(javax.xml.rpc.handler.MessageContext mc)
109 mandates that each MessageContext be checked to see if it is a a SOAPMessageContext and whether the handler processes it

        boolean retValue =
        (mc instanceof SOAPMessageContext)? true: false;
        if(!retValue && _logger.isLoggable(Level.WARNING)){
            _logger.log(Level.WARNING, "ws.error_not_soap");
        }
        return retValue;