Portlet: content-type

Status
Nicht offen für weitere Antworten.
C

cfichtinger

Gast
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

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

Code:
<supports>
          <mime-type>application/pdf</mime-type>
          <portlet-mode>view</portlet-mode>
</supports>
 
C

cfichtinger

Gast
ja, ich habs so gemacht...

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

cfichtinger

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

Code:
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.

Code:
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

Top Contributor
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

Neues Mitglied
portlet.xml
Code:
<?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

Top Contributor
Code:
<?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>
 
Status
Nicht offen für weitere Antworten.
Ähnliche Java Themen
  Titel Forum Antworten Datum
T JSR 168 Portlet SessionTimeout hinauszögern Allgemeines EE 7
E Portlet 2 Fragen Allgemeines EE 2
G Liferay Portlet Allgemeines EE 4
S Portlet-Einstieg Allgemeines EE 8
J Portlet to portlet linking Allgemeines EE 8
T ressourcen im Portlet Allgemeines EE 6
B Portlet Allgemeines EE 14
S Beispielanwendung Portlet? Allgemeines EE 5
S Prozesse im Hintergrund - Threads in JSP/Portlet? Allgemeines EE 2
G Portal/Portlet JSR168: Design, Themes, Snippets, Examples . Allgemeines EE 11
G Portlet Programmierung Allgemeines EE 20
M Portlet von JSPs aus aufrufen Allgemeines EE 3
L JSP: Dynamischer Content mit Beans für einen Konfigurator? Allgemeines EE 0
W JSF PrimeFaces center content of layoutUnit Center Allgemeines EE 19
M in JSP Content von fremder Domain einbinden? Allgemeines EE 6
G JSF und Content Management. Allgemeines EE 9
S Downloadbox auch ohne Daten erzwingen // Content-Disposition Allgemeines EE 6
F Aufbau eines Content managment systems Allgemeines EE 8
B [EJB] javax.inject.DefinitionException: bean not a Java type Allgemeines EE 5
MQue Type Safety warnung in JSP Allgemeines EE 2
J Auslesen von <input type="file"> Allgemeines EE 2
D <input type="file"> Problem Allgemeines EE 6
K Internet Explorer MIME Type Probleme Allgemeines EE 2
P Struts Anwendung- FormBean Tabelle mit input type=text Allgemeines EE 2
G jsp error "only a type can be imported" Allgemeines EE 2

Ähnliche Java Themen


Oben