I have a PdfViewer page that contains a panel that displays a dynamically
generated PDF using a resource reference. This works fine in Wicket 6.12.0,
but when I upgrade to 6.13.0 it stops working (just changed Maven dependency
- no code changes). No errors are displayed and the html is generated
exactly as it is with 6.12, but the pdf does not show up in the page.

By setting a breakpoint in Eclipse I have determined that code in the
resource that produces the response (newResourceResponse) is never called in
6.13. After migrating to the latest version (6.19) I still get the problem.
I've looked at the release notes for version 6.13 and see some changes
related to IResource but nothing that looks related to this problem.

I'm hoping someone has seen something similar. Here is some of the relevant
code:

PdfViewer .html - just has reference to panel

       <div wicket:id="pdfPanel"></div>

 

PdfPane.html - just has object reference

Raw HTML

       <object wicket:id="pdf" data="" border="1" width="80%"
height="80%"></object>

 

Generated HTML - seen with view source in browser

        <object data="./resource/org.apache.wicket.Application/pdfProducer" 

               border="1" width="80%" height="80%"></object>

 

PdfPanel.java - has setup for resource reference

public class PdfPanel extends Panel {

       

       private static final long serialVersionUID = 1L;

 

       public PdfPanel(String id) {

              super(id);

              

              ResourceReference resourceReference = new ResourceReference(

                           "pdfProducer") {

                     private static final long serialVersionUID = 1L;

                     

                     @Override

                     public IResource getResource() {

                           WebDocsSession session =
(WebDocsSession)getSession();

 

                           final byte[] pdf = session.getPdf();

                           

                           if(pdf == null)

System.out.println("PdfPanel session.getPdf returned null");

 

PdfResourceProducer pdfResourceProducer = 

new PdfResourceProducer(pdf);

 

                           return pdfResourceProducer;

                     }

              };

        

        String url = (String)RequestCycle.get().urlFor(resourceReference,
null);

              

        MarkupContainer wmc = new WebMarkupContainer("pdf");

        wmc.add(new AttributeModifier("data", url));

        add(wmc);

       }

 

PdfProducer.java - implements the Resource

                public class PdfResourceProducer extends AbstractResource {

 

       private static final long serialVersionUID = -2245331056747467763L;

       final byte[] pdfByteArray;

 

 

       public PdfResourceProducer(byte[] pdfByteArray) {

              super();

              this.pdfByteArray = pdfByteArray;

              if(pdfByteArray == null) {

                     System.out.println("PdfResourceProducer constructor
called with

null byte array.");

              }

       }

 

       @Override

       protected ResourceResponse newResourceResponse(Attributes attributes)
{

              ResourceResponse resourceResponse = new ResourceResponse();

              resourceResponse.setContentType("application/pdf");

              // resourceResponse.setTextEncoding("utf-8");

 

              resourceResponse.setContentLength((int)pdfByteArray.length);

              

              resourceResponse.disableCaching(); //do not allow resource to
be cached.

 

              resourceResponse.setWriteCallback(new WriteCallback() {

                     @Override

                     public void writeData(Attributes attributes) throws
IOException {

                           try {

                                  OutputStream outputStream =
attributes.getResponse()

                                                .getOutputStream();

                                  outputStream.write(pdfByteArray);

                                  outputStream.flush();

                           } catch (IOException e) {

                                  throw new WicketRuntimeException(

                                                "Problems writing pdf to
response...");

                           }

                     }

              });

 

              return resourceResponse;

       }

 

Bruce

 

Reply via email to