diff options
Diffstat (limited to 'sonar-ws-client')
3 files changed, 29 insertions, 0 deletions
diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/connectors/HttpClient3Connector.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/connectors/HttpClient3Connector.java index 966095110bc..cb720320d7c 100644 --- a/sonar-ws-client/src/main/java/org/sonar/wsclient/connectors/HttpClient3Connector.java +++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/connectors/HttpClient3Connector.java @@ -149,6 +149,9 @@ public class HttpClient3Connector extends Connector { private void initRequest(HttpMethodBase request, AbstractQuery query) { request.setRequestHeader("Accept", "application/json"); + if (query.getLocale() != null) { + request.setRequestHeader("Accept-Language", query.getLocale()); + } request.getParams().setSoTimeout(query.getTimeoutMilliseconds()); } diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/connectors/HttpClient4Connector.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/connectors/HttpClient4Connector.java index 4044592a0ce..e1aebfd175e 100644 --- a/sonar-ws-client/src/main/java/org/sonar/wsclient/connectors/HttpClient4Connector.java +++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/connectors/HttpClient4Connector.java @@ -178,6 +178,9 @@ public class HttpClient4Connector extends Connector { private void initRequest(HttpRequestBase request, AbstractQuery query) { request.setHeader("Accept", "application/json"); + if (query.getLocale() != null) { + request.setHeader("Accept-Language", query.getLocale()); + } request.getParams().setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, query.getTimeoutMilliseconds()); request.getParams().setParameter(CoreConnectionPNames.SO_TIMEOUT, query.getTimeoutMilliseconds()); } diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/services/AbstractQuery.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/services/AbstractQuery.java index 141dd14fab3..ff9aed7ddd5 100644 --- a/sonar-ws-client/src/main/java/org/sonar/wsclient/services/AbstractQuery.java +++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/services/AbstractQuery.java @@ -20,6 +20,7 @@ package org.sonar.wsclient.services; import java.util.Date; +import java.util.Locale; /** * @since 2.2 @@ -35,6 +36,9 @@ public abstract class AbstractQuery<MODEL extends Model> { private int timeoutMilliseconds = DEFAULT_TIMEOUT_MILLISECONDS; + // accepted-language as defined in http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html + private String locale; + /** * Must start with a slash, for example: /api/metrics * <p> @@ -75,6 +79,25 @@ public abstract class AbstractQuery<MODEL extends Model> { } /** + * Accepted-language, as defined in http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html + * + * @since 2.10 + */ + public final String getLocale() { + return locale; + } + + /** + * Set the Accepted-language HTTP parameter + * + * @since 2.10 + */ + public final AbstractQuery<MODEL> setLocale(String locale) { + this.locale = locale; + return this; + } + + /** * Encodes single parameter value. */ protected static String encode(String value) { |