Uploaded image for project: 'OpenShift Java Client'
  1. OpenShift Java Client
  2. OSJC-73

openshift-java-client: improve how userAgent is passed to UrlConnectionClient

    XMLWordPrintable

Details

    • Enhancement
    • Resolution: Duplicate
    • Minor
    • 2.2.0
    • None
    • None
    • None

    Description

      clarify how the user-agent is set to the UrlConnectionHttpClient.
      You can actually set it to the constructor but also by a setter:

      com.openshift.internal.client.httpclient.UrlConnectionHttpClient
      public UrlConnectionHttpClient(String username, String password, String userAgent, boolean sslChecks, IMediaType requestMediaType, String acceptedMediaType, String version, String authKey, String authIV) {
      
      com.openshift.internal.client.httpclient.UrlConnectionHttpClient
      public void setUserAgent(String userAgent) {
      	this.userAgent = userAgent;
      }
      

      Both variants are actually used in the library code:

      com.openshift.internal.client.RestService
      public RestService(String baseUrl, String clientId, IHttpClient client) {
      	this.baseUrl = UrlUtils.ensureStartsWithHttps(baseUrl);
      	this.client = client;
      	client.setUserAgent(new RestServiceProperties().getUseragent(clientId));
      
      com.openshift.client.OpenShiftConnectionFactory
      public IOpenShiftConnection getConnection(final String clientId, final String login, final String password,
      		final String authKey, final String authIV, final String serverUrl,
      		final boolean proxySet, final String proxyHost, final String proxyPort) throws OpenShiftException {
      	Assert.notNull(clientId);
      	Assert.notNull(login);
      	Assert.notNull(password);
      	Assert.notNull(serverUrl);
      	
      	if (proxySet) {
      		System.setProperty("proxyHost", proxyHost);
      		System.setProperty("proxyPort", proxyPort);
      	}
      
      	try {
      		final IHttpClient httpClient = new UrlConnectionHttpClientBuilder().setCredentials(login, password, authKey, authIV)
      				.client();
      		
      		final IRestService service = new RestService(serverUrl, clientId, httpClient);
      		return getConnection(service, login, password);
      	} catch (FileNotFoundException e) {
      		throw new OpenShiftException(e, "Failed to establish connection for user ''{0}}''", login);
      	} catch (IOException e) {
      		throw new OpenShiftException(e, "Failed to establish connection for user ''{0}}''", login);
      	}
      }
      

      Attachments

        Issue Links

          Activity

            People

              adietish@redhat.com André Dietisheim
              adietish@redhat.com André Dietisheim
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: