Java Code Examples for org.springframework.context.i18n.LocaleContextHolder#getLocaleContext()
The following examples show how to use
org.springframework.context.i18n.LocaleContextHolder#getLocaleContext() .
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: HttpComponentsHttpInvokerRequestExecutor.java From spring-analysis-note with MIT License | 6 votes |
/** * 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 * @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()); RequestConfig requestConfig = createRequestConfig(config); if (requestConfig != null) { httpPost.setConfig(requestConfig); } LocaleContext localeContext = LocaleContextHolder.getLocaleContext(); if (localeContext != null) { Locale locale = localeContext.getLocale(); if (locale != null) { httpPost.addHeader(HTTP_HEADER_ACCEPT_LANGUAGE, locale.toLanguageTag()); } } if (isAcceptGzipEncoding()) { httpPost.addHeader(HTTP_HEADER_ACCEPT_ENCODING, ENCODING_GZIP); } return httpPost; }
Example 2
Source File: SimpleHttpInvokerRequestExecutor.java From spring-analysis-note with MIT License | 6 votes |
/** * Prepare the given HTTP connection. * <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 connection 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 connection, int contentLength) throws IOException { if (this.connectTimeout >= 0) { connection.setConnectTimeout(this.connectTimeout); } if (this.readTimeout >= 0) { connection.setReadTimeout(this.readTimeout); } connection.setDoOutput(true); connection.setRequestMethod(HTTP_METHOD_POST); connection.setRequestProperty(HTTP_HEADER_CONTENT_TYPE, getContentType()); connection.setRequestProperty(HTTP_HEADER_CONTENT_LENGTH, Integer.toString(contentLength)); LocaleContext localeContext = LocaleContextHolder.getLocaleContext(); if (localeContext != null) { Locale locale = localeContext.getLocale(); if (locale != null) { connection.setRequestProperty(HTTP_HEADER_ACCEPT_LANGUAGE, locale.toLanguageTag()); } } if (isAcceptGzipEncoding()) { connection.setRequestProperty(HTTP_HEADER_ACCEPT_ENCODING, ENCODING_GZIP); } }
Example 3
Source File: HttpComponentsHttpInvokerRequestExecutor.java From java-technology-stack with MIT License | 6 votes |
/** * 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 * @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()); RequestConfig requestConfig = createRequestConfig(config); if (requestConfig != null) { httpPost.setConfig(requestConfig); } LocaleContext localeContext = LocaleContextHolder.getLocaleContext(); if (localeContext != null) { Locale locale = localeContext.getLocale(); if (locale != null) { httpPost.addHeader(HTTP_HEADER_ACCEPT_LANGUAGE, locale.toLanguageTag()); } } if (isAcceptGzipEncoding()) { httpPost.addHeader(HTTP_HEADER_ACCEPT_ENCODING, ENCODING_GZIP); } return httpPost; }
Example 4
Source File: SimpleHttpInvokerRequestExecutor.java From java-technology-stack with MIT License | 6 votes |
/** * Prepare the given HTTP connection. * <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 connection 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 connection, int contentLength) throws IOException { if (this.connectTimeout >= 0) { connection.setConnectTimeout(this.connectTimeout); } if (this.readTimeout >= 0) { connection.setReadTimeout(this.readTimeout); } connection.setDoOutput(true); connection.setRequestMethod(HTTP_METHOD_POST); connection.setRequestProperty(HTTP_HEADER_CONTENT_TYPE, getContentType()); connection.setRequestProperty(HTTP_HEADER_CONTENT_LENGTH, Integer.toString(contentLength)); LocaleContext localeContext = LocaleContextHolder.getLocaleContext(); if (localeContext != null) { Locale locale = localeContext.getLocale(); if (locale != null) { connection.setRequestProperty(HTTP_HEADER_ACCEPT_LANGUAGE, locale.toLanguageTag()); } } if (isAcceptGzipEncoding()) { connection.setRequestProperty(HTTP_HEADER_ACCEPT_ENCODING, ENCODING_GZIP); } }
Example 5
Source File: HttpComponentsHttpInvokerRequestExecutor.java From lams with GNU General Public License v2.0 | 6 votes |
/** * 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 * @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()); RequestConfig requestConfig = createRequestConfig(config); if (requestConfig != null) { httpPost.setConfig(requestConfig); } LocaleContext localeContext = LocaleContextHolder.getLocaleContext(); if (localeContext != null) { Locale locale = localeContext.getLocale(); if (locale != null) { httpPost.addHeader(HTTP_HEADER_ACCEPT_LANGUAGE, StringUtils.toLanguageTag(locale)); } } if (isAcceptGzipEncoding()) { httpPost.addHeader(HTTP_HEADER_ACCEPT_ENCODING, ENCODING_GZIP); } return httpPost; }
Example 6
Source File: SimpleHttpInvokerRequestExecutor.java From lams with GNU General Public License v2.0 | 6 votes |
/** * Prepare the given HTTP connection. * <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 connection 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 connection, int contentLength) throws IOException { if (this.connectTimeout >= 0) { connection.setConnectTimeout(this.connectTimeout); } if (this.readTimeout >= 0) { connection.setReadTimeout(this.readTimeout); } connection.setDoOutput(true); connection.setRequestMethod(HTTP_METHOD_POST); connection.setRequestProperty(HTTP_HEADER_CONTENT_TYPE, getContentType()); connection.setRequestProperty(HTTP_HEADER_CONTENT_LENGTH, Integer.toString(contentLength)); LocaleContext localeContext = LocaleContextHolder.getLocaleContext(); if (localeContext != null) { Locale locale = localeContext.getLocale(); if (locale != null) { connection.setRequestProperty(HTTP_HEADER_ACCEPT_LANGUAGE, StringUtils.toLanguageTag(locale)); } } if (isAcceptGzipEncoding()) { connection.setRequestProperty(HTTP_HEADER_ACCEPT_ENCODING, ENCODING_GZIP); } }
Example 7
Source File: HttpComponentsHttpInvokerRequestExecutor.java From spring4-understanding with Apache License 2.0 | 6 votes |
/** * 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 * @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()); RequestConfig requestConfig = createRequestConfig(config); if (requestConfig != null) { httpPost.setConfig(requestConfig); } LocaleContext localeContext = LocaleContextHolder.getLocaleContext(); if (localeContext != null) { Locale locale = localeContext.getLocale(); if (locale != null) { httpPost.addHeader(HTTP_HEADER_ACCEPT_LANGUAGE, StringUtils.toLanguageTag(locale)); } } if (isAcceptGzipEncoding()) { httpPost.addHeader(HTTP_HEADER_ACCEPT_ENCODING, ENCODING_GZIP); } return httpPost; }
Example 8
Source File: SimpleHttpInvokerRequestExecutor.java From spring4-understanding with Apache License 2.0 | 6 votes |
/** * Prepare the given HTTP connection. * <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 connection 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 connection, int contentLength) throws IOException { if (this.connectTimeout >= 0) { connection.setConnectTimeout(this.connectTimeout); } if (this.readTimeout >= 0) { connection.setReadTimeout(this.readTimeout); } connection.setDoOutput(true); connection.setRequestMethod(HTTP_METHOD_POST); connection.setRequestProperty(HTTP_HEADER_CONTENT_TYPE, getContentType()); connection.setRequestProperty(HTTP_HEADER_CONTENT_LENGTH, Integer.toString(contentLength)); LocaleContext localeContext = LocaleContextHolder.getLocaleContext(); if (localeContext != null) { Locale locale = localeContext.getLocale(); if (locale != null) { connection.setRequestProperty(HTTP_HEADER_ACCEPT_LANGUAGE, StringUtils.toLanguageTag(locale)); } } if (isAcceptGzipEncoding()) { connection.setRequestProperty(HTTP_HEADER_ACCEPT_ENCODING, ENCODING_GZIP); } }