当前位置: 首页>>代码示例>>Java>>正文


Java MessageContext.DEFAULT_CHAR_SET_ENCODING属性代码示例

本文整理汇总了Java中org.apache.axis2.context.MessageContext.DEFAULT_CHAR_SET_ENCODING属性的典型用法代码示例。如果您正苦于以下问题:Java MessageContext.DEFAULT_CHAR_SET_ENCODING属性的具体用法?Java MessageContext.DEFAULT_CHAR_SET_ENCODING怎么用?Java MessageContext.DEFAULT_CHAR_SET_ENCODING使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在org.apache.axis2.context.MessageContext的用法示例。


在下文中一共展示了MessageContext.DEFAULT_CHAR_SET_ENCODING属性的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: processDocument

public OMElement processDocument(Reader reader, String contentType,
                                 MessageContext messageContext) throws AxisFault {
    String charset;
    try {
        ContentType ct = new ContentType(contentType);
        charset = ct.getParameter("charset");
    } catch (ParseException ex) {
        charset = null;
    }
    if (charset == null) {
        charset = MessageContext.DEFAULT_CHAR_SET_ENCODING;
    }
    messageContext.setProperty(Constants.Configuration.CHARACTER_SET_ENCODING, charset);        
    return processDocument(new ReaderInputStream(reader, charset), contentType,
            messageContext);
}
 
开发者ID:wso2,项目名称:wso2-axis2-transports,代码行数:16,代码来源:TextMessageBuilderAdapter.java

示例2: getCharSetEncoding

/**
 * Utility method to query CharSetEncoding. First look in the
 * MessageContext. If it's not there look in the OpContext. Use the defualt,
 * if it's not given in either contexts.
 *
 * @param msgContext the active MessageContext
 * @return String the CharSetEncoding
 */
public static String getCharSetEncoding(MessageContext msgContext) {
    String charSetEnc = (String) msgContext
        .getProperty(Constants.Configuration.CHARACTER_SET_ENCODING);

    if (charSetEnc == null) {
        OperationContext opctx = msgContext.getOperationContext();
        if (opctx != null) {
            charSetEnc = (String) opctx
                .getProperty(Constants.Configuration.CHARACTER_SET_ENCODING);
        }
        /**
         * If the char set enc is still not found use the default
         */
        if (charSetEnc == null) {
            charSetEnc = MessageContext.DEFAULT_CHAR_SET_ENCODING;
        }
    }
    return charSetEnc;
}
 
开发者ID:wso2,项目名称:wso2-axis2,代码行数:27,代码来源:TransportUtils.java

示例3: initializeMessageContext

public static int initializeMessageContext(MessageContext msgContext,
                                            String soapActionHeader,
                                            String requestURI,
                                            String contentType) {
    int soapVersion = VERSION_UNKNOWN;
    // remove the starting and trailing " from the SOAP Action
    if ((soapActionHeader != null) 
            && soapActionHeader.length() > 0 
            && soapActionHeader.charAt(0) == '\"'
            && soapActionHeader.endsWith("\"")) {
        soapActionHeader = soapActionHeader.substring(1, soapActionHeader.length() - 1);
    }

    // fill up the Message Contexts
    msgContext.setSoapAction(soapActionHeader);
    msgContext.setTo(new EndpointReference(requestURI));
    msgContext.setServerSide(true);

    // get the type of char encoding
    String charSetEnc = BuilderUtil.getCharSetEncoding(contentType);
    if (charSetEnc == null) {
        charSetEnc = MessageContext.DEFAULT_CHAR_SET_ENCODING;
    }
    msgContext.setProperty(Constants.Configuration.CHARACTER_SET_ENCODING, charSetEnc);

    if (contentType != null) {
        if (contentType.indexOf(SOAP12Constants.SOAP_12_CONTENT_TYPE) > -1) {
            soapVersion = VERSION_SOAP12;
            TransportUtils.processContentTypeForAction(contentType, msgContext);
        } else if (contentType
                .indexOf(SOAP11Constants.SOAP_11_CONTENT_TYPE) > -1) {
            soapVersion = VERSION_SOAP11;
        } else if (isRESTRequest(contentType)) {
            // If REST, construct a SOAP11 envelope to hold the rest message and
            // indicate that this is a REST message.
            soapVersion = VERSION_SOAP11;
            msgContext.setDoingREST(true);
        }
        if (soapVersion == VERSION_SOAP11) {
            // TODO Keith : Do we need this anymore
            // Deployment configuration parameter
        	Parameter disableREST = msgContext
                    .getParameter(Constants.Configuration.DISABLE_REST);
        	if (soapActionHeader == null && disableREST != null) {
        		if (Constants.VALUE_FALSE.equals(disableREST.getValue())) {
                    // If the content Type is text/xml (BTW which is the
                    // SOAP 1.1 Content type ) and the SOAP Action is
                    // absent it is rest !!
                    msgContext.setDoingREST(true);
                }
            }
        }
    }
    return soapVersion;
}
 
开发者ID:wso2,项目名称:wso2-axis2,代码行数:55,代码来源:HTTPTransportUtils.java

示例4: createSOAPMessage

/**
     * This method will create a SOAPEnvelope based on the InputStream stored on
     * the MessageContext. The 'detach' parameter controls whether or not the
     * underlying DetachableInputStream is detached at the end of the method. Note,
     * detaching the DetachableInputStream closes the underlying InputStream that
     * is stored on the MessageContext.
     */
    public static SOAPEnvelope createSOAPMessage(MessageContext msgContext,
                                                 boolean detach) throws AxisFault {
//        final SOAPEnvelope envelope = msgContext.getEnvelope();
//        if (envelope != null) {
//            if (envelope.isComplete())
//                return envelope;
//        }
        try {
            InputStream inStream = (InputStream) msgContext
                    .getProperty(MessageContext.TRANSPORT_IN);
            msgContext.setProperty(MessageContext.TRANSPORT_IN, null);

            // this inputstram is set by the TransportSender represents a two
            // way transport or a Transport Recevier
            if (inStream == null) {
                throw new AxisFault(Messages.getMessage("inputstreamNull"));
            }

            String contentType = (String) msgContext
                    .getProperty(Constants.Configuration.CONTENT_TYPE);

            // get the type of char encoding
            String charSetEnc = (String) msgContext
                    .getProperty(Constants.Configuration.CHARACTER_SET_ENCODING);
            if (charSetEnc == null && contentType != null) {
                charSetEnc = BuilderUtil.getCharSetEncoding(contentType);
            } else if (charSetEnc == null) {
                charSetEnc = MessageContext.DEFAULT_CHAR_SET_ENCODING;
            }
            msgContext.setProperty(Constants.Configuration.CHARACTER_SET_ENCODING, charSetEnc);

            SOAPEnvelope env = createSOAPMessage(msgContext, inStream, contentType);

            // if we were told to detach, we will make the call here, this is only applicable
            // if a DetachableInputStream instance is found on the MessageContext
            if(detach) {
                DetachableInputStream dis = (DetachableInputStream) msgContext.getProperty(Constants.DETACHABLE_INPUT_STREAM);
                if(dis != null) {
                    if(log.isDebugEnabled()) {
                        log.debug("Detaching input stream after SOAPEnvelope construction");
                    }
                    dis.detach();
                }
            }
            return env;
        } catch (Exception e) {
            throw AxisFault.makeFault(e);
        }
    }
 
开发者ID:wso2,项目名称:wso2-axis2,代码行数:56,代码来源:TransportUtils.java

示例5: getCharSetEncoding

/**
 * Extracts and returns the character set encoding from the Content-type header
 * <p/>
 * Example: "Content-Type: text/xml; charset=utf-8" would return "utf-8"
 *
 * @param contentType a content-type (from HTTP or MIME, for instance)
 * @return the character set encoding if found, or MessageContext.DEFAULT_CHAR_SET_ENCODING
 */
public static String getCharSetEncoding(String contentType) {
    if (log.isDebugEnabled()) {
        log.debug("Input contentType (" + contentType + ")");
    }
    if (contentType == null) {
        // Using the default UTF-8
        if (log.isDebugEnabled()) {
            log.debug("CharSetEncoding defaulted (" + MessageContext.DEFAULT_CHAR_SET_ENCODING +
                      ")");
        }
        return MessageContext.DEFAULT_CHAR_SET_ENCODING;
    }

    int index = contentType.indexOf(HTTPConstants.CHAR_SET_ENCODING);

    if (index == -1) {    // Charset encoding not found in the content-type header
        // Using the default UTF-8
        if (log.isDebugEnabled()) {
            log.debug("CharSetEncoding defaulted (" + MessageContext.DEFAULT_CHAR_SET_ENCODING +
                      ")");
        }
        return MessageContext.DEFAULT_CHAR_SET_ENCODING;
    }

    // If there are spaces around the '=' sign
    int indexOfEq = contentType.indexOf("=", index);

    // There can be situations where "charset" is not the last parameter of the Content-Type header
    int indexOfSemiColon = contentType.indexOf(";", indexOfEq);
    String value;

    if (indexOfSemiColon > 0) {
        value = (contentType.substring(indexOfEq + 1, indexOfSemiColon));
    } else {
        value = (contentType.substring(indexOfEq + 1, contentType.length())).trim();
    }

    // There might be "" around the value - if so remove them
    if (value.indexOf('\"') != -1) {
        value = value.replaceAll("\"", "");
    }
    value = value.trim();
    if (log.isDebugEnabled()) {
        log.debug("CharSetEncoding from content-type (" + value + ")");
    }
    return value;
}
 
开发者ID:wso2,项目名称:wso2-axis2,代码行数:55,代码来源:BuilderUtil.java


注:本文中的org.apache.axis2.context.MessageContext.DEFAULT_CHAR_SET_ENCODING属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。