aspose file tools*
The moose likes Portals and Portlets and the fly likes Issues in file downloading Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Portals and Portlets
Bookmark "Issues in file downloading" Watch "Issues in file downloading" New topic
Author

Issues in file downloading

Ajil Mohan
Greenhorn

Joined: Feb 20, 2010
Posts: 8
Hi All,

I try to implement a module for download some reports in pdf format. I got an Internal Server Error

An error occurred while accessing the requested resource.

http://localhost:8080/web/bruno/profile?p_p_id=FileDownload_WAR_Istrac&p_p_lifecycle=2&p_p_state=normal&p_p_mode=view&p_p_cacheability=cacheLevelPage&p_p_col_id=column-1&p_p_col_count=7&_Fil

on the server , i couldn't understood this error .

Here is my code ,

View page
<div align="right">
<a href="<portlet:resourceURL>
<portlet:param name="fileDownload" value="fileDownload" />
</portlet:resourceURL>">
Download doc
</a>
</div>


Portlet


public void serveResource(ResourceRequest req, ResourceResponse res)
throws PortletException, IOException {
System.out.println(" start processing of file downloading " );
Logger log = new Logger(EventHandler.getLogger(), FileDownload.class);
log.entry("processing file download for Istrac");

EmployeeDao objManager = new EmployeeDao("cowaa");
HashMap<Integer, EmployeeBean> list = objManager.ListEmployees();
Document document = new Document();
Font catFont = new Font(Font.FontFamily.TIMES_ROMAN, 18,
Font.BOLD);
Font redFont = new Font(Font.FontFamily.TIMES_ROMAN, 12,
Font.NORMAL, BaseColor.RED);
Font subFont = new Font(Font.FontFamily.TIMES_ROMAN, 16,
Font.BOLD);
Font smallBold = new Font(Font.FontFamily.TIMES_ROMAN, 12,
Font.BOLD);
try{
res.setContentType("application/pdf");
PdfWriter.getInstance(document,res.getPortletOutputStream());
document.open();
document.add(this.addParagraph(catFont,"Details of Employee"));
Paragraph temp=this.addParagraph(catFont,"");
this.addEmptyLine(temp, 5);
document.add(temp);
PdfPTable table = new PdfPTable(6);
PdfPCell c1 = new PdfPCell(new Phrase("Nmae"));
c1.setHorizontalAlignment(Element.ALIGN_CENTER);
table.addCell(c1);

c1 = new PdfPCell(new Phrase("Designation"));
c1.setHorizontalAlignment(Element.ALIGN_CENTER);
table.addCell(c1);

c1 = new PdfPCell(new Phrase("Location"));
c1.setHorizontalAlignment(Element.ALIGN_CENTER);
table.addCell(c1);

c1 = new PdfPCell(new Phrase("Gender"));
c1.setHorizontalAlignment(Element.ALIGN_CENTER);
table.addCell(c1);

c1 = new PdfPCell(new Phrase("Religion"));
c1.setHorizontalAlignment(Element.ALIGN_CENTER);
table.addCell(c1);

c1 = new PdfPCell(new Phrase("State"));
c1.setHorizontalAlignment(Element.ALIGN_CENTER);
table.addCell(c1);
table.setHeaderRows(1);

Iterator iterator = list.values().iterator();
while(iterator. hasNext()){
EmployeeBean employee= (EmployeeBean)iterator.next();
table.addCell(employee.getName());
table.addCell(employee.getDesignation());
table.addCell(employee.getLocation());
table.addCell(employee.getGender());
table.addCell(employee.getReligion());
table.addCell(employee.getState());
}
document.add(table);
}catch(Exception e){
e.printStackTrace();
log.errorException(e);
}
document.close();
}



I am using Liferay 6 and jsr 268

Any Help regarding that would be appreciated

Ajil


SCJP 1.5
Ashish Sarin
author
Ranch Hand

Joined: Nov 20, 2000
Posts: 432
    
    5
Hi Ajil,

In your serveResource method are you actually writing the file to the response stream?. Also, you can consider using resourceId attribute of resourceURL tag to uniquely identify the resource.

I guess taking a look at chapter 12 example (ch12_BookCatalogResourceURL) of Portlets in Action might help you. The example shows how you can download files using serveResource method. You can find the examples here: http://code.google.com/p/portletsinaction/downloads/list

regards
ashish


Author of
Getting started with Spring Framework
Portlets in Action
Spring Roo 1.1 Cookbook
Portlets blogSpring Roo blog
Ajil Mohan
Greenhorn

Joined: Feb 20, 2010
Posts: 8
Hi Ashish,

In your serveResource method are you actually writing the file to the response stream?. Also, you can consider using resourceId attribute of resourceURL tag to uniquely identify the resource.


Ohh, sorry i missed that one , thanks .
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Issues in file downloading