From 6e38de82d91aed63e200f0b45f54a4a2a7875941 Mon Sep 17 00:00:00 2001 From: Simon Brandhof Date: Tue, 2 Aug 2011 15:35:47 +0200 Subject: SONAR-2665 Allow to override the HTTP parameter Accepted-Language in Java Web Service Client --- .../wsclient/connectors/HttpClient3Connector.java | 3 +++ .../wsclient/connectors/HttpClient4Connector.java | 3 +++ .../org/sonar/wsclient/services/AbstractQuery.java | 23 ++++++++++++++++++++++ 3 files changed, 29 insertions(+) (limited to 'sonar-ws-client') 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 { 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 *

@@ -74,6 +78,25 @@ public abstract class AbstractQuery { return this; } + /** + * 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 setLocale(String locale) { + this.locale = locale; + return this; + } + /** * Encodes single parameter value. */ -- cgit v1.2.3