8 Replies Latest reply on Jul 25, 2008 11:52 AM by Peter Johnson

    image/png Content type not accepted

    John Gilbert Apprentice

      I am trying to create a portlet that just returns content of type image/png. So I have configured my portlet with:


      and in my portlet I set the type as:


      But when I run the portlet I get the following exception: java.lang.IllegalArgumentException: Content type not accepted

      According to the spec this exception is thrown when the content type does not match request.getResponseContentType().

      When I add a debug statement, I see that request.getResponseContentType() returns text/html.

      Shouldn't this return image/png since I configured it as above? Or is this a bug or am I trying to do something that I shouldn't?

        • 1. Re: image/png Content type not accepted
          seansullivan Newbie

          I encountered the same problem. I have a portlet that produces a PNG image. The portlet writes the PNG data to the PortletOutputStream.

          I am using jboss-portal-2.4.1-cr1 (JBoss Portal + JBoss bundle)

          • 2. Re: image/png Content type not accepted
            seansullivan Newbie

            I found a flaw in my portlet.xml file:


            I'll change the mime-type to image/png and post the results later today.

            • 3. Re: image/png Content type not accepted
              seansullivan Newbie

              I fixed my portlet.xml file but I don't think JBoss Portlal can handle a portlet that produces image/png data.

              On the OpenSymphony message board, I found a discussion about producing image output from a portlet:


              Nils-Helge Garli wrote:
              > Hm... I might have been wrong about it. Maybe you can't generate
              > image output from a portlet. Didn't see anything about that in the
              > portlet spec (maybe someone can enlighten me?).

              There's nothing that prohibits it, but there's also nothing that
              supports it, other than the call to response.setContentType();

              What a portal has to do is define a custom window state that says
              "display only this portlet". When the portlet is rendered with such a
              state it can assume that it will "own" the output, and can thus create
              images or Excel reports or whatever.

              The usual workaround for portals that doesn't have such a window state
              is to link to a servlet that can generate the data instead. Using a
              servlet is worse, however, since it cannot leverage any security
              configuration that a portlet would be able to, and would have to ensure
              on its own that any call is legitimate. But sometimes that is ok.


              • 4. Re: image/png Content type not accepted
                seansullivan Newbie

                In the Portle 2.0 specification, the portlet class may implement the javax.portlet.ResourceServingPortlet interface

                public interface ResourceServingPortlet

                The ResourceServingPortlet interface allows serving resources through the portlet.

                The portlet container must call this method for links created by the RenderResponse.createResouceURL() call. If the portlet creates resource URLs with RenderResponse.createResouceURL() it must implement this listener.

                The ResourceServingPortlet interface contains this method:

                void serveResource(ResourceRequest request,
                ResourceResponse response)
                throws PortletException,

                Called by the portlet container to allow the portlet to generate the resouce content based on its current state. The portal / portlet container must not render any output in addition to the content returned by the portlet. The portal / portlet container should expect that the portlet may return binary content for a renderResource call.

                • 6. Re: image/png Content type not accepted
                  Roy Russo Master

                  We don't support Portlet 2.0, yet.

                  So to serve your binaries, you will have to dispatch to a servlet, from the portlet, and have the servlet stream the binary.

                  • 7. Re: image/png Content type not accepted
                    Anto Vala Newbie

                    Hi all

                    i hai the same problem discussed here but i'm going to fighting with an application/pdf mime tipe.

                    the proble is analogous, what change is the type of output returned.
                    I have developed a CMS portlet that contain a link to my PDF file that is stored in the CMS too, but now i need to open the pdf content only within a window, reading the PDF file from a CMS
                    I have already set the returned mime type in my portlet implementation


                    and in my portlet.xml


                    but as result i have only seen a "wonderful", unlimited stack trace in my server's log that say:

                    java.lang.IllegalArgumentException: Content type not accepted
                    <infinite stack...>
                    Caused by: javax.activation.MimeTypeParseException: Type [application/pdf] not supported

                    any advice will be appreciated!!!

                    I use jboss portal 2.6.5

                    • 8. Re: image/png Content type not accepted
                      Peter Johnson Master

                      avelendino, you should not have attached your question to a two year old topic, you should have started a new topic instead.

                      The error message means exactly what is says - the only mime type supported by portlets is text/html. The only way you can supply a PDF to your users is to provide a link to the PDF within CMS. Or you could write code that reads the PDF and converts it to HTML. (Hey, a tag that did this would probably be a big hit!)