Example usage for org.springframework.context.i18n LocaleContext getLocale

List of usage examples for org.springframework.context.i18n LocaleContext getLocale

Introduction

In this page you can find the example usage for org.springframework.context.i18n LocaleContext getLocale.

Prototype

@Nullable
Locale getLocale();

Source Link

Document

Return the current Locale, which can be fixed or determined dynamically, depending on the implementation strategy.

Usage

From source file:com.baidu.jprotobuf.rpc.client.SimpleHttpRequestExecutor.java

/**
 * Prepare the given HTTP connection.//from  w  w w .j ava2s  .  c o  m
 * <p>The default implementation specifies POST as method,
 * "application/x-java-serialized-object" as "Content-Type" header,
 * and the given content length as "Content-Length" header.
 * @param con the HTTP connection to prepare
 * @param contentLength the length of the content to send
 * @throws IOException if thrown by HttpURLConnection methods
 * @see java.net.HttpURLConnection#setRequestMethod
 * @see java.net.HttpURLConnection#setRequestProperty
 */
protected void prepareConnection(HttpURLConnection con, int contentLength) throws IOException {
    con.setDoOutput(true);
    con.setRequestMethod(HTTP_METHOD_POST);
    con.setRequestProperty(HTTP_HEADER_CONTENT_TYPE, getContentType());
    con.setRequestProperty(HTTP_HEADER_CONTENT_LENGTH, Integer.toString(contentLength));
    LocaleContext locale = LocaleContextHolder.getLocaleContext();
    if (locale != null) {
        con.setRequestProperty(HTTP_HEADER_ACCEPT_LANGUAGE, StringUtils.toLanguageTag(locale.getLocale()));
    }
    if (isAcceptGzipEncoding()) {
        con.setRequestProperty(HTTP_HEADER_ACCEPT_ENCODING, ENCODING_GZIP);
    }
}

From source file:com.duowan.common.rpc.client.CommonsHttpInvokerRequestExecutor.java

/**
 * Create a PostMethod for the given configuration.
 * <p>The default implementation creates a standard PostMethod with
 * "application/x-java-serialized-object" as "Content-Type" header.
 * @param config the HTTP invoker configuration that specifies the
 * target service//from   w  w  w.  ja v  a 2s . c o  m
 * @return the PostMethod instance
 * @throws IOException if thrown by I/O methods
 */
protected PostMethod createPostMethod(String serviceUrl) throws IOException {
    PostMethod postMethod = new PostMethod(serviceUrl);
    LocaleContext locale = LocaleContextHolder.getLocaleContext();
    if (locale != null) {
        postMethod.addRequestHeader(HTTP_HEADER_ACCEPT_LANGUAGE, StringUtils.toLanguageTag(locale.getLocale()));
    }
    if (isAcceptGzipEncoding()) {
        postMethod.addRequestHeader(HTTP_HEADER_ACCEPT_ENCODING, ENCODING_GZIP);
    }
    return postMethod;
}

From source file:org.springframework.remoting.httpinvoker.HttpComponentsHttpInvokerRequestExecutor.java

/**
 * Create a HttpPost for the given configuration.
 * <p>The default implementation creates a standard HttpPost with
 * "application/x-java-serialized-object" as "Content-Type" header.
 * @param config the HTTP invoker configuration that specifies the
 * target service//from w w  w  .j  a va2 s .  c om
 * @return the HttpPost instance
 * @throws java.io.IOException if thrown by I/O methods
 */
protected HttpPost createHttpPost(HttpInvokerClientConfiguration config) throws IOException {
    HttpPost httpPost = new HttpPost(config.getServiceUrl());
    LocaleContext locale = LocaleContextHolder.getLocaleContext();
    if (locale != null) {
        httpPost.addHeader(HTTP_HEADER_ACCEPT_LANGUAGE, StringUtils.toLanguageTag(locale.getLocale()));
    }
    if (isAcceptGzipEncoding()) {
        httpPost.addHeader(HTTP_HEADER_ACCEPT_ENCODING, ENCODING_GZIP);
    }
    return httpPost;
}

From source file:spring.test.web.HttpComponentsHttpInvokerRequestExecutor.java

/**
* Create a HttpPost for the given configuration.
* <p>The default implementation creates a standard HttpPost with
* "application/x-java-serialized-object" as "Content-Type" header.
* @param config the HTTP invoker configuration that specifies the
* target service/*from ww w .j av a 2  s .  c  o m*/
* @return the HttpPost instance
* @throws java.io.IOException if thrown by I/O methods
*/
protected HttpPost createHttpPost(HttpInvokerClientConfiguration config) throws IOException {
    HttpPost httpPost = new HttpPost(config.getServiceUrl());
    LocaleContext locale = LocaleContextHolder.getLocaleContext();

    if (locale != null) {
        httpPost.addHeader(HTTP_HEADER_ACCEPT_LANGUAGE, StringUtils.toLanguageTag(locale.getLocale()));
    }

    if (isAcceptGzipEncoding()) {
        httpPost.addHeader(HTTP_HEADER_ACCEPT_ENCODING, ENCODING_GZIP);
    }

    return httpPost;
}