Author: adietish
Date: 2011-10-06 15:25:58 -0400 (Thu, 06 Oct 2011)
New Revision: 35431
Modified:
trunk/as/plugins/org.jboss.tools.openshift.express.client/src/org/jboss/tools/openshift/express/client/IHttpClient.java
trunk/as/plugins/org.jboss.tools.openshift.express.client/src/org/jboss/tools/openshift/express/client/OpenshiftService.java
trunk/as/plugins/org.jboss.tools.openshift.express.client/src/org/jboss/tools/openshift/express/client/User.java
trunk/as/plugins/org.jboss.tools.openshift.express.client/src/org/jboss/tools/openshift/express/internal/client/InternalUser.java
trunk/as/plugins/org.jboss.tools.openshift.express.client/src/org/jboss/tools/openshift/express/internal/client/httpclient/UrlConnectionHttpClient.java
trunk/as/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/CredentialsWizardPageModel.java
trunk/as/tests/org.jboss.tools.openshift.express.client.test/src/org/jboss/tools/openshift/express/internal/client/test/ApplicationIntegrationTest.java
trunk/as/tests/org.jboss.tools.openshift.express.client.test/src/org/jboss/tools/openshift/express/internal/client/test/ApplicationLogReaderIntegrationTest.java
trunk/as/tests/org.jboss.tools.openshift.express.client.test/src/org/jboss/tools/openshift/express/internal/client/test/CartridgesIntegrationTest.java
trunk/as/tests/org.jboss.tools.openshift.express.client.test/src/org/jboss/tools/openshift/express/internal/client/test/DomainIntegrationTest.java
trunk/as/tests/org.jboss.tools.openshift.express.client.test/src/org/jboss/tools/openshift/express/internal/client/test/ListCartridgesIntegrationTest.java
trunk/as/tests/org.jboss.tools.openshift.express.client.test/src/org/jboss/tools/openshift/express/internal/client/test/UserInfoIntegrationTest.java
trunk/as/tests/org.jboss.tools.openshift.express.client.test/src/org/jboss/tools/openshift/express/internal/client/test/UserIntegrationTest.java
trunk/as/tests/org.jboss.tools.openshift.express.client.test/src/org/jboss/tools/openshift/express/internal/client/test/fakes/TestUser.java
Log:
[JBIDE-9857] added user agent parameter to the user objects, the service and http client
Modified:
trunk/as/plugins/org.jboss.tools.openshift.express.client/src/org/jboss/tools/openshift/express/client/IHttpClient.java
===================================================================
---
trunk/as/plugins/org.jboss.tools.openshift.express.client/src/org/jboss/tools/openshift/express/client/IHttpClient.java 2011-10-06
19:13:20 UTC (rev 35430)
+++
trunk/as/plugins/org.jboss.tools.openshift.express.client/src/org/jboss/tools/openshift/express/client/IHttpClient.java 2011-10-06
19:25:58 UTC (rev 35431)
@@ -17,6 +17,8 @@
*/
public interface IHttpClient {
+ public static final String USER_AGENT = "User-Agent"; //$NON-NLS-1$
+
public String post(String data) throws HttpClientException;
public String get() throws HttpClientException;
Modified:
trunk/as/plugins/org.jboss.tools.openshift.express.client/src/org/jboss/tools/openshift/express/client/OpenshiftService.java
===================================================================
---
trunk/as/plugins/org.jboss.tools.openshift.express.client/src/org/jboss/tools/openshift/express/client/OpenshiftService.java 2011-10-06
19:13:20 UTC (rev 35430)
+++
trunk/as/plugins/org.jboss.tools.openshift.express.client/src/org/jboss/tools/openshift/express/client/OpenshiftService.java 2011-10-06
19:25:58 UTC (rev 35431)
@@ -47,12 +47,14 @@
public class OpenshiftService implements IOpenshiftService {
private String baseUrl;
-
- public OpenshiftService() {
- this(BASE_URL);
+ private String id;
+
+ public OpenshiftService(String id) {
+ this(id, BASE_URL);
}
- public OpenshiftService(String baseUrl) {
+ public OpenshiftService(String id, String baseUrl) {
+ this.id = id;
this.baseUrl = baseUrl;
}
@@ -79,7 +81,7 @@
String requestString = new UserInfoRequestJsonMarshaller().marshall(request);
String openShiftRequestString = new OpenshiftEnvelopeFactory(user.getPassword(),
requestString)
.createString();
- String responseString = createHttpClient(url).post(openShiftRequestString);
+ String responseString = createHttpClient(id, url).post(openShiftRequestString);
responseString = JsonSanitizer.sanitize(responseString);
OpenshiftResponse<UserInfo> response =
new UserInfoResponseUnmarshaller().unmarshall(responseString);
@@ -106,7 +108,7 @@
new ListCartridgesRequestJsonMarshaller().marshall(listCartridgesRequest);
String request = new OpenshiftEnvelopeFactory(user.getPassword(),
listCartridgesRequestString)
.createString();
- String listCatridgesReponse = createHttpClient(url).post(request);
+ String listCatridgesReponse = createHttpClient(id, url).post(request);
listCatridgesReponse = JsonSanitizer.sanitize(listCatridgesReponse);
OpenshiftResponse<List<ICartridge>> response =
new ListCartridgesResponseUnmarshaller().unmarshall(listCatridgesReponse);
@@ -141,7 +143,7 @@
user.getPassword(),
new DomainRequestJsonMarshaller().marshall(request))
.createString();
- String responseString = createHttpClient(url).post(requestString);
+ String responseString = createHttpClient(id, url).post(requestString);
responseString = JsonSanitizer.sanitize(responseString);
OpenshiftResponse<IDomain> response =
new DomainResponseUnmarshaller(request.getName(), user,
this).unmarshall(responseString);
@@ -203,7 +205,7 @@
String applicationRequestString =
new ApplicationRequestJsonMarshaller().marshall(applicationRequest);
String request = new OpenshiftEnvelopeFactory(user.getPassword(),
applicationRequestString).createString();
- String response = createHttpClient(url).post(request);
+ String response = createHttpClient(id, url).post(request);
response = JsonSanitizer.sanitize(response);
OpenshiftResponse<String> openshiftResponse =
@@ -231,7 +233,7 @@
String applicationRequestString =
new ApplicationRequestJsonMarshaller().marshall(applicationRequest);
String request = new OpenshiftEnvelopeFactory(user.getPassword(),
applicationRequestString).createString();
- String response = createHttpClient(url).post(request);
+ String response = createHttpClient(id, url).post(request);
response = JsonSanitizer.sanitize(response);
OpenshiftResponse<Application> openshiftResponse =
@@ -253,7 +255,7 @@
}
}
- private IHttpClient createHttpClient(String url) throws MalformedURLException {
- return new UrlConnectionHttpClient(new URL(url));
+ private IHttpClient createHttpClient(String id, String url) throws MalformedURLException
{
+ return new UrlConnectionHttpClient(id, new URL(url));
}
}
Modified:
trunk/as/plugins/org.jboss.tools.openshift.express.client/src/org/jboss/tools/openshift/express/client/User.java
===================================================================
---
trunk/as/plugins/org.jboss.tools.openshift.express.client/src/org/jboss/tools/openshift/express/client/User.java 2011-10-06
19:13:20 UTC (rev 35430)
+++
trunk/as/plugins/org.jboss.tools.openshift.express.client/src/org/jboss/tools/openshift/express/client/User.java 2011-10-06
19:25:58 UTC (rev 35431)
@@ -17,11 +17,11 @@
*/
public class User extends InternalUser {
- public User(String rhlogin, String password) {
- super(rhlogin, password);
+ public User(String rhlogin, String password, String id) {
+ super(rhlogin, password, id);
}
- protected User(String rhlogin, String password, String url) {
- super(rhlogin, password, url);
+ protected User(String rhlogin, String password, String id, String url) {
+ super(rhlogin, password, id, url);
}
}
Modified:
trunk/as/plugins/org.jboss.tools.openshift.express.client/src/org/jboss/tools/openshift/express/internal/client/InternalUser.java
===================================================================
---
trunk/as/plugins/org.jboss.tools.openshift.express.client/src/org/jboss/tools/openshift/express/internal/client/InternalUser.java 2011-10-06
19:13:20 UTC (rev 35430)
+++
trunk/as/plugins/org.jboss.tools.openshift.express.client/src/org/jboss/tools/openshift/express/internal/client/InternalUser.java 2011-10-06
19:25:58 UTC (rev 35431)
@@ -43,20 +43,20 @@
private IOpenshiftService service;
- public InternalUser(String password) throws OpenshiftException, IOException {
- this(new UserConfiguration(), password);
+ public InternalUser(String password, String id) throws OpenshiftException, IOException
{
+ this(new UserConfiguration(), password, id);
}
- public InternalUser(UserConfiguration configuration, String password) {
- this(configuration.getRhlogin(), password, (ISSHPublicKey) null, new
OpenshiftService());
+ public InternalUser(UserConfiguration configuration, String password, String id) {
+ this(configuration.getRhlogin(), password, (ISSHPublicKey) null, new
OpenshiftService(id));
}
- public InternalUser(String rhlogin, String password) {
- this(rhlogin, password, (ISSHPublicKey) null, new OpenshiftService());
+ public InternalUser(String rhlogin, String password, String id) {
+ this(rhlogin, password, (ISSHPublicKey) null, new OpenshiftService(id));
}
- public InternalUser(String rhlogin, String password, String url) {
- this(rhlogin, password, (ISSHPublicKey) null, new OpenshiftService(url));
+ public InternalUser(String rhlogin, String password, String id, String url) {
+ this(rhlogin, password, (ISSHPublicKey) null, new OpenshiftService(id, url));
}
public InternalUser(String rhlogin, String password, IOpenshiftService service) {
Modified:
trunk/as/plugins/org.jboss.tools.openshift.express.client/src/org/jboss/tools/openshift/express/internal/client/httpclient/UrlConnectionHttpClient.java
===================================================================
---
trunk/as/plugins/org.jboss.tools.openshift.express.client/src/org/jboss/tools/openshift/express/internal/client/httpclient/UrlConnectionHttpClient.java 2011-10-06
19:13:20 UTC (rev 35430)
+++
trunk/as/plugins/org.jboss.tools.openshift.express.client/src/org/jboss/tools/openshift/express/internal/client/httpclient/UrlConnectionHttpClient.java 2011-10-06
19:25:58 UTC (rev 35431)
@@ -28,15 +28,17 @@
private static final int TIMEOUT = 10 * 1024;
private URL url;
+ private String userAgent;
- public UrlConnectionHttpClient(URL url) {
+ public UrlConnectionHttpClient(String userAgent, URL url) {
+ this.userAgent = userAgent;
this.url = url;
}
public String post(String data) throws HttpClientException {
HttpURLConnection connection = null;
try {
- connection = createConnection(url);
+ connection = createConnection(userAgent, url);
connection.setDoOutput(true);
StreamUtils.writeTo(data.getBytes(), connection.getOutputStream());
return StreamUtils.readToString(connection.getInputStream());
@@ -55,7 +57,7 @@
public String get() throws HttpClientException {
HttpURLConnection connection = null;
try {
- connection = createConnection(url);
+ connection = createConnection(userAgent, url);
return StreamUtils.readToString(connection.getInputStream());
} catch (FileNotFoundException e) {
throw new NotFoundException(
@@ -88,7 +90,7 @@
}
}
- private HttpURLConnection createConnection(URL url) throws IOException {
+ private HttpURLConnection createConnection(String userAgent, URL url) throws IOException
{
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setUseCaches(false);
connection.setDoInput(true);
@@ -96,6 +98,10 @@
connection.setConnectTimeout(TIMEOUT);
connection.setRequestProperty(PROPERTY_CONTENT_TYPE,
"application/x-www-form-urlencoded");
connection.setInstanceFollowRedirects(true);
+ if (userAgent != null
+ && userAgent.length() > 0) {
+ connection.setRequestProperty(USER_AGENT, userAgent);
+ }
return connection;
}
}
Modified:
trunk/as/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/CredentialsWizardPageModel.java
===================================================================
---
trunk/as/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/CredentialsWizardPageModel.java 2011-10-06
19:13:20 UTC (rev 35430)
+++
trunk/as/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/CredentialsWizardPageModel.java 2011-10-06
19:25:58 UTC (rev 35431)
@@ -27,6 +27,8 @@
*/
public class CredentialsWizardPageModel extends ObservableUIPojo {
+ private static final String ID = OpenshiftUIActivator.PLUGIN_ID;
+
private static final String RHLOGIN_PREFS_KEY =
"org.jboss.tools.openshift.express.internal.ui.wizard.CredentialsWizardModel_RHLOGIN";
public static final String PROPERTY_SERVER_URL = "serverUrl";
@@ -120,7 +122,7 @@
public void validateCredentials() {
IStatus status = new Status(IStatus.ERROR, OpenshiftUIActivator.PLUGIN_ID, "Your
credentails are not valid.");
try {
- this.user = new User(getRhLogin(), getPassword());
+ this.user = new User(getRhLogin(), getPassword(), ID);
if (user.isValid()) {
status = Status.OK_STATUS;
}
Modified:
trunk/as/tests/org.jboss.tools.openshift.express.client.test/src/org/jboss/tools/openshift/express/internal/client/test/ApplicationIntegrationTest.java
===================================================================
---
trunk/as/tests/org.jboss.tools.openshift.express.client.test/src/org/jboss/tools/openshift/express/internal/client/test/ApplicationIntegrationTest.java 2011-10-06
19:13:20 UTC (rev 35430)
+++
trunk/as/tests/org.jboss.tools.openshift.express.client.test/src/org/jboss/tools/openshift/express/internal/client/test/ApplicationIntegrationTest.java 2011-10-06
19:25:58 UTC (rev 35431)
@@ -44,7 +44,7 @@
@Before
public void setUp() {
- this.service = new OpenshiftService();
+ this.service = new OpenshiftService(TestUser.ID);
this.user = new TestUser();
this.invalidUser = new TestUser("bogusPassword");
}
Modified:
trunk/as/tests/org.jboss.tools.openshift.express.client.test/src/org/jboss/tools/openshift/express/internal/client/test/ApplicationLogReaderIntegrationTest.java
===================================================================
---
trunk/as/tests/org.jboss.tools.openshift.express.client.test/src/org/jboss/tools/openshift/express/internal/client/test/ApplicationLogReaderIntegrationTest.java 2011-10-06
19:13:20 UTC (rev 35430)
+++
trunk/as/tests/org.jboss.tools.openshift.express.client.test/src/org/jboss/tools/openshift/express/internal/client/test/ApplicationLogReaderIntegrationTest.java 2011-10-06
19:25:58 UTC (rev 35431)
@@ -40,7 +40,7 @@
@Before
public void setUp() {
- this.service = new OpenshiftService();
+ this.service = new OpenshiftService(TestUser.ID);
this.user = new TestUser();
}
Modified:
trunk/as/tests/org.jboss.tools.openshift.express.client.test/src/org/jboss/tools/openshift/express/internal/client/test/CartridgesIntegrationTest.java
===================================================================
---
trunk/as/tests/org.jboss.tools.openshift.express.client.test/src/org/jboss/tools/openshift/express/internal/client/test/CartridgesIntegrationTest.java 2011-10-06
19:13:20 UTC (rev 35430)
+++
trunk/as/tests/org.jboss.tools.openshift.express.client.test/src/org/jboss/tools/openshift/express/internal/client/test/CartridgesIntegrationTest.java 2011-10-06
19:25:58 UTC (rev 35431)
@@ -34,7 +34,7 @@
@Before
public void setUp() {
- this.openshiftService = new OpenshiftService();
+ this.openshiftService = new OpenshiftService(TestUser.ID);
this.user = new TestUser();
}
Modified:
trunk/as/tests/org.jboss.tools.openshift.express.client.test/src/org/jboss/tools/openshift/express/internal/client/test/DomainIntegrationTest.java
===================================================================
---
trunk/as/tests/org.jboss.tools.openshift.express.client.test/src/org/jboss/tools/openshift/express/internal/client/test/DomainIntegrationTest.java 2011-10-06
19:13:20 UTC (rev 35430)
+++
trunk/as/tests/org.jboss.tools.openshift.express.client.test/src/org/jboss/tools/openshift/express/internal/client/test/DomainIntegrationTest.java 2011-10-06
19:25:58 UTC (rev 35431)
@@ -29,7 +29,7 @@
@Before
public void setUp() {
- this.openshiftService = new OpenshiftService();
+ this.openshiftService = new OpenshiftService(TestUser.ID);
this.user = new TestUser();
}
Modified:
trunk/as/tests/org.jboss.tools.openshift.express.client.test/src/org/jboss/tools/openshift/express/internal/client/test/ListCartridgesIntegrationTest.java
===================================================================
---
trunk/as/tests/org.jboss.tools.openshift.express.client.test/src/org/jboss/tools/openshift/express/internal/client/test/ListCartridgesIntegrationTest.java 2011-10-06
19:13:20 UTC (rev 35430)
+++
trunk/as/tests/org.jboss.tools.openshift.express.client.test/src/org/jboss/tools/openshift/express/internal/client/test/ListCartridgesIntegrationTest.java 2011-10-06
19:25:58 UTC (rev 35431)
@@ -32,7 +32,7 @@
@Before
public void setUp() {
- this.openshiftService = new OpenshiftService();
+ this.openshiftService = new OpenshiftService(TestUser.ID);
this.user = new TestUser();
}
Modified:
trunk/as/tests/org.jboss.tools.openshift.express.client.test/src/org/jboss/tools/openshift/express/internal/client/test/UserInfoIntegrationTest.java
===================================================================
---
trunk/as/tests/org.jboss.tools.openshift.express.client.test/src/org/jboss/tools/openshift/express/internal/client/test/UserInfoIntegrationTest.java 2011-10-06
19:13:20 UTC (rev 35430)
+++
trunk/as/tests/org.jboss.tools.openshift.express.client.test/src/org/jboss/tools/openshift/express/internal/client/test/UserInfoIntegrationTest.java 2011-10-06
19:25:58 UTC (rev 35431)
@@ -40,7 +40,7 @@
@Before
public void setUp() {
- this.openshiftService = new OpenshiftService();
+ this.openshiftService = new OpenshiftService(TestUser.ID);
this.user = new TestUser();
}
Modified:
trunk/as/tests/org.jboss.tools.openshift.express.client.test/src/org/jboss/tools/openshift/express/internal/client/test/UserIntegrationTest.java
===================================================================
---
trunk/as/tests/org.jboss.tools.openshift.express.client.test/src/org/jboss/tools/openshift/express/internal/client/test/UserIntegrationTest.java 2011-10-06
19:13:20 UTC (rev 35430)
+++
trunk/as/tests/org.jboss.tools.openshift.express.client.test/src/org/jboss/tools/openshift/express/internal/client/test/UserIntegrationTest.java 2011-10-06
19:25:58 UTC (rev 35431)
@@ -132,7 +132,7 @@
assertEquals(numOfApplications + 1, applications.size());
assertApplication(applicationName, ICartridge.JBOSSAS_7.getName(), application);
} finally {
- ApplicationUtils.silentlyDestroyAS7Application(applicationName, user, new
OpenshiftService());
+ ApplicationUtils.silentlyDestroyAS7Application(applicationName, user, new
OpenshiftService(TestUser.ID));
}
}
@@ -145,7 +145,7 @@
assertNotNull(applicationFound);
assertEquals(application, applicationFound);
} finally {
- ApplicationUtils.silentlyDestroyAS7Application(applicationName, user, new
OpenshiftService());
+ ApplicationUtils.silentlyDestroyAS7Application(applicationName, user, new
OpenshiftService(TestUser.ID));
}
}
}
Modified:
trunk/as/tests/org.jboss.tools.openshift.express.client.test/src/org/jboss/tools/openshift/express/internal/client/test/fakes/TestUser.java
===================================================================
---
trunk/as/tests/org.jboss.tools.openshift.express.client.test/src/org/jboss/tools/openshift/express/internal/client/test/fakes/TestUser.java 2011-10-06
19:13:20 UTC (rev 35430)
+++
trunk/as/tests/org.jboss.tools.openshift.express.client.test/src/org/jboss/tools/openshift/express/internal/client/test/fakes/TestUser.java 2011-10-06
19:25:58 UTC (rev 35431)
@@ -21,6 +21,8 @@
*/
public class TestUser extends User {
+ public static final String ID =
"org.jboss.tools.openshift.express.client.test";
+
public static final String RHLOGIN_USER_WITHOUT_DOMAIN =
"toolsjboss.no.domain2(a)gmail.com";
public static final String PASSWORD_USER_WITHOUT_DOMAIN = "1q2w3e";
@@ -28,19 +30,19 @@
public static final String PASSWORD = "1q2w3e";
public TestUser() {
- super(RHLOGIN, PASSWORD);
+ super(RHLOGIN, PASSWORD,ID);
}
public TestUser(String password) {
- super(RHLOGIN, password);
+ super(RHLOGIN, password, ID);
}
public TestUser(String rhlogin, String password) {
- super(rhlogin, password);
+ super(rhlogin, password, ID);
}
public TestUser(String rhlogin, String password, String url) {
- super(rhlogin, password, url);
+ super(rhlogin, password, ID, url);
}
public IApplication createTestApplication() throws OpenshiftException {