You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@logging.apache.org by Gary Gregory <ga...@gmail.com> on 2018/03/06 16:37:13 UTC

org.apache.logging.log4j.core.layout.AbstractStringLayout.getContentType() does not use Charset

Hi All,

It looks
like org.apache.logging.log4j.core.layout.AbstractStringLayout.getContentType()
does NOT use its charset.

Can anyone foresee a problem with fixing this?

Gary

Re: org.apache.logging.log4j.core.layout.AbstractStringLayout.getContentType() does not use Charset

Posted by Gary Gregory <ga...@gmail.com>.
On Tue, Mar 6, 2018 at 11:01 PM, Apache <ra...@dslextreme.com> wrote:

> But I would expect getContentType to return a mime type, not a charset.
>

A content type can contain a charset parameter, for example:

Content-type: text/plain; charset=us-ascii

See https://www.w3.org/Protocols/rfc1341/4_Content-Type.html

Gary


> Ralph
>
> > On Mar 6, 2018, at 9:17 PM, Gary Gregory <ga...@gmail.com> wrote:
> >
> >> On Tue, Mar 6, 2018 at 6:01 PM, Remko Popma <re...@gmail.com>
> wrote:
> >>
> >> Sorry, I don’t follow.
> >> Why not get the appender’s layout and get the charset by calling
> >> getCharset()?
> >>
> >
> > Right now, I have this ugly non-OO code:
> >
> >                final Layout<? extends Serializable> layout =
> > appender.getLayout();
> >                final Charset charset;
> >                if (layout instanceof StringLayout) {
> >                    charset = ((StringLayout) layout).getCharset();
> >                } else {
> >                    charset =
> > ContentType.parse(layout.getContentType()).getCharset();
> >                }
> >
> > If getContentType() always returned the right thing, I would not need a
> > conditional.
> >
> > Gary
> >
> >
> >>
> >>
> >>
> >>> On Mar 7, 2018, at 7:21, Gary Gregory <ga...@gmail.com> wrote:
> >>>
> >>> Here is my current use case: I'd like to be able to query
> >> getContentType()
> >>> on an FILE appender (File, RollingFile, RAF, ...) and get the proper
> >>> charset if the layout for that appender defines it.
> >>>
> >>> Gary
> >>>
> >>>> On Tue, Mar 6, 2018 at 3:16 PM, Matt Sicker <bo...@gmail.com> wrote:
> >>>>
> >>>> Not all MIME types actually use the encoding parameter. For example,
> >>>> "application/json;charset=UTF-8" is technically an invalid MIME type
> >> (it's
> >>>> supposed to be "application/json", and it's assumed to be UTF-8
> because
> >>>> that's the only official charset for JSON). Providing the charset
> >>>> separately makes semantic sense to me.
> >>>>
> >>>>> On 6 March 2018 at 16:04, Gary Gregory <ga...@gmail.com>
> wrote:
> >>>>>
> >>>>> Right. AbstractStringLayout says:
> >>>>>
> >>>>>   @Override
> >>>>>   public Charset getCharset() {
> >>>>>       return charset;
> >>>>>   }
> >>>>>
> >>>>>   /**
> >>>>>    * @return The default content type for Strings.
> >>>>>    */
> >>>>>   @Override
> >>>>>   public String getContentType() {
> >>>>>       return "text/plain";
> >>>>>   }
> >>>>>
> >>>>> Gary
> >>>>>
> >>>>>
> >>>>>
> >>>>> On Tue, Mar 6, 2018 at 2:52 PM, Remko Popma <re...@gmail.com>
> >>>> wrote:
> >>>>>
> >>>>>> (Away from pc) by “use”, do you mean that the string returned by
> >>>>>> getContentType() doesn’t include a charset?
> >>>>>>
> >>>>>> From memory, I remember the only place this method is used is in the
> >>>>>> HtmlAppender. Are there other places?
> >>>>>>
> >>>>>> (Shameless plug) Every java main() method deserves
> >> http://picocli.info
> >>>>>>
> >>>>>>> On Mar 7, 2018, at 1:37, Gary Gregory <ga...@gmail.com>
> >>>> wrote:
> >>>>>>>
> >>>>>>> Hi All,
> >>>>>>>
> >>>>>>> It looks
> >>>>>>> like org.apache.logging.log4j.core.layout.AbstractStringLayout.
> >>>>>> getContentType()
> >>>>>>> does NOT use its charset.
> >>>>>>>
> >>>>>>> Can anyone foresee a problem with fixing this?
> >>>>>>>
> >>>>>>> Gary
> >>>>>>
> >>>>>
> >>>>
> >>>>
> >>>>
> >>>> --
> >>>> Matt Sicker <bo...@gmail.com>
> >>>>
> >>
>
>
>

Re: org.apache.logging.log4j.core.layout.AbstractStringLayout.getContentType() does not use Charset

Posted by Apache <ra...@dslextreme.com>.
But I would expect getContentType to return a mime type, not a charset.

Ralph

> On Mar 6, 2018, at 9:17 PM, Gary Gregory <ga...@gmail.com> wrote:
> 
>> On Tue, Mar 6, 2018 at 6:01 PM, Remko Popma <re...@gmail.com> wrote:
>> 
>> Sorry, I don’t follow.
>> Why not get the appender’s layout and get the charset by calling
>> getCharset()?
>> 
> 
> Right now, I have this ugly non-OO code:
> 
>                final Layout<? extends Serializable> layout =
> appender.getLayout();
>                final Charset charset;
>                if (layout instanceof StringLayout) {
>                    charset = ((StringLayout) layout).getCharset();
>                } else {
>                    charset =
> ContentType.parse(layout.getContentType()).getCharset();
>                }
> 
> If getContentType() always returned the right thing, I would not need a
> conditional.
> 
> Gary
> 
> 
>> 
>> 
>> 
>>> On Mar 7, 2018, at 7:21, Gary Gregory <ga...@gmail.com> wrote:
>>> 
>>> Here is my current use case: I'd like to be able to query
>> getContentType()
>>> on an FILE appender (File, RollingFile, RAF, ...) and get the proper
>>> charset if the layout for that appender defines it.
>>> 
>>> Gary
>>> 
>>>> On Tue, Mar 6, 2018 at 3:16 PM, Matt Sicker <bo...@gmail.com> wrote:
>>>> 
>>>> Not all MIME types actually use the encoding parameter. For example,
>>>> "application/json;charset=UTF-8" is technically an invalid MIME type
>> (it's
>>>> supposed to be "application/json", and it's assumed to be UTF-8 because
>>>> that's the only official charset for JSON). Providing the charset
>>>> separately makes semantic sense to me.
>>>> 
>>>>> On 6 March 2018 at 16:04, Gary Gregory <ga...@gmail.com> wrote:
>>>>> 
>>>>> Right. AbstractStringLayout says:
>>>>> 
>>>>>   @Override
>>>>>   public Charset getCharset() {
>>>>>       return charset;
>>>>>   }
>>>>> 
>>>>>   /**
>>>>>    * @return The default content type for Strings.
>>>>>    */
>>>>>   @Override
>>>>>   public String getContentType() {
>>>>>       return "text/plain";
>>>>>   }
>>>>> 
>>>>> Gary
>>>>> 
>>>>> 
>>>>> 
>>>>> On Tue, Mar 6, 2018 at 2:52 PM, Remko Popma <re...@gmail.com>
>>>> wrote:
>>>>> 
>>>>>> (Away from pc) by “use”, do you mean that the string returned by
>>>>>> getContentType() doesn’t include a charset?
>>>>>> 
>>>>>> From memory, I remember the only place this method is used is in the
>>>>>> HtmlAppender. Are there other places?
>>>>>> 
>>>>>> (Shameless plug) Every java main() method deserves
>> http://picocli.info
>>>>>> 
>>>>>>> On Mar 7, 2018, at 1:37, Gary Gregory <ga...@gmail.com>
>>>> wrote:
>>>>>>> 
>>>>>>> Hi All,
>>>>>>> 
>>>>>>> It looks
>>>>>>> like org.apache.logging.log4j.core.layout.AbstractStringLayout.
>>>>>> getContentType()
>>>>>>> does NOT use its charset.
>>>>>>> 
>>>>>>> Can anyone foresee a problem with fixing this?
>>>>>>> 
>>>>>>> Gary
>>>>>> 
>>>>> 
>>>> 
>>>> 
>>>> 
>>>> --
>>>> Matt Sicker <bo...@gmail.com>
>>>> 
>> 



Re: org.apache.logging.log4j.core.layout.AbstractStringLayout.getContentType() does not use Charset

Posted by Gary Gregory <ga...@gmail.com>.
On Tue, Mar 6, 2018 at 6:01 PM, Remko Popma <re...@gmail.com> wrote:

> Sorry, I don’t follow.
> Why not get the appender’s layout and get the charset by calling
> getCharset()?
>

Right now, I have this ugly non-OO code:

                final Layout<? extends Serializable> layout =
appender.getLayout();
                final Charset charset;
                if (layout instanceof StringLayout) {
                    charset = ((StringLayout) layout).getCharset();
                } else {
                    charset =
ContentType.parse(layout.getContentType()).getCharset();
                }

If getContentType() always returned the right thing, I would not need a
conditional.

Gary


>
>
>
> > On Mar 7, 2018, at 7:21, Gary Gregory <ga...@gmail.com> wrote:
> >
> > Here is my current use case: I'd like to be able to query
> getContentType()
> > on an FILE appender (File, RollingFile, RAF, ...) and get the proper
> > charset if the layout for that appender defines it.
> >
> > Gary
> >
> >> On Tue, Mar 6, 2018 at 3:16 PM, Matt Sicker <bo...@gmail.com> wrote:
> >>
> >> Not all MIME types actually use the encoding parameter. For example,
> >> "application/json;charset=UTF-8" is technically an invalid MIME type
> (it's
> >> supposed to be "application/json", and it's assumed to be UTF-8 because
> >> that's the only official charset for JSON). Providing the charset
> >> separately makes semantic sense to me.
> >>
> >>> On 6 March 2018 at 16:04, Gary Gregory <ga...@gmail.com> wrote:
> >>>
> >>> Right. AbstractStringLayout says:
> >>>
> >>>    @Override
> >>>    public Charset getCharset() {
> >>>        return charset;
> >>>    }
> >>>
> >>>    /**
> >>>     * @return The default content type for Strings.
> >>>     */
> >>>    @Override
> >>>    public String getContentType() {
> >>>        return "text/plain";
> >>>    }
> >>>
> >>> Gary
> >>>
> >>>
> >>>
> >>> On Tue, Mar 6, 2018 at 2:52 PM, Remko Popma <re...@gmail.com>
> >> wrote:
> >>>
> >>>> (Away from pc) by “use”, do you mean that the string returned by
> >>>> getContentType() doesn’t include a charset?
> >>>>
> >>>> From memory, I remember the only place this method is used is in the
> >>>> HtmlAppender. Are there other places?
> >>>>
> >>>> (Shameless plug) Every java main() method deserves
> http://picocli.info
> >>>>
> >>>>> On Mar 7, 2018, at 1:37, Gary Gregory <ga...@gmail.com>
> >> wrote:
> >>>>>
> >>>>> Hi All,
> >>>>>
> >>>>> It looks
> >>>>> like org.apache.logging.log4j.core.layout.AbstractStringLayout.
> >>>> getContentType()
> >>>>> does NOT use its charset.
> >>>>>
> >>>>> Can anyone foresee a problem with fixing this?
> >>>>>
> >>>>> Gary
> >>>>
> >>>
> >>
> >>
> >>
> >> --
> >> Matt Sicker <bo...@gmail.com>
> >>
>

Re: org.apache.logging.log4j.core.layout.AbstractStringLayout.getContentType() does not use Charset

Posted by Remko Popma <re...@gmail.com>.
Sorry, I don’t follow. 
Why not get the appender’s layout and get the charset by calling getCharset()?



> On Mar 7, 2018, at 7:21, Gary Gregory <ga...@gmail.com> wrote:
> 
> Here is my current use case: I'd like to be able to query getContentType()
> on an FILE appender (File, RollingFile, RAF, ...) and get the proper
> charset if the layout for that appender defines it.
> 
> Gary
> 
>> On Tue, Mar 6, 2018 at 3:16 PM, Matt Sicker <bo...@gmail.com> wrote:
>> 
>> Not all MIME types actually use the encoding parameter. For example,
>> "application/json;charset=UTF-8" is technically an invalid MIME type (it's
>> supposed to be "application/json", and it's assumed to be UTF-8 because
>> that's the only official charset for JSON). Providing the charset
>> separately makes semantic sense to me.
>> 
>>> On 6 March 2018 at 16:04, Gary Gregory <ga...@gmail.com> wrote:
>>> 
>>> Right. AbstractStringLayout says:
>>> 
>>>    @Override
>>>    public Charset getCharset() {
>>>        return charset;
>>>    }
>>> 
>>>    /**
>>>     * @return The default content type for Strings.
>>>     */
>>>    @Override
>>>    public String getContentType() {
>>>        return "text/plain";
>>>    }
>>> 
>>> Gary
>>> 
>>> 
>>> 
>>> On Tue, Mar 6, 2018 at 2:52 PM, Remko Popma <re...@gmail.com>
>> wrote:
>>> 
>>>> (Away from pc) by “use”, do you mean that the string returned by
>>>> getContentType() doesn’t include a charset?
>>>> 
>>>> From memory, I remember the only place this method is used is in the
>>>> HtmlAppender. Are there other places?
>>>> 
>>>> (Shameless plug) Every java main() method deserves http://picocli.info
>>>> 
>>>>> On Mar 7, 2018, at 1:37, Gary Gregory <ga...@gmail.com>
>> wrote:
>>>>> 
>>>>> Hi All,
>>>>> 
>>>>> It looks
>>>>> like org.apache.logging.log4j.core.layout.AbstractStringLayout.
>>>> getContentType()
>>>>> does NOT use its charset.
>>>>> 
>>>>> Can anyone foresee a problem with fixing this?
>>>>> 
>>>>> Gary
>>>> 
>>> 
>> 
>> 
>> 
>> --
>> Matt Sicker <bo...@gmail.com>
>> 

Re: org.apache.logging.log4j.core.layout.AbstractStringLayout.getContentType() does not use Charset

Posted by Gary Gregory <ga...@gmail.com>.
Here is my current use case: I'd like to be able to query getContentType()
on an FILE appender (File, RollingFile, RAF, ...) and get the proper
charset if the layout for that appender defines it.

Gary

On Tue, Mar 6, 2018 at 3:16 PM, Matt Sicker <bo...@gmail.com> wrote:

> Not all MIME types actually use the encoding parameter. For example,
> "application/json;charset=UTF-8" is technically an invalid MIME type (it's
> supposed to be "application/json", and it's assumed to be UTF-8 because
> that's the only official charset for JSON). Providing the charset
> separately makes semantic sense to me.
>
> On 6 March 2018 at 16:04, Gary Gregory <ga...@gmail.com> wrote:
>
> > Right. AbstractStringLayout says:
> >
> >     @Override
> >     public Charset getCharset() {
> >         return charset;
> >     }
> >
> >     /**
> >      * @return The default content type for Strings.
> >      */
> >     @Override
> >     public String getContentType() {
> >         return "text/plain";
> >     }
> >
> > Gary
> >
> >
> >
> > On Tue, Mar 6, 2018 at 2:52 PM, Remko Popma <re...@gmail.com>
> wrote:
> >
> > > (Away from pc) by “use”, do you mean that the string returned by
> > > getContentType() doesn’t include a charset?
> > >
> > > From memory, I remember the only place this method is used is in the
> > > HtmlAppender. Are there other places?
> > >
> > > (Shameless plug) Every java main() method deserves http://picocli.info
> > >
> > > > On Mar 7, 2018, at 1:37, Gary Gregory <ga...@gmail.com>
> wrote:
> > > >
> > > > Hi All,
> > > >
> > > > It looks
> > > > like org.apache.logging.log4j.core.layout.AbstractStringLayout.
> > > getContentType()
> > > > does NOT use its charset.
> > > >
> > > > Can anyone foresee a problem with fixing this?
> > > >
> > > > Gary
> > >
> >
>
>
>
> --
> Matt Sicker <bo...@gmail.com>
>

Re: org.apache.logging.log4j.core.layout.AbstractStringLayout.getContentType() does not use Charset

Posted by Matt Sicker <bo...@gmail.com>.
Not all MIME types actually use the encoding parameter. For example,
"application/json;charset=UTF-8" is technically an invalid MIME type (it's
supposed to be "application/json", and it's assumed to be UTF-8 because
that's the only official charset for JSON). Providing the charset
separately makes semantic sense to me.

On 6 March 2018 at 16:04, Gary Gregory <ga...@gmail.com> wrote:

> Right. AbstractStringLayout says:
>
>     @Override
>     public Charset getCharset() {
>         return charset;
>     }
>
>     /**
>      * @return The default content type for Strings.
>      */
>     @Override
>     public String getContentType() {
>         return "text/plain";
>     }
>
> Gary
>
>
>
> On Tue, Mar 6, 2018 at 2:52 PM, Remko Popma <re...@gmail.com> wrote:
>
> > (Away from pc) by “use”, do you mean that the string returned by
> > getContentType() doesn’t include a charset?
> >
> > From memory, I remember the only place this method is used is in the
> > HtmlAppender. Are there other places?
> >
> > (Shameless plug) Every java main() method deserves http://picocli.info
> >
> > > On Mar 7, 2018, at 1:37, Gary Gregory <ga...@gmail.com> wrote:
> > >
> > > Hi All,
> > >
> > > It looks
> > > like org.apache.logging.log4j.core.layout.AbstractStringLayout.
> > getContentType()
> > > does NOT use its charset.
> > >
> > > Can anyone foresee a problem with fixing this?
> > >
> > > Gary
> >
>



-- 
Matt Sicker <bo...@gmail.com>

Re: org.apache.logging.log4j.core.layout.AbstractStringLayout.getContentType() does not use Charset

Posted by Gary Gregory <ga...@gmail.com>.
Right. AbstractStringLayout says:

    @Override
    public Charset getCharset() {
        return charset;
    }

    /**
     * @return The default content type for Strings.
     */
    @Override
    public String getContentType() {
        return "text/plain";
    }

Gary



On Tue, Mar 6, 2018 at 2:52 PM, Remko Popma <re...@gmail.com> wrote:

> (Away from pc) by “use”, do you mean that the string returned by
> getContentType() doesn’t include a charset?
>
> From memory, I remember the only place this method is used is in the
> HtmlAppender. Are there other places?
>
> (Shameless plug) Every java main() method deserves http://picocli.info
>
> > On Mar 7, 2018, at 1:37, Gary Gregory <ga...@gmail.com> wrote:
> >
> > Hi All,
> >
> > It looks
> > like org.apache.logging.log4j.core.layout.AbstractStringLayout.
> getContentType()
> > does NOT use its charset.
> >
> > Can anyone foresee a problem with fixing this?
> >
> > Gary
>

Re: org.apache.logging.log4j.core.layout.AbstractStringLayout.getContentType() does not use Charset

Posted by Remko Popma <re...@gmail.com>.
(Away from pc) by “use”, do you mean that the string returned by getContentType() doesn’t include a charset?

From memory, I remember the only place this method is used is in the HtmlAppender. Are there other places?

(Shameless plug) Every java main() method deserves http://picocli.info

> On Mar 7, 2018, at 1:37, Gary Gregory <ga...@gmail.com> wrote:
> 
> Hi All,
> 
> It looks
> like org.apache.logging.log4j.core.layout.AbstractStringLayout.getContentType()
> does NOT use its charset.
> 
> Can anyone foresee a problem with fixing this?
> 
> Gary