diff options
author | Simon Brandhof <simon.brandhof@gmail.com> | 2011-08-02 15:35:47 +0200 |
---|---|---|
committer | Simon Brandhof <simon.brandhof@gmail.com> | 2011-08-02 15:51:26 +0200 |
commit | 6e38de82d91aed63e200f0b45f54a4a2a7875941 (patch) | |
tree | cacf61310fe991b56400eeb93b1533adb184e5c7 | |
parent | 72b398d7145961d718eb92349f0d74e51626c013 (diff) | |
download | sonarqube-6e38de82d91aed63e200f0b45f54a4a2a7875941.tar.gz sonarqube-6e38de82d91aed63e200f0b45f54a4a2a7875941.zip |
SONAR-2665 Allow to override the HTTP parameter Accepted-Language in Java Web Service 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) { |