List of usage examples for org.springframework.context.i18n LocaleContextHolder getLocaleContext
@Nullable public static LocaleContext getLocaleContext()
From source file:org.cee.service.language.LanguageService.java
public LanguageList getSupportedLanguages() { List<String> langIds = searchService.getSupportedLanguages(); if (langIds == null) { //search service does not support languages at all, provide user with full list of languages langIds = Arrays.asList(Locale.getISOLanguages()); }/*from w w w . j a v a2s.c o m*/ List<EntityKey> languages = new ArrayList<EntityKey>(); int defaultLanguageIndex = 0; String defaultLanguage = "en"; Locale currentUserLocale = LocaleContextHolder.getLocaleContext().getLocale(); if (currentUserLocale != null) { defaultLanguage = currentUserLocale.getLanguage(); } for (String langId : langIds) { Locale locale = Locale.forLanguageTag(langId); if (locale != null) { if (locale.getLanguage().startsWith(defaultLanguage) || defaultLanguage.startsWith(locale.getLanguage())) { defaultLanguageIndex = languages.size(); } languages.add(EntityKey.get(locale.getDisplayLanguage(), langId)); } else { languages.add(EntityKey.get(langId, langId)); } } LanguageList languageList = new LanguageList(); languageList.setLanguages(languages); languageList.setDefaultLanguage(defaultLanguageIndex); return languageList; }
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/*w w w . java 2 s . 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:com.baidu.jprotobuf.rpc.client.SimpleHttpRequestExecutor.java
/** * Prepare the given HTTP connection./* www. j a v a 2 s. co 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: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// w w w . j a v a 2s .com * @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: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 www.j av a 2 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:org.squashtest.tm.service.internal.bugtracker.BugTrackersLocalServiceImpl.java
private LocaleContext getLocaleContext() { return LocaleContextHolder.getLocaleContext(); }
From source file:org.squashtest.tm.service.internal.bugtracker.ExecutionIssueFinder.java
/** * Fetches remote issues from remote bugtracker * * @param pairs execution-issue pairs which remote issues should be fetched * @param bugTracker non-null bugtracker where to fetch issues *///from ww w . jav a2 s. c o m private List<IssueOwnership<RemoteIssueDecorator>> findRemoteIssues( List<? extends Pair<? extends IssueDetector, Issue>> pairs, BugTracker bugTracker) { if (bugTracker == null || pairs.isEmpty()) { return Collections.emptyList(); } List<IssueOwnership<RemoteIssueDecorator>> ownerships; List<String> remoteIssueIds = IssueOwnershipFinderUtils.collectRemoteIssueIds(pairs); try { Future<List<RemoteIssue>> futureIssues = remoteBugTrackersService.getIssues(remoteIssueIds, bugTracker, contextHolder.getContext(), LocaleContextHolder.getLocaleContext()); List<RemoteIssue> btIssues = futureIssues.get(timeout, TimeUnit.SECONDS); Map<String, RemoteIssue> remoteById = IssueOwnershipFinderUtils .createRemoteIssueByRemoteIdMap(btIssues); ownerships = IssueOwnershipFinderUtils.coerceIntoIssueOwnerships(pairs, remoteById); } catch (TimeoutException | ExecutionException | InterruptedException ex) { throw new BugTrackerRemoteException(ex); } return ownerships; }