Ejemplo n.º 1
0
 AuthenticationCredentials updateCredentials() {
   // update configuration with latest values
   AuthenticationCredentials credentials = location.getCredentials(AuthenticationType.REPOSITORY);
   if (credentials != null) {
     Credentials httpCredentials =
         WebUtil.getHttpClientCredentials(credentials, WebUtil.getHost(location.getUrl()));
     httpClient.getState().setCredentials(authScope, httpCredentials);
     //			if (CoreUtil.TEST_MODE) {
     //				System.err.println(" Setting credentials: " + httpCredentials); //$NON-NLS-1$
     //			}
     httpClient.getState().setCredentials(authScope, httpCredentials);
   } else {
     httpClient.getState().clearCredentials();
   }
   return credentials;
 }
Ejemplo n.º 2
0
 public CommonXmlRpcClient(AbstractWebLocation location, HttpClient client) {
   this.location = location;
   this.httpClient = createHttpClient(DEFAULT_USER_AGENT);
   this.authScope =
       new AuthScope(
           WebUtil.getHost(location.getUrl()),
           WebUtil.getPort(location.getUrl()),
           null,
           AuthScope.ANY_SCHEME);
 }
Ejemplo n.º 3
0
  protected void createXmlRpcClient() {
    config = new XmlRpcClientConfigImpl();
    config.setEncoding(DEFAULT_CHARSET);
    config.setTimeZone(TimeZone.getTimeZone(DEFAULT_TIME_ZONE));
    config.setContentLengthOptional(false);
    config.setConnectionTimeout(WebUtil.getConnectionTimeout());
    config.setReplyTimeout(WebUtil.getSocketTimeout());

    xmlrpc = new XmlRpcClient();
    xmlrpc.setConfig(config);
    // bug 307200: force factory that supports proper UTF-8 encoding
    xmlrpc.setXmlWriterFactory(new CharSetXmlWriterFactory());

    factory = new HttpClientTransportFactory(xmlrpc, httpClient);
    factory.setLocation(location);
    factory.setInterceptor(
        new HttpMethodInterceptor() {
          public void processRequest(HttpMethod method) {
            DigestScheme scheme = digestScheme;
            if (scheme != null) {
              if (DEBUG_AUTH) {
                System.err.println(location.getUrl() + ": Digest scheme is present"); // $NON-NLS-1$
              }
              Credentials creds = httpClient.getState().getCredentials(authScope);
              if (creds != null) {
                if (DEBUG_AUTH) {
                  System.err.println(
                      location.getUrl() + ": Setting digest scheme for request"); // $NON-NLS-1$
                }
                method.getHostAuthState().setAuthScheme(digestScheme);
                method.getHostAuthState().setAuthRequested(true);
              }
            }
          }

          @SuppressWarnings("null")
          public void processResponse(HttpMethod method) throws XmlRpcException {
            if (isContentTypeCheckingEnabled()) {
              Header contentTypeHeader = method.getResponseHeader("Content-Type"); // $NON-NLS-1$
              if (contentTypeHeader == null
                  || !DEFAULT_CONTENT_TYPE.equals(contentTypeHeader.getValue())) {
                throw new XmlRpcIllegalContentTypeException(
                    NLS.bind(
                        "The server returned an unexpected content type: ''{0}''",
                        contentTypeHeader.getValue()),
                    contentTypeHeader.getValue()); // $NON-NLS-1$
              }
            }
            AuthScheme authScheme = method.getHostAuthState().getAuthScheme();
            if (authScheme instanceof DigestScheme) {
              digestScheme = (DigestScheme) authScheme;
              if (DEBUG_AUTH) {
                System.err.println(location.getUrl() + ": Received digest scheme"); // $NON-NLS-1$
              }
            }
          }
        });
    xmlrpc.setTransportFactory(factory);

    try {
      config.setServerURL(new URL(location.getUrl()));
    } catch (MalformedURLException e) {
      throw new RuntimeException(e);
    }
  }