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

[HttpClient] enum for methods?

Hi All,

In my apps, I usually have this enum, handy for parameterizing things like
tests.

/**
 * HTTP methods defined in RFC2616.
 *
 * TODO Rename class to RFC2616Method ?
 *
 * @author <a href="mailto:ggregory@rocketsoftware.com">Gary Gregory</a>
 */
public enum HttpMethod {
    OPTIONS {
        @Override
        public HttpUriRequest createHttpUriRequest(final URI uri) {
            return new HttpOptions(uri);
        }
    },
    GET {
        @Override
        public HttpUriRequest createHttpUriRequest(final URI uri) {
            return new HttpGet(uri);
        }
    },
    HEAD {
        @Override
        public HttpUriRequest createHttpUriRequest(final URI uri) {
            return new HttpHead(uri);
        }
    },
    PATCH {
        @Override
        public HttpUriRequest createHttpUriRequest(final URI uri) {
            return new HttpPatch(uri);
        }
    },
    POST {
        @Override
        public HttpUriRequest createHttpUriRequest(final URI uri) {
            return new HttpPost(uri);
        }
    },
    PUT {
        @Override
        public HttpUriRequest createHttpUriRequest(final URI uri) {
            return new HttpPut(uri);
        }
    },
    DELETE {
        @Override
        public HttpUriRequest createHttpUriRequest(final URI uri) {
            return new HttpDelete(uri);
        }
    },
    TRACE {
        @Override
        public HttpUriRequest createHttpUriRequest(final URI uri) {
            return new HttpTrace(uri);
        }
    };

    public abstract HttpUriRequest createHttpUriRequest(URI uri);
}

Any thoughts on adding this to HttpClient? nain or test jar?

Gary

Re: [HttpClient] enum for methods?

Posted by Gary Gregory <ga...@gmail.com>.
Thank you Oleg. I think we can consider this thread closed.

Gary

On Sat, Jul 14, 2018 at 4:41 AM Oleg Kalnichevski <ol...@apache.org> wrote:

> On Fri, 2018-07-13 at 13:40 -0600, Gary Gregory wrote:
> > On Fri, Jul 13, 2018 at 12:24 PM Oleg Kalnichevski <ol...@apache.org>
> > wrote:
> >
> > > On Fri, 2018-07-13 at 10:27 -0600, Gary Gregory wrote:
> > > >
> > >
> > > ...
> > >
> > > >
> > > > This is now in git master but I think I need another tweak: I
> > > > made
> > > > the
> > > > return type for HttpRequests the class HttpUriRequestBase instead
> > > > of
> > > > an
> > > > interface. I left ClassicHttpRequests to return
> > > > ClassicHttpRequest
> > > > but now
> > > > I wonder if it would not be more flexible to make it return
> > > > HttpUriRequestBase
> > > > as well. Thoughts?
> > > >
> > >
> > > Hi Gary
> > >
> > > I am sorry it was not quite clear what exactly I had meant. I just
> > > wanted to have a similar enum applicable to the async methods that
> > > use
> > > generic HttpRequest / HttpResponse classes.
> > >
> > > I tweaked your code slightly. Please have a look.
> > >
> >
> > Hi Oleg,
> >
> > Looks good.
> >
> > The remaining question is what should be the return type for
> > ClassicHttpRequests.create(URI):  ClassicHttpRequest or
> > HttpUriRequestBase?
> >
>
> I suppose it should have been HttpUriRequestBase. Corrected.
>
>
> http://git-wip-us.apache.org/repos/asf/httpcomponents-client/commit/0abadca8
>
> Oleg
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org
> For additional commands, e-mail: dev-help@hc.apache.org
>
>

Re: [HttpClient] enum for methods?

Posted by Oleg Kalnichevski <ol...@apache.org>.
On Fri, 2018-07-13 at 13:40 -0600, Gary Gregory wrote:
> On Fri, Jul 13, 2018 at 12:24 PM Oleg Kalnichevski <ol...@apache.org>
> wrote:
> 
> > On Fri, 2018-07-13 at 10:27 -0600, Gary Gregory wrote:
> > > 
> > 
> > ...
> > 
> > > 
> > > This is now in git master but I think I need another tweak: I
> > > made
> > > the
> > > return type for HttpRequests the class HttpUriRequestBase instead
> > > of
> > > an
> > > interface. I left ClassicHttpRequests to return
> > > ClassicHttpRequest
> > > but now
> > > I wonder if it would not be more flexible to make it return
> > > HttpUriRequestBase
> > > as well. Thoughts?
> > > 
> > 
> > Hi Gary
> > 
> > I am sorry it was not quite clear what exactly I had meant. I just
> > wanted to have a similar enum applicable to the async methods that
> > use
> > generic HttpRequest / HttpResponse classes.
> > 
> > I tweaked your code slightly. Please have a look.
> > 
> 
> Hi Oleg,
> 
> Looks good.
> 
> The remaining question is what should be the return type for
> ClassicHttpRequests.create(URI):  ClassicHttpRequest or
> HttpUriRequestBase?
> 

I suppose it should have been HttpUriRequestBase. Corrected.

http://git-wip-us.apache.org/repos/asf/httpcomponents-client/commit/0abadca8

Oleg

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


Re: [HttpClient] enum for methods?

Posted by Gary Gregory <ga...@gmail.com>.
On Fri, Jul 13, 2018 at 12:24 PM Oleg Kalnichevski <ol...@apache.org> wrote:

> On Fri, 2018-07-13 at 10:27 -0600, Gary Gregory wrote:
> >
>
> ...
>
> >
> > This is now in git master but I think I need another tweak: I made
> > the
> > return type for HttpRequests the class HttpUriRequestBase instead of
> > an
> > interface. I left ClassicHttpRequests to return ClassicHttpRequest
> > but now
> > I wonder if it would not be more flexible to make it return
> > HttpUriRequestBase
> > as well. Thoughts?
> >
>
> Hi Gary
>
> I am sorry it was not quite clear what exactly I had meant. I just
> wanted to have a similar enum applicable to the async methods that use
> generic HttpRequest / HttpResponse classes.
>
> I tweaked your code slightly. Please have a look.
>

Hi Oleg,

Looks good.

The remaining question is what should be the return type for
ClassicHttpRequests.create(URI):  ClassicHttpRequest or HttpUriRequestBase?

Thank you,
Gary


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

Re: [HttpClient] enum for methods?

Posted by Oleg Kalnichevski <ol...@apache.org>.
On Fri, 2018-07-13 at 10:27 -0600, Gary Gregory wrote:
> 

...

> 
> This is now in git master but I think I need another tweak: I made
> the
> return type for HttpRequests the class HttpUriRequestBase instead of
> an
> interface. I left ClassicHttpRequests to return ClassicHttpRequest
> but now
> I wonder if it would not be more flexible to make it return
> HttpUriRequestBase
> as well. Thoughts?
> 

Hi Gary

I am sorry it was not quite clear what exactly I had meant. I just
wanted to have a similar enum applicable to the async methods that use
generic HttpRequest / HttpResponse classes.

I tweaked your code slightly. Please have a look.

Oleg

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


Re: [HttpClient] enum for methods?

Posted by Gary Gregory <ga...@gmail.com>.
On Thu, Jul 12, 2018 at 6:15 PM Gary Gregory <ga...@gmail.com> wrote:

>
>
> On Thu, Jul 12, 2018 at 2:40 PM Oleg Kalnichevski <ol...@apache.org>
> wrote:
>
>> On Thu, 2018-07-12 at 09:35 -0600, Gary Gregory wrote:
>> > On Wed, Jul 11, 2018 at 3:18 PM Oleg Kalnichevski <ol...@apache.org>
>> > wrote:
>> >
>> > > On Wed, 2018-07-11 at 10:01 -0600, Gary Gregory wrote:
>> > > > On Wed, Jul 11, 2018 at 8:55 AM Oleg Kalnichevski <olegk@apache.o
>> > > > rg>
>> > > > wrote:
>> > > >
>> > > > > On Wed, 2018-07-11 at 08:40 -0600, Gary Gregory wrote:
>> > > > > > Hi All,
>> > > > > >
>> > > > > > In my apps, I usually have this enum, handy for
>> > > > > > parameterizing
>> > > > > > things
>> > > > > > like
>> > > > > > tests.
>> > > > > >
>> > > > >
>> > > > > There is already one called StandardMethods. Would that be
>> > > > > enough?
>> > > > >
>> > > >
>> > > > Yes :-) but I can add factory methods to create request objects
>> > > > as in
>> > > > my
>> > > > version (Using the version 5 interface instead of 4)? For
>> > > > example:
>> > > >
>> > >
>> > > This would make StandardMethods dependent on the classic I/O model,
>> > > which is not ideal in my option. What is wrong with just having a
>> > > factory class (which can be an enum if that suits you)?
>> > >
>> >
>> > So basically the enum I started this thread with but called
>> > ClassicHttpRequests
>> > (or  ClassicHttpRequestFactory) in HttpClient?
>> >
>>
>> ClassicHttpRequests works for me. Can you make HttpRequests for generic
>> requests as well?
>>
>
> Will do.
>

This is now in git master but I think I need another tweak: I made the
return type for HttpRequests the class HttpUriRequestBase instead of an
interface. I left ClassicHttpRequests to return ClassicHttpRequest but now
I wonder if it would not be more flexible to make it return HttpUriRequestBase
as well. Thoughts?

Gary


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

Re: [HttpClient] enum for methods?

Posted by Gary Gregory <ga...@gmail.com>.
I am also thinking that the enum StandardMethods should be renamed
to StandardMethod (singular); other enums we have are singular.

Gary

On Thu, Jul 12, 2018 at 6:15 PM Gary Gregory <ga...@gmail.com> wrote:

>
>
> On Thu, Jul 12, 2018 at 2:40 PM Oleg Kalnichevski <ol...@apache.org>
> wrote:
>
>> On Thu, 2018-07-12 at 09:35 -0600, Gary Gregory wrote:
>> > On Wed, Jul 11, 2018 at 3:18 PM Oleg Kalnichevski <ol...@apache.org>
>> > wrote:
>> >
>> > > On Wed, 2018-07-11 at 10:01 -0600, Gary Gregory wrote:
>> > > > On Wed, Jul 11, 2018 at 8:55 AM Oleg Kalnichevski <olegk@apache.o
>> > > > rg>
>> > > > wrote:
>> > > >
>> > > > > On Wed, 2018-07-11 at 08:40 -0600, Gary Gregory wrote:
>> > > > > > Hi All,
>> > > > > >
>> > > > > > In my apps, I usually have this enum, handy for
>> > > > > > parameterizing
>> > > > > > things
>> > > > > > like
>> > > > > > tests.
>> > > > > >
>> > > > >
>> > > > > There is already one called StandardMethods. Would that be
>> > > > > enough?
>> > > > >
>> > > >
>> > > > Yes :-) but I can add factory methods to create request objects
>> > > > as in
>> > > > my
>> > > > version (Using the version 5 interface instead of 4)? For
>> > > > example:
>> > > >
>> > >
>> > > This would make StandardMethods dependent on the classic I/O model,
>> > > which is not ideal in my option. What is wrong with just having a
>> > > factory class (which can be an enum if that suits you)?
>> > >
>> >
>> > So basically the enum I started this thread with but called
>> > ClassicHttpRequests
>> > (or  ClassicHttpRequestFactory) in HttpClient?
>> >
>>
>> ClassicHttpRequests works for me. Can you make HttpRequests for generic
>> requests as well?
>>
>
> Will do.
>
> Gary
>
>
>>
>> Oleg
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org
>> For additional commands, e-mail: dev-help@hc.apache.org
>>
>>

Re: [HttpClient] enum for methods?

Posted by Gary Gregory <ga...@gmail.com>.
On Thu, Jul 12, 2018 at 2:40 PM Oleg Kalnichevski <ol...@apache.org> wrote:

> On Thu, 2018-07-12 at 09:35 -0600, Gary Gregory wrote:
> > On Wed, Jul 11, 2018 at 3:18 PM Oleg Kalnichevski <ol...@apache.org>
> > wrote:
> >
> > > On Wed, 2018-07-11 at 10:01 -0600, Gary Gregory wrote:
> > > > On Wed, Jul 11, 2018 at 8:55 AM Oleg Kalnichevski <olegk@apache.o
> > > > rg>
> > > > wrote:
> > > >
> > > > > On Wed, 2018-07-11 at 08:40 -0600, Gary Gregory wrote:
> > > > > > Hi All,
> > > > > >
> > > > > > In my apps, I usually have this enum, handy for
> > > > > > parameterizing
> > > > > > things
> > > > > > like
> > > > > > tests.
> > > > > >
> > > > >
> > > > > There is already one called StandardMethods. Would that be
> > > > > enough?
> > > > >
> > > >
> > > > Yes :-) but I can add factory methods to create request objects
> > > > as in
> > > > my
> > > > version (Using the version 5 interface instead of 4)? For
> > > > example:
> > > >
> > >
> > > This would make StandardMethods dependent on the classic I/O model,
> > > which is not ideal in my option. What is wrong with just having a
> > > factory class (which can be an enum if that suits you)?
> > >
> >
> > So basically the enum I started this thread with but called
> > ClassicHttpRequests
> > (or  ClassicHttpRequestFactory) in HttpClient?
> >
>
> ClassicHttpRequests works for me. Can you make HttpRequests for generic
> requests as well?
>

Will do.

Gary


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

Re: [HttpClient] enum for methods?

Posted by Oleg Kalnichevski <ol...@apache.org>.
On Thu, 2018-07-12 at 09:35 -0600, Gary Gregory wrote:
> On Wed, Jul 11, 2018 at 3:18 PM Oleg Kalnichevski <ol...@apache.org>
> wrote:
> 
> > On Wed, 2018-07-11 at 10:01 -0600, Gary Gregory wrote:
> > > On Wed, Jul 11, 2018 at 8:55 AM Oleg Kalnichevski <olegk@apache.o
> > > rg>
> > > wrote:
> > > 
> > > > On Wed, 2018-07-11 at 08:40 -0600, Gary Gregory wrote:
> > > > > Hi All,
> > > > > 
> > > > > In my apps, I usually have this enum, handy for
> > > > > parameterizing
> > > > > things
> > > > > like
> > > > > tests.
> > > > > 
> > > > 
> > > > There is already one called StandardMethods. Would that be
> > > > enough?
> > > > 
> > > 
> > > Yes :-) but I can add factory methods to create request objects
> > > as in
> > > my
> > > version (Using the version 5 interface instead of 4)? For
> > > example:
> > > 
> > 
> > This would make StandardMethods dependent on the classic I/O model,
> > which is not ideal in my option. What is wrong with just having a
> > factory class (which can be an enum if that suits you)?
> > 
> 
> So basically the enum I started this thread with but called
> ClassicHttpRequests
> (or  ClassicHttpRequestFactory) in HttpClient?
> 

ClassicHttpRequests works for me. Can you make HttpRequests for generic
requests as well? 

Oleg

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


Re: [HttpClient] enum for methods?

Posted by Gary Gregory <ga...@gmail.com>.
On Wed, Jul 11, 2018 at 3:18 PM Oleg Kalnichevski <ol...@apache.org> wrote:

> On Wed, 2018-07-11 at 10:01 -0600, Gary Gregory wrote:
> > On Wed, Jul 11, 2018 at 8:55 AM Oleg Kalnichevski <ol...@apache.org>
> > wrote:
> >
> > > On Wed, 2018-07-11 at 08:40 -0600, Gary Gregory wrote:
> > > > Hi All,
> > > >
> > > > In my apps, I usually have this enum, handy for parameterizing
> > > > things
> > > > like
> > > > tests.
> > > >
> > >
> > > There is already one called StandardMethods. Would that be enough?
> > >
> >
> > Yes :-) but I can add factory methods to create request objects as in
> > my
> > version (Using the version 5 interface instead of 4)? For example:
> >
>
> This would make StandardMethods dependent on the classic I/O model,
> which is not ideal in my option. What is wrong with just having a
> factory class (which can be an enum if that suits you)?
>

So basically the enum I started this thread with but called
ClassicHttpRequests
(or  ClassicHttpRequestFactory) in HttpClient?

Gary

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

Re: [HttpClient] enum for methods?

Posted by Oleg Kalnichevski <ol...@apache.org>.
On Wed, 2018-07-11 at 10:01 -0600, Gary Gregory wrote:
> On Wed, Jul 11, 2018 at 8:55 AM Oleg Kalnichevski <ol...@apache.org>
> wrote:
> 
> > On Wed, 2018-07-11 at 08:40 -0600, Gary Gregory wrote:
> > > Hi All,
> > > 
> > > In my apps, I usually have this enum, handy for parameterizing
> > > things
> > > like
> > > tests.
> > > 
> > 
> > There is already one called StandardMethods. Would that be enough?
> > 
> 
> Yes :-) but I can add factory methods to create request objects as in
> my
> version (Using the version 5 interface instead of 4)? For example:
> 

This would make StandardMethods dependent on the classic I/O model,
which is not ideal in my option. What is wrong with just having a
factory class (which can be an enum if that suits you)?

Oleg


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


Re: [HttpClient] enum for methods?

Posted by Gary Gregory <ga...@gmail.com>.
On Wed, Jul 11, 2018 at 8:55 AM Oleg Kalnichevski <ol...@apache.org> wrote:

> On Wed, 2018-07-11 at 08:40 -0600, Gary Gregory wrote:
> > Hi All,
> >
> > In my apps, I usually have this enum, handy for parameterizing things
> > like
> > tests.
> >
>
> There is already one called StandardMethods. Would that be enough?
>

Yes :-) but I can add factory methods to create request objects as in my
version (Using the version 5 interface instead of 4)? For example:

    GET {
        @Override
        public ClassicHttpRequest createClassicHttpRequest(final URI uri) {
            return new HttpGet(uri);
        }
    }

?

Gary


>
> Oleg
>
>
> > /**
>  * HTTP methods defined in RFC2616.
> >  *
> >  * TODO Rename class to RFC2616Method ?
> >  *
> >  * @author <a href="mailto:ggregory@rocketsoftware.com">Gary
> > Gregory</a>
> >  */
> > public enum HttpMethod {
> >     OPTIONS {
> >         @Override
> >         public HttpUriRequest createHttpUriRequest(final URI uri) {
> >             return new HttpOptions(uri);
> >         }
> >     },
> >     GET {
> >         @Override
> >         public HttpUriRequest createHttpUriRequest(final URI uri) {
> >             return new HttpGet(uri);
> >         }
> >     },
> >     HEAD {
> >         @Override
> >         public HttpUriRequest createHttpUriRequest(final URI uri) {
> >             return new HttpHead(uri);
> >         }
> >     },
> >     PATCH {
> >         @Override
> >         public HttpUriRequest createHttpUriRequest(final URI uri) {
> >             return new HttpPatch(uri);
> >         }
> >     },
> >     POST {
> >         @Override
> >         public HttpUriRequest createHttpUriRequest(final URI uri) {
> >             return new HttpPost(uri);
> >         }
> >     },
> >     PUT {
> >         @Override
> >         public HttpUriRequest createHttpUriRequest(final URI uri) {
> >             return new HttpPut(uri);
> >         }
> >     },
> >     DELETE {
> >         @Override
> >         public HttpUriRequest createHttpUriRequest(final URI uri) {
> >             return new HttpDelete(uri);
> >         }
> >     },
> >     TRACE {
> >         @Override
> >         public HttpUriRequest createHttpUriRequest(final URI uri) {
> >             return new HttpTrace(uri);
> >         }
> >     };
> >
> >     public abstract HttpUriRequest createHttpUriRequest(URI uri);
> > }
> >
> > Any thoughts on adding this to HttpClient? nain or test jar?
> >
> > Gary
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org
> For additional commands, e-mail: dev-help@hc.apache.org
>
>

Re: [HttpClient] enum for methods?

Posted by Julian Reschke <ju...@gmx.de>.
On 2018-07-11 16:55, Oleg Kalnichevski wrote:
> On Wed, 2018-07-11 at 08:40 -0600, Gary Gregory wrote:
>> Hi All,
>>
>> In my apps, I usually have this enum, handy for parameterizing things
>> like
>> tests.
>>
> 
> There is already one called StandardMethods. Would that be enough?
> 
> Oleg

Methods are an extension point in the protocol, so an "enum" seems to be 
a bad idea here.

FWIW, what was the criterium for what methods are included in 
"StandardMethods"???

Best regards, Julian

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


Re: [HttpClient] enum for methods?

Posted by Oleg Kalnichevski <ol...@apache.org>.
On Wed, 2018-07-11 at 08:40 -0600, Gary Gregory wrote:
> Hi All,
> 
> In my apps, I usually have this enum, handy for parameterizing things
> like
> tests.
> 

There is already one called StandardMethods. Would that be enough?

Oleg


> /**
 * HTTP methods defined in RFC2616.
>  *
>  * TODO Rename class to RFC2616Method ?
>  *
>  * @author <a href="mailto:ggregory@rocketsoftware.com">Gary
> Gregory</a>
>  */
> public enum HttpMethod {
>     OPTIONS {
>         @Override
>         public HttpUriRequest createHttpUriRequest(final URI uri) {
>             return new HttpOptions(uri);
>         }
>     },
>     GET {
>         @Override
>         public HttpUriRequest createHttpUriRequest(final URI uri) {
>             return new HttpGet(uri);
>         }
>     },
>     HEAD {
>         @Override
>         public HttpUriRequest createHttpUriRequest(final URI uri) {
>             return new HttpHead(uri);
>         }
>     },
>     PATCH {
>         @Override
>         public HttpUriRequest createHttpUriRequest(final URI uri) {
>             return new HttpPatch(uri);
>         }
>     },
>     POST {
>         @Override
>         public HttpUriRequest createHttpUriRequest(final URI uri) {
>             return new HttpPost(uri);
>         }
>     },
>     PUT {
>         @Override
>         public HttpUriRequest createHttpUriRequest(final URI uri) {
>             return new HttpPut(uri);
>         }
>     },
>     DELETE {
>         @Override
>         public HttpUriRequest createHttpUriRequest(final URI uri) {
>             return new HttpDelete(uri);
>         }
>     },
>     TRACE {
>         @Override
>         public HttpUriRequest createHttpUriRequest(final URI uri) {
>             return new HttpTrace(uri);
>         }
>     };
> 
>     public abstract HttpUriRequest createHttpUriRequest(URI uri);
> }
> 
> Any thoughts on adding this to HttpClient? nain or test jar?
> 
> Gary

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