Changing Port

153 views
Skip to first unread message

Prinn

unread,
Aug 3, 2015, 12:09:07 PM8/3/15
to sardine
How do I change the port number to something different from port 80 (for HTTP) and 443 (for HTTPS)?
I know that the User guide states that I have to "override SardineImpl#createDefaultSchemeRegistry() or provide your own configured HTTP client instance by instantiating SardineImpl#SardineImpl(org.apache.http.impl.client.HttpClientBuilder)" 


However, I'm still not sure how would I set the port after taking a look at createDefaultSchemeRegistry() and HttpClientBuilder. Can someone please provide me with an example of how to do this?

Thanks.

ciberg

unread,
Jan 15, 2016, 10:56:05 AM1/15/16
to sardine
How come no one answers this?

I have the same problem and the User Guide doesn't help.

I searched several examples and still didn't find how can I define a port in HttpClientBuilder.

I have the following code but it's incomplete as I cannot define host and port.

      HttpClientBuilder builder = HttpClientBuilder.create();    
      SardineImpl sardine = new SardineImpl(builder, "user", "password");

Beowulf

unread,
Jul 23, 2016, 1:56:27 AM7/23/16
to sardine
Over a year later and still no examples of this. I cant believe this is such a pain to implement. It is quite common to set up services on ports other than the primary, so it is mind boggling that years later we still dont have any example of how we change the port. Both HttpClient and the SardineImpl approach do not have any example.. starting to think it was never possible.

Beowulf

unread,
Jul 23, 2016, 2:51:24 AM7/23/16
to sardine
OK.. this is my solution.. this seems to work for me. I dont know if it will work for everyone. This is using the latest Sardine which I believe is using HttpClient 4.5.x.

HttpClientBuilder builder = new HttpClientBuilder(){
@Override
public CloseableHttpClient build() {
SchemePortResolver spr = new SchemePortResolver() {
@Override
public int resolve(HttpHost httpHost) throws UnsupportedSchemeException {
return 8443; // SSL port to use
}
};

CloseableHttpClient httpclient = HttpClients.custom()
.useSystemProperties()
.setSchemePortResolver(spr)
.build();
return httpclient;
}
};

Sardine sardine = new SardineImpl(builder, "user", "passwd");

List<DavResource> resources = null;

resources = sardine.list("https://ftp-site.com/path/");
resources.forEach(resource -> {
  System.out.println(resource.getName());
}

Hope that helps somebody.
Reply all
Reply to author
Forward
0 new messages