FileDocCategorySizeDatePackage
ChannelContext.javaAPI DocExample11612Tue May 29 16:57:14 BST 2007com.sun.xml.ws.transport.tcp.util

ChannelContext

public class ChannelContext extends Object implements WSTCPFastInfosetStreamReaderRecyclable.RecycleAwareListener

Fields Summary
private static final Logger
logger
private final ConnectionSession
connectionSession
private final ChannelSettings
channelSettings
Channel settings aggreed during client-service handshaking
private com.sun.xml.ws.api.pipe.Codec
codec
Codec used to encode/decode messages on this channel
private final ContentType
contentType
Constructors Summary
public ChannelContext(ConnectionSession connectionSession, ChannelSettings channelSettings)

    
        
                
        this.connectionSession = connectionSession;
        this.channelSettings = channelSettings;
    
Methods Summary
public static voidconfigureCodec(com.sun.xml.ws.transport.tcp.util.ChannelContext channelContext, com.sun.xml.ws.api.SOAPVersion soapVersion, com.sun.xml.ws.api.pipe.Codec defaultCodec)
Configure Codec according to channel settings

        final List<String> supportedMimeTypes = channelContext.getChannelSettings().getNegotiatedMimeTypes();
        if (supportedMimeTypes != null) {
            if (supportedMimeTypes.contains(MimeTypeConstants.FAST_INFOSET_STATEFUL_SOAP11) ||
                    supportedMimeTypes.contains(MimeTypeConstants.FAST_INFOSET_STATEFUL_SOAP12)) {
                logger.log(Level.FINEST, "ChannelContext.configureCodec: FI Stateful");
                StreamSOAPCodec streamSoapCodec = defaultCodec instanceof SOAPBindingCodec ?
                    ((SOAPBindingCodec) defaultCodec).getXMLCodec() : null;
                channelContext.setCodec(WSTCPFastInfosetStreamCodec.create(streamSoapCodec, soapVersion, channelContext, true));
                return;
            } else if (supportedMimeTypes.contains(MimeTypeConstants.FAST_INFOSET_SOAP11) ||
                    supportedMimeTypes.contains(MimeTypeConstants.FAST_INFOSET_SOAP12)) {
                logger.log(Level.FINEST, "ChannelContext.configureCodec: FI Stateless");
                StreamSOAPCodec streamSoapCodec = defaultCodec instanceof SOAPBindingCodec ?
                    ((SOAPBindingCodec) defaultCodec).getXMLCodec() : null;
                channelContext.setCodec(WSTCPFastInfosetStreamCodec.create(streamSoapCodec, soapVersion, channelContext, false));
                return;
            }
        }
        
        logger.log(Level.FINEST, "ChannelContext.configureCodec: default");
        channelContext.setCodec(defaultCodec);
    
public java.lang.StringdecodeMimeType(int contentId)

        String mimeType = channelSettings.getNegotiatedMimeTypes().get(contentId);
        
        if (mimeType != null) {
            return mimeType;
        }
        throw new WSTCPException(WSTCPError.createNonCriticalError(TCPConstants.UNKNOWN_CONTENT_ID,
                MessagesMessages.WSTCP_0011_UNKNOWN_CONTENT_TYPE(contentId)));
    
public java.lang.StringdecodeParam(int paramId)

        String paramStr = channelSettings.getNegotiatedParams().get(paramId);
        
        if (paramStr != null) {
            return paramStr;
        }
        throw new WSTCPException(WSTCPError.createNonCriticalError(TCPConstants.UNKNOWN_PARAMETER_ID,
                MessagesMessages.WSTCP_0010_UNKNOWN_PARAMETER(paramId)));
    
public intencodeMimeType(java.lang.String mimeType)

        int contentId = channelSettings.getNegotiatedMimeTypes().indexOf(mimeType);
        if (contentId != -1) {
            return contentId;
        }
        
        throw new WSTCPException(WSTCPError.createNonCriticalError(TCPConstants.UNKNOWN_CONTENT_ID,
                MessagesMessages.WSTCP_0011_UNKNOWN_CONTENT_TYPE(mimeType)));
    
public intencodeParam(java.lang.String paramStr)

        int paramId = channelSettings.getNegotiatedParams().indexOf(paramStr);
        if (paramId != -1) {
            return paramId;
        }
        
        throw new WSTCPException(WSTCPError.createNonCriticalError(TCPConstants.UNKNOWN_PARAMETER_ID,
                MessagesMessages.WSTCP_0010_UNKNOWN_PARAMETER(paramStr)));
    
public intgetChannelId()
Return channel id

        return channelSettings.getChannelId();
    
public ChannelSettingsgetChannelSettings()
Return channel settings, which were aggreed during handshake phase

        return channelSettings;
    
public com.sun.xml.ws.api.pipe.CodecgetCodec()
Return message Codec, which is used for encoding/decoding messages on this virtual channel

        return codec;
    
public com.sun.xml.ws.transport.tcp.io.ConnectiongetConnection()
Return TCP connection object, where this virtual channel is acting on

        return connectionSession.getConnection();
    
public ConnectionSessiongetConnectionSession()
Return TCP session object where which this virual channel is open on

        return connectionSession;
    
public java.lang.StringgetContentType()
Gets message's content type from TCP protocol specific representation

        Connection connection = connectionSession.getConnection();
        final int mimeId = connection.getContentId();
        Map<Integer, String> params = connection.getContentProperties();
        
        if (logger.isLoggable(Level.FINEST)) {
            logger.log(Level.FINEST, MessagesMessages.WSTCP_1122_CHANNEL_CONTEXT_DECODE_CT(mimeId, params));
        }
        
        String mimeType = decodeMimeType(mimeId);
        
        String contentTypeStr = mimeType;
        if (params.size() > 0) {
            final StringBuffer ctBuf = new StringBuffer(contentTypeStr);
            for(Map.Entry<Integer, String> parameter : params.entrySet()) {
                ctBuf.append(';");
                final String paramKey = decodeParam(parameter.getKey());
                final String paramValue = parameter.getValue();
                ctBuf.append(paramKey);
                ctBuf.append('=");
                ctBuf.append(paramValue);
            }
            contentTypeStr = ctBuf.toString();
        }
        
        if (logger.isLoggable(Level.FINEST)) {
            logger.log(Level.FINEST, MessagesMessages.WSTCP_1123_CHANNEL_CONTEXT_DECODED_CT(contentTypeStr));
        }
        return contentTypeStr;
    
public WSTCPURIgetTargetWSURI()
Return correspondent WS's URI

        return channelSettings.getTargetWSURI();
    
public javax.xml.namespace.QNamegetWSServiceName()
Return virtual channel's correspondent service name

        return channelSettings.getWSServiceName();
    
public voidonRecycled()

        connectionSession.onReadCompleted();
    
private voidsetCodec(com.sun.xml.ws.api.pipe.Codec codec)

        this.codec = codec;
    
public voidsetContentType(java.lang.String contentTypeS)
Sets message's content type to TCP protocol specific representation

        Connection connection = connectionSession.getConnection();
        if (logger.isLoggable(Level.FINEST)) {
            logger.log(Level.FINEST, MessagesMessages.WSTCP_1120_CHANNEL_CONTEXT_ENCODE_CT(contentTypeS));
        }
        contentType.parse(contentTypeS);
        
        int mt = encodeMimeType(contentType.getMimeType());
        
        connection.setContentId(mt);
        final Map<String, String> parameters = contentType.getParameters();
        for(Map.Entry<String, String> parameter : parameters.entrySet()) {
            final int paramId = encodeParam(parameter.getKey());
            connection.setContentProperty(paramId, parameter.getValue());
        }
        
        if (logger.isLoggable(Level.FINEST)) {
            logger.log(Level.FINEST, MessagesMessages.WSTCP_1121_CHANNEL_CONTEXT_ENCODED_CT(mt, parameters));
        }
    
public voidsetWSServiceName(javax.xml.namespace.QName wsServiceName)

        channelSettings.setWSServiceName(wsServiceName);
    
public java.lang.StringtoString()

        return String.format("ID: %d\nURI: %s\nCodec:%s", new Object[] {getChannelId(), getTargetWSURI(), getCodec()});