You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by Gary Gregory <ga...@gmail.com> on 2018/07/12 15:22:12 UTC

Porting URIBuilder call sites

Hi All,

I just had to port this 'nice' fluent code:

            final String uri = new URIBuilder()
                .setScheme(scheme)
                .setHost("localhost")
                .setUserInfo(userInfo)
                .setPort(proxyPort)
                .setPath(path)
                .setCustomQuery(queryParameterString)
                .build()
                .toString();

to:

            final URIBuilder builder = new URIBuilder()
                .setScheme(scheme)
                .setHost("localhost")
                .setPort(proxyPort)
                .setPath(path)
                .setCustomQuery(queryParameterString);
            if (StringUtils.isNotBlank(userInfo)) {
                builder.setUserInfo(userInfo);
            }
            final String uri = builder.build().toString();

To avoid an IllegalArgumentException when userInfo is "":

java.lang.IllegalArgumentException: User info may not be empty
at org.apache.hc.core5.util.Args.containsNoBlanks(Args.java:84)
at org.apache.hc.core5.net.URIAuthority.<init>(URIAuthority.java:73)
at
org.apache.hc.core5.http.message.BasicHttpRequest.setUri(BasicHttpRequest.java:172)
at
org.apache.hc.core5.http.message.BasicHttpRequest.<init>(BasicHttpRequest.java:102)
at
org.apache.hc.core5.http.message.BasicClassicHttpRequest.<init>(BasicClassicHttpRequest.java:77)
at
org.apache.hc.client5.http.classic.methods.HttpUriRequestBase.<init>(HttpUriRequestBase.java:48)
at
org.apache.hc.client5.http.classic.methods.RequestBuilder.build(RequestBuilder.java:482)
at
com.rs.seagull.httpmonitor.ClientTests.testHttpMethod(ClientTests.java:106)
...

I would be nice to still offer this fluent style when userInfo is null (and
even "")

Thoughts?

Gary

Re: Porting URIBuilder call sites

Posted by Gary Gregory <ga...@gmail.com>.
On Fri, Jul 13, 2018 at 12:38 PM Pascal Schumacher <pa...@gmx.net>
wrote:

> I guess this was send to the wrong mailing list?
>

Yep, sorry.

Gary

>
> Am 12.07.2018 um 17:22 schrieb Gary Gregory:
> > Hi All,
> >
> > I just had to port this 'nice' fluent code:
> >
> >              final String uri = new URIBuilder()
> >                  .setScheme(scheme)
> >                  .setHost("localhost")
> >                  .setUserInfo(userInfo)
> >                  .setPort(proxyPort)
> >                  .setPath(path)
> >                  .setCustomQuery(queryParameterString)
> >                  .build()
> >                  .toString();
> >
> > to:
> >
> >              final URIBuilder builder = new URIBuilder()
> >                  .setScheme(scheme)
> >                  .setHost("localhost")
> >                  .setPort(proxyPort)
> >                  .setPath(path)
> >                  .setCustomQuery(queryParameterString);
> >              if (StringUtils.isNotBlank(userInfo)) {
> >                  builder.setUserInfo(userInfo);
> >              }
> >              final String uri = builder.build().toString();
> >
> > To avoid an IllegalArgumentException when userInfo is "":
> >
> > java.lang.IllegalArgumentException: User info may not be empty
> > at org.apache.hc.core5.util.Args.containsNoBlanks(Args.java:84)
> > at org.apache.hc.core5.net.URIAuthority.<init>(URIAuthority.java:73)
> > at
> >
> org.apache.hc.core5.http.message.BasicHttpRequest.setUri(BasicHttpRequest.java:172)
> > at
> >
> org.apache.hc.core5.http.message.BasicHttpRequest.<init>(BasicHttpRequest.java:102)
> > at
> >
> org.apache.hc.core5.http.message.BasicClassicHttpRequest.<init>(BasicClassicHttpRequest.java:77)
> > at
> >
> org.apache.hc.client5.http.classic.methods.HttpUriRequestBase.<init>(HttpUriRequestBase.java:48)
> > at
> >
> org.apache.hc.client5.http.classic.methods.RequestBuilder.build(RequestBuilder.java:482)
> > at
> >
> com.rs.seagull.httpmonitor.ClientTests.testHttpMethod(ClientTests.java:106)
> > ...
> >
> > I would be nice to still offer this fluent style when userInfo is null
> (and
> > even "")
> >
> > Thoughts?
> >
> > Gary
> >
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
> For additional commands, e-mail: dev-help@commons.apache.org
>
>

Re: Porting URIBuilder call sites

Posted by Pascal Schumacher <pa...@gmx.net>.
I guess this was send to the wrong mailing list?

Am 12.07.2018 um 17:22 schrieb Gary Gregory:
> Hi All,
>
> I just had to port this 'nice' fluent code:
>
>              final String uri = new URIBuilder()
>                  .setScheme(scheme)
>                  .setHost("localhost")
>                  .setUserInfo(userInfo)
>                  .setPort(proxyPort)
>                  .setPath(path)
>                  .setCustomQuery(queryParameterString)
>                  .build()
>                  .toString();
>
> to:
>
>              final URIBuilder builder = new URIBuilder()
>                  .setScheme(scheme)
>                  .setHost("localhost")
>                  .setPort(proxyPort)
>                  .setPath(path)
>                  .setCustomQuery(queryParameterString);
>              if (StringUtils.isNotBlank(userInfo)) {
>                  builder.setUserInfo(userInfo);
>              }
>              final String uri = builder.build().toString();
>
> To avoid an IllegalArgumentException when userInfo is "":
>
> java.lang.IllegalArgumentException: User info may not be empty
> at org.apache.hc.core5.util.Args.containsNoBlanks(Args.java:84)
> at org.apache.hc.core5.net.URIAuthority.<init>(URIAuthority.java:73)
> at
> org.apache.hc.core5.http.message.BasicHttpRequest.setUri(BasicHttpRequest.java:172)
> at
> org.apache.hc.core5.http.message.BasicHttpRequest.<init>(BasicHttpRequest.java:102)
> at
> org.apache.hc.core5.http.message.BasicClassicHttpRequest.<init>(BasicClassicHttpRequest.java:77)
> at
> org.apache.hc.client5.http.classic.methods.HttpUriRequestBase.<init>(HttpUriRequestBase.java:48)
> at
> org.apache.hc.client5.http.classic.methods.RequestBuilder.build(RequestBuilder.java:482)
> at
> com.rs.seagull.httpmonitor.ClientTests.testHttpMethod(ClientTests.java:106)
> ...
>
> I would be nice to still offer this fluent style when userInfo is null (and
> even "")
>
> Thoughts?
>
> Gary
>


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org


Re: Fwd: Porting URIBuilder call sites

Posted by Gary Gregory <ga...@gmail.com>.
On Sat, Jul 14, 2018 at 4:14 AM Oleg Kalnichevski <ol...@apache.org> wrote:

> On Fri, 2018-07-13 at 13:03 -0600, Gary Gregory wrote:
> > Hi All,
> >
> > I just had to port this 'nice' fluent code:
> >
> >             final String uri = new URIBuilder()
> >                 .setScheme(scheme)
> >                 .setHost("localhost")
> >                 .setUserInfo(userInfo)
> >                 .setPort(proxyPort)
> >                 .setPath(path)
> >                 .setCustomQuery(queryParameterString)
> >                 .build()
> >                 .toString();
> >
> > to:
> >
> >             final URIBuilder builder = new URIBuilder()
> >                 .setScheme(scheme)
> >                 .setHost("localhost")
> >                 .setPort(proxyPort)
> >                 .setPath(path)
> >                 .setCustomQuery(queryParameterString);
> >             if (StringUtils.isNotBlank(userInfo)) {
> >                 builder.setUserInfo(userInfo);
> >             }
> >             final String uri = builder.build().toString();
> >
> > To avoid an IllegalArgumentException when userInfo is "":
>
> Corrected with
>
>
> https://git1-us-west.apache.org/repos/asf?p=httpcomponents-core.git;a=commit;h=c4342118
>
> Thank you Oleg!

Gary


> Oleg
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org
> For additional commands, e-mail: dev-help@hc.apache.org
>
>

Re: Fwd: Porting URIBuilder call sites

Posted by Oleg Kalnichevski <ol...@apache.org>.
On Fri, 2018-07-13 at 13:03 -0600, Gary Gregory wrote:
> Hi All,
> 
> I just had to port this 'nice' fluent code:
> 
>             final String uri = new URIBuilder()
>                 .setScheme(scheme)
>                 .setHost("localhost")
>                 .setUserInfo(userInfo)
>                 .setPort(proxyPort)
>                 .setPath(path)
>                 .setCustomQuery(queryParameterString)
>                 .build()
>                 .toString();
> 
> to:
> 
>             final URIBuilder builder = new URIBuilder()
>                 .setScheme(scheme)
>                 .setHost("localhost")
>                 .setPort(proxyPort)
>                 .setPath(path)
>                 .setCustomQuery(queryParameterString);
>             if (StringUtils.isNotBlank(userInfo)) {
>                 builder.setUserInfo(userInfo);
>             }
>             final String uri = builder.build().toString();
> 
> To avoid an IllegalArgumentException when userInfo is "":

Corrected with

https://git1-us-west.apache.org/repos/asf?p=httpcomponents-core.git;a=commit;h=c4342118

Oleg


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org
For additional commands, e-mail: dev-help@hc.apache.org


Fwd: Porting URIBuilder call sites

Posted by Gary Gregory <ga...@gmail.com>.
Hi All,

I just had to port this 'nice' fluent code:

            final String uri = new URIBuilder()
                .setScheme(scheme)
                .setHost("localhost")
                .setUserInfo(userInfo)
                .setPort(proxyPort)
                .setPath(path)
                .setCustomQuery(queryParameterString)
                .build()
                .toString();

to:

            final URIBuilder builder = new URIBuilder()
                .setScheme(scheme)
                .setHost("localhost")
                .setPort(proxyPort)
                .setPath(path)
                .setCustomQuery(queryParameterString);
            if (StringUtils.isNotBlank(userInfo)) {
                builder.setUserInfo(userInfo);
            }
            final String uri = builder.build().toString();

To avoid an IllegalArgumentException when userInfo is "":

java.lang.IllegalArgumentException: User info may not be empty
at org.apache.hc.core5.util.Args.containsNoBlanks(Args.java:84)
at org.apache.hc.core5.net.URIAuthority.<init>(URIAuthority.java:73)
at
org.apache.hc.core5.http.message.BasicHttpRequest.setUri(BasicHttpRequest.java:172)
at
org.apache.hc.core5.http.message.BasicHttpRequest.<init>(BasicHttpRequest.java:102)
at
org.apache.hc.core5.http.message.BasicClassicHttpRequest.<init>(BasicClassicHttpRequest.java:77)
at
org.apache.hc.client5.http.classic.methods.HttpUriRequestBase.<init>(HttpUriRequestBase.java:48)
at
org.apache.hc.client5.http.classic.methods.RequestBuilder.build(RequestBuilder.java:482)
at
com.rs.seagull.httpmonitor.ClientTests.testHttpMethod(ClientTests.java:106)
...

I would be nice to still offer this fluent style when userInfo is null (and
even "")

Thoughts?

Gary