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 2015/11/30 19:53:07 UTC

Better header API

I'd like to apply this patch:


-- 
E-Mail: garydgregory@gmail.com | ggregory@apache.org
Java Persistence with Hibernate, Second Edition
<http://www.manning.com/bauer3/>
JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
Spring Batch in Action <http://www.manning.com/templier/>
Blog: http://garygregory.wordpress.com
Home: http://garygregory.com/
Tweet! http://twitter.com/GaryGregory

Re: Better header API

Posted by sebb <se...@gmail.com>.
On 30 November 2015 at 21:43, Michael Osipov <mi...@apache.org> wrote:
> Am 2015-11-30 um 19:53 schrieb Gary Gregory:
>>
>> I mean:
>>
>> Index: src/main/java/org/apache/hc/core5/http/HttpMessage.java
>> ===================================================================
>> --- src/main/java/org/apache/hc/core5/http/HttpMessage.java (revision
>> 1717301)
>> +++ src/main/java/org/apache/hc/core5/http/HttpMessage.java (working copy)
>> @@ -55,7 +55,7 @@
>>        * @param name the name of the header.
>>        * @param value the value of the header.
>>        */
>> -    void addHeader(String name, String value);
>> +    void addHeader(String name, Object value);
>>
>>       /**
>>        * Overwrites the first header with the same name. The new header
>> will
>> be appended to
>> @@ -72,7 +72,7 @@
>>        * @param name the name of the header.
>>        * @param value the value of the header.
>>        */
>> -    void setHeader(String name, String value);
>> +    void setHeader(String name, Object value);
>>
>>       /**
>>        * Overwrites all the headers in the message.
>> Index:
>> src/main/java/org/apache/hc/core5/http/message/AbstractHttpMessage.java
>> ===================================================================
>> ---
>> src/main/java/org/apache/hc/core5/http/message/AbstractHttpMessage.java
>> (revision
>> 1717301)
>> +++
>> src/main/java/org/apache/hc/core5/http/message/AbstractHttpMessage.java
>> (working
>> copy)
>> @@ -43,13 +43,13 @@
>>       private HttpEntity entity;
>>
>>       @Override
>> -    public void addHeader(final String name, final String value) {
>> +    public void addHeader(final String name, final Object value) {
>>           Args.notNull(name, "Header name");
>>           addHeader(new BasicHeader(name, value));
>>       }
>>
>>       @Override
>> -    public void setHeader(final String name, final String value) {
>> +    public void setHeader(final String name, final Object value) {
>>           Args.notNull(name, "Header name");
>>           setHeader(new BasicHeader(name, value));
>>       }
>> Index: src/main/java/org/apache/hc/core5/http/message/BasicHeader.java
>> ===================================================================
>> --- src/main/java/org/apache/hc/core5/http/message/BasicHeader.java
>> (revision
>> 1717301)
>> +++ src/main/java/org/apache/hc/core5/http/message/BasicHeader.java
>> (working
>> copy)
>> @@ -28,6 +28,7 @@
>>   package org.apache.hc.core5.http.message;
>>
>>   import java.io.Serializable;
>> +import java.util.Objects;
>>
>>   import org.apache.hc.core5.annotation.Immutable;
>>   import org.apache.hc.core5.http.Header;
>> @@ -55,10 +56,10 @@
>>        * @param name the header name
>>        * @param value the header value
>>        */
>> -    public BasicHeader(final String name, final String value) {
>> +    public BasicHeader(final String name, final Object value) {
>>           super();
>>           this.name = Args.notNull(name, "Name");
>> -        this.value = value;
>> +        this.value = Objects.toString(value, null);
>>       }
>>
>>       @Override
>>
>> Thoughts?
>
>
> Gary,
>
> what benefit do you expect from this patch? If I would read the new code, I
> would expect some magic which would auto-convert compatible types to its
> HTTP header counterparts. E.g., numbers, dates, lists, etc.
> Which you obviously don't. If you don't plan to add that, you should at
> least extend the Javadoc and say you relief the caller from the #toString
> burden. No more, no less.

+1

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

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


Re: Better header API

Posted by Gary Gregory <ga...@gmail.com>.
On Tue, Dec 1, 2015 at 4:07 AM, Michael Osipov <mi...@apache.org> wrote:

> Am 2015-12-01 um 02:22 schrieb Gary Gregory:
>
>> On Mon, Nov 30, 2015 at 1:43 PM, Michael Osipov <mi...@apache.org>
>> wrote:
>>
>> Am 2015-11-30 um 19:53 schrieb Gary Gregory:
>>>
>>> I mean:
>>>>
>>>> Index: src/main/java/org/apache/hc/core5/http/HttpMessage.java
>>>> ===================================================================
>>>> --- src/main/java/org/apache/hc/core5/http/HttpMessage.java (revision
>>>> 1717301)
>>>> +++ src/main/java/org/apache/hc/core5/http/HttpMessage.java (working
>>>> copy)
>>>> @@ -55,7 +55,7 @@
>>>>         * @param name the name of the header.
>>>>         * @param value the value of the header.
>>>>         */
>>>> -    void addHeader(String name, String value);
>>>> +    void addHeader(String name, Object value);
>>>>
>>>>        /**
>>>>         * Overwrites the first header with the same name. The new header
>>>> will
>>>> be appended to
>>>> @@ -72,7 +72,7 @@
>>>>         * @param name the name of the header.
>>>>         * @param value the value of the header.
>>>>         */
>>>> -    void setHeader(String name, String value);
>>>> +    void setHeader(String name, Object value);
>>>>
>>>>        /**
>>>>         * Overwrites all the headers in the message.
>>>> Index:
>>>> src/main/java/org/apache/hc/core5/http/message/AbstractHttpMessage.java
>>>> ===================================================================
>>>> ---
>>>> src/main/java/org/apache/hc/core5/http/message/AbstractHttpMessage.java
>>>> (revision
>>>> 1717301)
>>>> +++
>>>> src/main/java/org/apache/hc/core5/http/message/AbstractHttpMessage.java
>>>> (working
>>>> copy)
>>>> @@ -43,13 +43,13 @@
>>>>        private HttpEntity entity;
>>>>
>>>>        @Override
>>>> -    public void addHeader(final String name, final String value) {
>>>> +    public void addHeader(final String name, final Object value) {
>>>>            Args.notNull(name, "Header name");
>>>>            addHeader(new BasicHeader(name, value));
>>>>        }
>>>>
>>>>        @Override
>>>> -    public void setHeader(final String name, final String value) {
>>>> +    public void setHeader(final String name, final Object value) {
>>>>            Args.notNull(name, "Header name");
>>>>            setHeader(new BasicHeader(name, value));
>>>>        }
>>>> Index: src/main/java/org/apache/hc/core5/http/message/BasicHeader.java
>>>> ===================================================================
>>>> --- src/main/java/org/apache/hc/core5/http/message/BasicHeader.java
>>>> (revision
>>>> 1717301)
>>>> +++ src/main/java/org/apache/hc/core5/http/message/BasicHeader.java
>>>> (working
>>>> copy)
>>>> @@ -28,6 +28,7 @@
>>>>    package org.apache.hc.core5.http.message;
>>>>
>>>>    import java.io.Serializable;
>>>> +import java.util.Objects;
>>>>
>>>>    import org.apache.hc.core5.annotation.Immutable;
>>>>    import org.apache.hc.core5.http.Header;
>>>> @@ -55,10 +56,10 @@
>>>>         * @param name the header name
>>>>         * @param value the header value
>>>>         */
>>>> -    public BasicHeader(final String name, final String value) {
>>>> +    public BasicHeader(final String name, final Object value) {
>>>>            super();
>>>>            this.name = Args.notNull(name, "Name");
>>>> -        this.value = value;
>>>> +        this.value = Objects.toString(value, null);
>>>>        }
>>>>
>>>>        @Override
>>>>
>>>> Thoughts?
>>>>
>>>>
>>> Gary,
>>>
>>> what benefit do you expect from this patch? If I would read the new code,
>>> I would expect some magic which would auto-convert compatible types to
>>> its
>>> HTTP header counterparts. E.g., numbers, dates, lists, etc.
>>> Which you obviously don't. If you don't plan to add that, you should at
>>> least extend the Javadoc and say you relief the caller from the #toString
>>> burden. No more, no less.
>>>
>>>
>> I have a case now where all I want indeed is to toString() the object
>> passed in. I'm happy to Javadoc it that way if that's OK with everyone.
>>
>
> Please do so.


Done.

Gary

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


-- 
E-Mail: garydgregory@gmail.com | ggregory@apache.org
Java Persistence with Hibernate, Second Edition
<http://www.manning.com/bauer3/>
JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
Spring Batch in Action <http://www.manning.com/templier/>
Blog: http://garygregory.wordpress.com
Home: http://garygregory.com/
Tweet! http://twitter.com/GaryGregory

Re: Better header API

Posted by Michael Osipov <mi...@apache.org>.
Am 2015-12-01 um 02:22 schrieb Gary Gregory:
> On Mon, Nov 30, 2015 at 1:43 PM, Michael Osipov <mi...@apache.org> wrote:
>
>> Am 2015-11-30 um 19:53 schrieb Gary Gregory:
>>
>>> I mean:
>>>
>>> Index: src/main/java/org/apache/hc/core5/http/HttpMessage.java
>>> ===================================================================
>>> --- src/main/java/org/apache/hc/core5/http/HttpMessage.java (revision
>>> 1717301)
>>> +++ src/main/java/org/apache/hc/core5/http/HttpMessage.java (working copy)
>>> @@ -55,7 +55,7 @@
>>>         * @param name the name of the header.
>>>         * @param value the value of the header.
>>>         */
>>> -    void addHeader(String name, String value);
>>> +    void addHeader(String name, Object value);
>>>
>>>        /**
>>>         * Overwrites the first header with the same name. The new header
>>> will
>>> be appended to
>>> @@ -72,7 +72,7 @@
>>>         * @param name the name of the header.
>>>         * @param value the value of the header.
>>>         */
>>> -    void setHeader(String name, String value);
>>> +    void setHeader(String name, Object value);
>>>
>>>        /**
>>>         * Overwrites all the headers in the message.
>>> Index:
>>> src/main/java/org/apache/hc/core5/http/message/AbstractHttpMessage.java
>>> ===================================================================
>>> ---
>>> src/main/java/org/apache/hc/core5/http/message/AbstractHttpMessage.java
>>> (revision
>>> 1717301)
>>> +++
>>> src/main/java/org/apache/hc/core5/http/message/AbstractHttpMessage.java
>>> (working
>>> copy)
>>> @@ -43,13 +43,13 @@
>>>        private HttpEntity entity;
>>>
>>>        @Override
>>> -    public void addHeader(final String name, final String value) {
>>> +    public void addHeader(final String name, final Object value) {
>>>            Args.notNull(name, "Header name");
>>>            addHeader(new BasicHeader(name, value));
>>>        }
>>>
>>>        @Override
>>> -    public void setHeader(final String name, final String value) {
>>> +    public void setHeader(final String name, final Object value) {
>>>            Args.notNull(name, "Header name");
>>>            setHeader(new BasicHeader(name, value));
>>>        }
>>> Index: src/main/java/org/apache/hc/core5/http/message/BasicHeader.java
>>> ===================================================================
>>> --- src/main/java/org/apache/hc/core5/http/message/BasicHeader.java
>>> (revision
>>> 1717301)
>>> +++ src/main/java/org/apache/hc/core5/http/message/BasicHeader.java
>>> (working
>>> copy)
>>> @@ -28,6 +28,7 @@
>>>    package org.apache.hc.core5.http.message;
>>>
>>>    import java.io.Serializable;
>>> +import java.util.Objects;
>>>
>>>    import org.apache.hc.core5.annotation.Immutable;
>>>    import org.apache.hc.core5.http.Header;
>>> @@ -55,10 +56,10 @@
>>>         * @param name the header name
>>>         * @param value the header value
>>>         */
>>> -    public BasicHeader(final String name, final String value) {
>>> +    public BasicHeader(final String name, final Object value) {
>>>            super();
>>>            this.name = Args.notNull(name, "Name");
>>> -        this.value = value;
>>> +        this.value = Objects.toString(value, null);
>>>        }
>>>
>>>        @Override
>>>
>>> Thoughts?
>>>
>>
>> Gary,
>>
>> what benefit do you expect from this patch? If I would read the new code,
>> I would expect some magic which would auto-convert compatible types to its
>> HTTP header counterparts. E.g., numbers, dates, lists, etc.
>> Which you obviously don't. If you don't plan to add that, you should at
>> least extend the Javadoc and say you relief the caller from the #toString
>> burden. No more, no less.
>>
>
> I have a case now where all I want indeed is to toString() the object
> passed in. I'm happy to Javadoc it that way if that's OK with everyone.

Please do so.

Michael


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


Re: Better header API

Posted by Gary Gregory <ga...@gmail.com>.
On Mon, Nov 30, 2015 at 1:43 PM, Michael Osipov <mi...@apache.org> wrote:

> Am 2015-11-30 um 19:53 schrieb Gary Gregory:
>
>> I mean:
>>
>> Index: src/main/java/org/apache/hc/core5/http/HttpMessage.java
>> ===================================================================
>> --- src/main/java/org/apache/hc/core5/http/HttpMessage.java (revision
>> 1717301)
>> +++ src/main/java/org/apache/hc/core5/http/HttpMessage.java (working copy)
>> @@ -55,7 +55,7 @@
>>        * @param name the name of the header.
>>        * @param value the value of the header.
>>        */
>> -    void addHeader(String name, String value);
>> +    void addHeader(String name, Object value);
>>
>>       /**
>>        * Overwrites the first header with the same name. The new header
>> will
>> be appended to
>> @@ -72,7 +72,7 @@
>>        * @param name the name of the header.
>>        * @param value the value of the header.
>>        */
>> -    void setHeader(String name, String value);
>> +    void setHeader(String name, Object value);
>>
>>       /**
>>        * Overwrites all the headers in the message.
>> Index:
>> src/main/java/org/apache/hc/core5/http/message/AbstractHttpMessage.java
>> ===================================================================
>> ---
>> src/main/java/org/apache/hc/core5/http/message/AbstractHttpMessage.java
>> (revision
>> 1717301)
>> +++
>> src/main/java/org/apache/hc/core5/http/message/AbstractHttpMessage.java
>> (working
>> copy)
>> @@ -43,13 +43,13 @@
>>       private HttpEntity entity;
>>
>>       @Override
>> -    public void addHeader(final String name, final String value) {
>> +    public void addHeader(final String name, final Object value) {
>>           Args.notNull(name, "Header name");
>>           addHeader(new BasicHeader(name, value));
>>       }
>>
>>       @Override
>> -    public void setHeader(final String name, final String value) {
>> +    public void setHeader(final String name, final Object value) {
>>           Args.notNull(name, "Header name");
>>           setHeader(new BasicHeader(name, value));
>>       }
>> Index: src/main/java/org/apache/hc/core5/http/message/BasicHeader.java
>> ===================================================================
>> --- src/main/java/org/apache/hc/core5/http/message/BasicHeader.java
>> (revision
>> 1717301)
>> +++ src/main/java/org/apache/hc/core5/http/message/BasicHeader.java
>> (working
>> copy)
>> @@ -28,6 +28,7 @@
>>   package org.apache.hc.core5.http.message;
>>
>>   import java.io.Serializable;
>> +import java.util.Objects;
>>
>>   import org.apache.hc.core5.annotation.Immutable;
>>   import org.apache.hc.core5.http.Header;
>> @@ -55,10 +56,10 @@
>>        * @param name the header name
>>        * @param value the header value
>>        */
>> -    public BasicHeader(final String name, final String value) {
>> +    public BasicHeader(final String name, final Object value) {
>>           super();
>>           this.name = Args.notNull(name, "Name");
>> -        this.value = value;
>> +        this.value = Objects.toString(value, null);
>>       }
>>
>>       @Override
>>
>> Thoughts?
>>
>
> Gary,
>
> what benefit do you expect from this patch? If I would read the new code,
> I would expect some magic which would auto-convert compatible types to its
> HTTP header counterparts. E.g., numbers, dates, lists, etc.
> Which you obviously don't. If you don't plan to add that, you should at
> least extend the Javadoc and say you relief the caller from the #toString
> burden. No more, no less.
>

I have a case now where all I want indeed is to toString() the object
passed in. I'm happy to Javadoc it that way if that's OK with everyone.

Gary


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


-- 
E-Mail: garydgregory@gmail.com | ggregory@apache.org
Java Persistence with Hibernate, Second Edition
<http://www.manning.com/bauer3/>
JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
Spring Batch in Action <http://www.manning.com/templier/>
Blog: http://garygregory.wordpress.com
Home: http://garygregory.com/
Tweet! http://twitter.com/GaryGregory

Re: Better header API

Posted by Michael Osipov <mi...@apache.org>.
Am 2015-11-30 um 19:53 schrieb Gary Gregory:
> I mean:
>
> Index: src/main/java/org/apache/hc/core5/http/HttpMessage.java
> ===================================================================
> --- src/main/java/org/apache/hc/core5/http/HttpMessage.java (revision
> 1717301)
> +++ src/main/java/org/apache/hc/core5/http/HttpMessage.java (working copy)
> @@ -55,7 +55,7 @@
>        * @param name the name of the header.
>        * @param value the value of the header.
>        */
> -    void addHeader(String name, String value);
> +    void addHeader(String name, Object value);
>
>       /**
>        * Overwrites the first header with the same name. The new header will
> be appended to
> @@ -72,7 +72,7 @@
>        * @param name the name of the header.
>        * @param value the value of the header.
>        */
> -    void setHeader(String name, String value);
> +    void setHeader(String name, Object value);
>
>       /**
>        * Overwrites all the headers in the message.
> Index:
> src/main/java/org/apache/hc/core5/http/message/AbstractHttpMessage.java
> ===================================================================
> --- src/main/java/org/apache/hc/core5/http/message/AbstractHttpMessage.java
> (revision
> 1717301)
> +++ src/main/java/org/apache/hc/core5/http/message/AbstractHttpMessage.java
> (working
> copy)
> @@ -43,13 +43,13 @@
>       private HttpEntity entity;
>
>       @Override
> -    public void addHeader(final String name, final String value) {
> +    public void addHeader(final String name, final Object value) {
>           Args.notNull(name, "Header name");
>           addHeader(new BasicHeader(name, value));
>       }
>
>       @Override
> -    public void setHeader(final String name, final String value) {
> +    public void setHeader(final String name, final Object value) {
>           Args.notNull(name, "Header name");
>           setHeader(new BasicHeader(name, value));
>       }
> Index: src/main/java/org/apache/hc/core5/http/message/BasicHeader.java
> ===================================================================
> --- src/main/java/org/apache/hc/core5/http/message/BasicHeader.java (revision
> 1717301)
> +++ src/main/java/org/apache/hc/core5/http/message/BasicHeader.java (working
> copy)
> @@ -28,6 +28,7 @@
>   package org.apache.hc.core5.http.message;
>
>   import java.io.Serializable;
> +import java.util.Objects;
>
>   import org.apache.hc.core5.annotation.Immutable;
>   import org.apache.hc.core5.http.Header;
> @@ -55,10 +56,10 @@
>        * @param name the header name
>        * @param value the header value
>        */
> -    public BasicHeader(final String name, final String value) {
> +    public BasicHeader(final String name, final Object value) {
>           super();
>           this.name = Args.notNull(name, "Name");
> -        this.value = value;
> +        this.value = Objects.toString(value, null);
>       }
>
>       @Override
>
> Thoughts?

Gary,

what benefit do you expect from this patch? If I would read the new 
code, I would expect some magic which would auto-convert compatible 
types to its HTTP header counterparts. E.g., numbers, dates, lists, etc.
Which you obviously don't. If you don't plan to add that, you should at 
least extend the Javadoc and say you relief the caller from the 
#toString burden. No more, no less.

Michael




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


Re: Better header API

Posted by Gary Gregory <ga...@gmail.com>.
Done! :-)

Gary

On Mon, Nov 30, 2015 at 12:28 PM, Oleg Kalnichevski <ol...@apache.org>
wrote:

> On Mon, 2015-11-30 at 10:53 -0800, Gary Gregory wrote:
> > I mean:
> >
> > Index: src/main/java/org/apache/hc/core5/http/HttpMessage.java
> > ===================================================================
> > --- src/main/java/org/apache/hc/core5/http/HttpMessage.java (revision
> > 1717301)
> > +++ src/main/java/org/apache/hc/core5/http/HttpMessage.java (working
> copy)
> > @@ -55,7 +55,7 @@
> >       * @param name the name of the header.
> >       * @param value the value of the header.
> >       */
> > -    void addHeader(String name, String value);
> > +    void addHeader(String name, Object value);
> >
> >      /**
> >       * Overwrites the first header with the same name. The new header
> will
> > be appended to
> > @@ -72,7 +72,7 @@
> >       * @param name the name of the header.
> >       * @param value the value of the header.
> >       */
> > -    void setHeader(String name, String value);
> > +    void setHeader(String name, Object value);
> >
> >      /**
> >       * Overwrites all the headers in the message.
> > Index:
> > src/main/java/org/apache/hc/core5/http/message/AbstractHttpMessage.java
> > ===================================================================
> > ---
> src/main/java/org/apache/hc/core5/http/message/AbstractHttpMessage.java
> > (revision
> > 1717301)
> > +++
> src/main/java/org/apache/hc/core5/http/message/AbstractHttpMessage.java
> > (working
> > copy)
> > @@ -43,13 +43,13 @@
> >      private HttpEntity entity;
> >
> >      @Override
> > -    public void addHeader(final String name, final String value) {
> > +    public void addHeader(final String name, final Object value) {
> >          Args.notNull(name, "Header name");
> >          addHeader(new BasicHeader(name, value));
> >      }
> >
> >      @Override
> > -    public void setHeader(final String name, final String value) {
> > +    public void setHeader(final String name, final Object value) {
> >          Args.notNull(name, "Header name");
> >          setHeader(new BasicHeader(name, value));
> >      }
> > Index: src/main/java/org/apache/hc/core5/http/message/BasicHeader.java
> > ===================================================================
> > --- src/main/java/org/apache/hc/core5/http/message/BasicHeader.java
> (revision
> > 1717301)
> > +++ src/main/java/org/apache/hc/core5/http/message/BasicHeader.java
> (working
> > copy)
> > @@ -28,6 +28,7 @@
> >  package org.apache.hc.core5.http.message;
> >
> >  import java.io.Serializable;
> > +import java.util.Objects;
> >
> >  import org.apache.hc.core5.annotation.Immutable;
> >  import org.apache.hc.core5.http.Header;
> > @@ -55,10 +56,10 @@
> >       * @param name the header name
> >       * @param value the header value
> >       */
> > -    public BasicHeader(final String name, final String value) {
> > +    public BasicHeader(final String name, final Object value) {
> >          super();
> >          this.name = Args.notNull(name, "Name");
> > -        this.value = value;
> > +        this.value = Objects.toString(value, null);
> >      }
> >
> >      @Override
> >
> > Thoughts?
> >
>
> Works for me.
>
> +1
>
> Oleg
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org
> For additional commands, e-mail: dev-help@hc.apache.org
>
>


-- 
E-Mail: garydgregory@gmail.com | ggregory@apache.org
Java Persistence with Hibernate, Second Edition
<http://www.manning.com/bauer3/>
JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
Spring Batch in Action <http://www.manning.com/templier/>
Blog: http://garygregory.wordpress.com
Home: http://garygregory.com/
Tweet! http://twitter.com/GaryGregory

Re: Better header API

Posted by Oleg Kalnichevski <ol...@apache.org>.
On Mon, 2015-11-30 at 10:53 -0800, Gary Gregory wrote:
> I mean:
> 
> Index: src/main/java/org/apache/hc/core5/http/HttpMessage.java
> ===================================================================
> --- src/main/java/org/apache/hc/core5/http/HttpMessage.java (revision
> 1717301)
> +++ src/main/java/org/apache/hc/core5/http/HttpMessage.java (working copy)
> @@ -55,7 +55,7 @@
>       * @param name the name of the header.
>       * @param value the value of the header.
>       */
> -    void addHeader(String name, String value);
> +    void addHeader(String name, Object value);
> 
>      /**
>       * Overwrites the first header with the same name. The new header will
> be appended to
> @@ -72,7 +72,7 @@
>       * @param name the name of the header.
>       * @param value the value of the header.
>       */
> -    void setHeader(String name, String value);
> +    void setHeader(String name, Object value);
> 
>      /**
>       * Overwrites all the headers in the message.
> Index:
> src/main/java/org/apache/hc/core5/http/message/AbstractHttpMessage.java
> ===================================================================
> --- src/main/java/org/apache/hc/core5/http/message/AbstractHttpMessage.java
> (revision
> 1717301)
> +++ src/main/java/org/apache/hc/core5/http/message/AbstractHttpMessage.java
> (working
> copy)
> @@ -43,13 +43,13 @@
>      private HttpEntity entity;
> 
>      @Override
> -    public void addHeader(final String name, final String value) {
> +    public void addHeader(final String name, final Object value) {
>          Args.notNull(name, "Header name");
>          addHeader(new BasicHeader(name, value));
>      }
> 
>      @Override
> -    public void setHeader(final String name, final String value) {
> +    public void setHeader(final String name, final Object value) {
>          Args.notNull(name, "Header name");
>          setHeader(new BasicHeader(name, value));
>      }
> Index: src/main/java/org/apache/hc/core5/http/message/BasicHeader.java
> ===================================================================
> --- src/main/java/org/apache/hc/core5/http/message/BasicHeader.java (revision
> 1717301)
> +++ src/main/java/org/apache/hc/core5/http/message/BasicHeader.java (working
> copy)
> @@ -28,6 +28,7 @@
>  package org.apache.hc.core5.http.message;
> 
>  import java.io.Serializable;
> +import java.util.Objects;
> 
>  import org.apache.hc.core5.annotation.Immutable;
>  import org.apache.hc.core5.http.Header;
> @@ -55,10 +56,10 @@
>       * @param name the header name
>       * @param value the header value
>       */
> -    public BasicHeader(final String name, final String value) {
> +    public BasicHeader(final String name, final Object value) {
>          super();
>          this.name = Args.notNull(name, "Name");
> -        this.value = value;
> +        this.value = Objects.toString(value, null);
>      }
> 
>      @Override
> 
> Thoughts?
> 

Works for me.

+1

Oleg



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


Re: Better header API

Posted by Gary Gregory <ga...@gmail.com>.
I mean:

Index: src/main/java/org/apache/hc/core5/http/HttpMessage.java
===================================================================
--- src/main/java/org/apache/hc/core5/http/HttpMessage.java (revision
1717301)
+++ src/main/java/org/apache/hc/core5/http/HttpMessage.java (working copy)
@@ -55,7 +55,7 @@
      * @param name the name of the header.
      * @param value the value of the header.
      */
-    void addHeader(String name, String value);
+    void addHeader(String name, Object value);

     /**
      * Overwrites the first header with the same name. The new header will
be appended to
@@ -72,7 +72,7 @@
      * @param name the name of the header.
      * @param value the value of the header.
      */
-    void setHeader(String name, String value);
+    void setHeader(String name, Object value);

     /**
      * Overwrites all the headers in the message.
Index:
src/main/java/org/apache/hc/core5/http/message/AbstractHttpMessage.java
===================================================================
--- src/main/java/org/apache/hc/core5/http/message/AbstractHttpMessage.java
(revision
1717301)
+++ src/main/java/org/apache/hc/core5/http/message/AbstractHttpMessage.java
(working
copy)
@@ -43,13 +43,13 @@
     private HttpEntity entity;

     @Override
-    public void addHeader(final String name, final String value) {
+    public void addHeader(final String name, final Object value) {
         Args.notNull(name, "Header name");
         addHeader(new BasicHeader(name, value));
     }

     @Override
-    public void setHeader(final String name, final String value) {
+    public void setHeader(final String name, final Object value) {
         Args.notNull(name, "Header name");
         setHeader(new BasicHeader(name, value));
     }
Index: src/main/java/org/apache/hc/core5/http/message/BasicHeader.java
===================================================================
--- src/main/java/org/apache/hc/core5/http/message/BasicHeader.java (revision
1717301)
+++ src/main/java/org/apache/hc/core5/http/message/BasicHeader.java (working
copy)
@@ -28,6 +28,7 @@
 package org.apache.hc.core5.http.message;

 import java.io.Serializable;
+import java.util.Objects;

 import org.apache.hc.core5.annotation.Immutable;
 import org.apache.hc.core5.http.Header;
@@ -55,10 +56,10 @@
      * @param name the header name
      * @param value the header value
      */
-    public BasicHeader(final String name, final String value) {
+    public BasicHeader(final String name, final Object value) {
         super();
         this.name = Args.notNull(name, "Name");
-        this.value = value;
+        this.value = Objects.toString(value, null);
     }

     @Override

Thoughts?

Gary

On Mon, Nov 30, 2015 at 10:53 AM, Gary Gregory <ga...@gmail.com>
wrote:

> I'd like to apply this patch:
>
>
> --
> E-Mail: garydgregory@gmail.com | ggregory@apache.org
> Java Persistence with Hibernate, Second Edition
> <http://www.manning.com/bauer3/>
> JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
> Spring Batch in Action <http://www.manning.com/templier/>
> Blog: http://garygregory.wordpress.com
> Home: http://garygregory.com/
> Tweet! http://twitter.com/GaryGregory
>



-- 
E-Mail: garydgregory@gmail.com | ggregory@apache.org
Java Persistence with Hibernate, Second Edition
<http://www.manning.com/bauer3/>
JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
Spring Batch in Action <http://www.manning.com/templier/>
Blog: http://garygregory.wordpress.com
Home: http://garygregory.com/
Tweet! http://twitter.com/GaryGregory