Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Issues in file downloading

 
Ajil Mohan
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Ashish Sarin
author
Ranch Hand
Posts: 432
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Ajil Mohan
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 .
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic