# Portlet: content-type



## cfichtinger (8. Feb 2007)

hallo,

ich habe folgendes Problem.
ich möchte in einer klasse, die von GenericPortlet erbt, in der doView() Methode den Content-Type, mittels response.setContentType(), auf application/pdf setzten.

habe auch in der portlet.xml den supports tag für den mime-type hinzugefügt.

beim ausführen fliege ich immer mit folgender Exception:

java.lang.IllegalArgumentException: Unsupported response content type: application/pdf


ich bitte um rasche hilfe.
danke.


Grüße,
cfichtinger


----------



## KSG9|sebastian (9. Feb 2007)

Wie sieht deine portlet.xml aus?
Hast du es so gemacht:


```
<supports>
          <mime-type>application/pdf</mime-type>
          <portlet-mode>view</portlet-mode>
</supports>
```


----------



## cfichtinger (9. Feb 2007)

danke für die Hilfe!!

Grüße,
cfichtinger


----------



## cfichtinger (9. Feb 2007)

ja, ich habs so gemacht...

aber was ich nicht ganz verstehe ist, warum ich den content type nicht ändern kann.


----------



## cfichtinger (9. Feb 2007)

also, hab jetzt ein Servlet geschrieben in dem das Pdf angezeigt werden soll.


```
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
       File f= new File(this.getServletContext().getRealPath("/res/resource.pdf"));
       response.setContentType("application/pdf");
           InputStream st= new FileInputStream(f);
           OutputStream pw = response.getOutputStream();
           byte[] b = new byte[256];
           int i=0;
           while((i=st.read(b))!=-1)
               pw.write(b,0,i);

           pw.close();
           st.close();
    }
```

weiters wird dieses Servlet in der doView Methode des Portlets eingebunden.


```
PortletRequestDispatcher dispatcher = getPortletContext().getRequestDispatcher("/ShowPdf");
        dispatcher.include(request, response);
```


aber jetzt flieg ich mit folgender Exception:

*java.lang.IllegalStateException: RenderResponseImpl.getOutputStream: contentType either contains wildcard or is not set*[/b]


----------



## KSG9|sebastian (9. Feb 2007)

Mit welchem PortalServer/Portlet API arbeitest du denn?
Zeig mal deine portlet.xml bidde


Gruß seb

Edit: Zeig mal bitte den kompletten Stacktrace, dann kann ich zurückverfolgen wo die Exception geworfen wird.
Haste mal versucht den MIME-Type beim Server bekannt zu machen?


----------



## cfichtinger (9. Feb 2007)

portlet.xml

```
<?xml version="1.0" encoding="UTF-8"?>
<portlet-app xmlns="http://java.sun.com/xml/ns/portlet/portlet-app_1_0.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/portlet/portlet-app_1_0.xsd/etc/opt/SUNWportal/dtd/portlet.xsd" version="1.0">


 <portlet>
        <description>Pdf</description>
        <portlet-name>Pdf</portlet-name>
        <display-name>Pdf</display-name>
        <portlet-class>com.pdf.Pdf</portlet-class>
        <expiration-cache>0</expiration-cache>
         <supports>
            <mime-type>text/html</mime-type>
            <portlet-mode>VIEW</portlet-mode>
            <portlet-mode>EDIT</portlet-mode>
        </supports>
        <portlet-info>
            <title>Pdf</title>
            <short-title>Pdf</short-title>
        </portlet-info>
 </portlet>
</portlet-app>
```

aufgrund einer deiner antworten hab ich die portlet.xml wieder so umbeschrieben, dass als einziger mime-type der text/hmtl type angegeben ist.

der StackTrace:

java.lang.IllegalStateException: RenderResponseImpl.getOutputStream: contentType either contains wildcard or is not set.
        at com.sun.portal.portletcontainer.portlet.impl.RenderResponseImpl.getPortletOutputStream(RenderResponseImpl.java:497)
        at com.sun.portal.portletcontainer.portlet.impl.RDResponseWrapper.getOutputStream(RDResponseWrapper.java:113)
        at com.pdf.ShowPdf.processRequest(ShowPdf.java:32)
        at com.pdf.ShowPdf.doGet(ShowPdf.java:49)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:707)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
        at org.apache.catalina.core.ApplicationFilterChain.servletService(ApplicationFilterChain.java:397)
        at org.apache.catalina.core.ApplicationDispatcher.doInvoke(ApplicationDispatcher.java:850)
        at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:697)
        at org.apache.catalina.core.ApplicationDispatcher.doInclude(ApplicationDispatcher.java:654)
        at org.apache.catalina.core.ApplicationDispatcher.include(ApplicationDispatcher.java:568)
        at com.sun.portal.portletcontainer.portlet.impl.RequestDispatcherImpl.include(RequestDispatcherImpl.java:109)
        at com.pdf.Pdf.doView(Pdf.java:45)
        at javax.portlet.GenericPortlet.doDispatch(GenericPortlet.java:247)
        at javax.portlet.GenericPortlet.render(GenericPortlet.java:175)
        at com.sun.portal.portletcontainer.portletappengine.PortletAppEngineServlet.service(PortletAppEngineServlet.java:353)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
        at org.apache.catalina.core.ApplicationFilterChain.servletService(ApplicationFilterChain.java:397)
        at org.apache.catalina.core.ApplicationDispatcher.doInvoke(ApplicationDispatcher.java:850)
        at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:697)
        at org.apache.catalina.core.ApplicationDispatcher.doInclude(ApplicationDispatcher.java:654)
        at org.apache.catalina.core.ApplicationDispatcher.include(ApplicationDispatcher.java:568)
        at com.sun.portal.portletcontainer.impl.PortletContainer.invokePAE(PortletContainer.java:523)
        at com.sun.portal.portletcontainer.impl.PortletContainer.invokePAE(PortletContainer.java:437)
        at com.sun.portal.portletcontainer.impl.PortletContainer.getMarkup(PortletContainer.java:186)
        at com.sun.portal.portletcontainer.driver.window.WindowInvoker.getPortletContent(WindowInvoker.java:329)
        at com.sun.portal.portletcontainer.driver.window.WindowInvoker.render(WindowInvoker.java:230)
        at com.sun.portal.portletcontainer.driver.PortletContent.getContent(PortletContent.java:67)
        at com.sun.portal.portletcontainer.driver.DesktopServlet.getPortletContents(DesktopServlet.java:223)
        at com.sun.portal.portletcontainer.driver.DesktopServlet.getAllPortletContents(DesktopServlet.java:187)
        at com.sun.portal.portletcontainer.driver.DesktopServlet.doGetPost(DesktopServlet.java:105)
        at com.sun.portal.portletcontainer.driver.DesktopServlet.doGet(DesktopServlet.java:79)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:707)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
        at org.apache.catalina.core.ApplicationFilterChain.servletService(ApplicationFilterChain.java:397)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:278)
        at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:566)
        at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:536)
        at org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:240)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:179)
        at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:566)
        at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:73)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:182)
        at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:566)
        at com.sun.enterprise.web.VirtualServerPipeline.invoke(VirtualServerPipeline.java:120)
        at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:939)
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:137)
        at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:566)
        at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:536)
        at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:939)
        at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:239)
        at com.sun.enterprise.web.connector.grizzly.ProcessorTask.invokeAdapter(ProcessorTask.java:667)
        at com.sun.enterprise.web.connector.grizzly.ProcessorTask.processNonBlocked(ProcessorTask.java:574)
        at com.sun.enterprise.web.connector.grizzly.ProcessorTask.process(ProcessorTask.java:844)
        at com.sun.enterprise.web.connector.grizzly.ReadTask.executeProcessorTask(ReadTask.java:287)
        at com.sun.enterprise.web.connector.grizzly.ReadTask.doTask(ReadTask.java:212)
        at com.sun.enterprise.web.connector.grizzly.TaskBase.run(TaskBase.java:252)
        at com.sun.enterprise.web.connector.grizzly.WorkerThread.run(WorkerThread.java:75)


ich hab noch nicht versucht den mime-type beim server bekannt zu machen.
ich weis auch nicht wie das funktioniert.
arbeite mit dem application server 9.


----------



## KSG9|sebastian (9. Feb 2007)

```
<?xml version="1.0" encoding="UTF-8"?> 
<portlet-app xmlns="http://java.sun.com/xml/ns/portlet/portlet-app_1_0.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/portlet/portlet-app_1_0.xsd/etc/opt/SUNWportal/dtd/portlet.xsd" version="1.0"> 


<portlet> 
        <description>Pdf</description> 
        <portlet-name>Pdf</portlet-name> 
        <display-name>Pdf</display-name> 
        <portlet-class>com.pdf.Pdf</portlet-class> 
        <expiration-cache>0</expiration-cache> 
         <supports> 
            <mime-type>text/html</mime-type> 
            <mime-type>application/pdf</mime-type> 
            <portlet-mode>VIEW</portlet-mode> 
            <portlet-mode>EDIT</portlet-mode> 
        </supports> 
        <portlet-info> 
            <title>Pdf</title> 
            <short-title>Pdf</short-title> 
        </portlet-info> 
</portlet> 
</portlet-app>
```


----------

