You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by ChambreNoire <aw...@tentelemed.com> on 2015/03/30 17:44:30 UTC
Download serves empty files with correct number of pages !?!
Hello,
I have a strange problem. Ever since I have moved the files I'm linking to
in the following code to the classpath, they are downloading as empty files
but *with the correct number of pages*!
Any ideas?
Thanks
class AlarmLink extends Link<Alarm> implements IResourceListener {
private IResource resource;
AlarmLink(String id, final IModel<Alarm> model) {
super(id, model);
resource = new ResourceStreamResource(null) {
@Override
protected IResourceStream getResourceStream() {
File path;
try {
path = new
ClassPathResource("descriptors/hc").getFile();
} catch (IOException exception) {
return null;
}
return new FileResourceStream(new File(path,
getModelObject().getFile()));
}
};
}
public final void onResourceRequested() {
Attributes a = new Attributes(RequestCycle.get().getRequest(),
RequestCycle.get().getResponse(), null);
resource.respond(a);
onLinkClicked();
}
@Override
protected final CharSequence getURL() {
return urlFor(IResourceListener.INTERFACE, null);
}
@Override
public void onClick() {}
@Override
public IModel<?> getBody() {
return PropertyModel.of(getModel(), "label");
}
@Override
protected void onComponentTag(ComponentTag tag) {
super.onComponentTag(tag);
tag.getAttributes().put("target", "_blank");
}
}
--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Download-serves-empty-files-with-correct-number-of-pages-tp4670117.html
Sent from the Users forum mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: Download serves empty files with correct number of pages !?!
Posted by ChambreNoire <aw...@tentelemed.com>.
Francois Meillet wrote
> path = new ClassPathResource("descriptors/hc").getFile();
> the path isn't null ?
Nope. By the time we get to the line :
return new FileResourceStream(new File(path, getModelObject().getFile()));
the path isn't null and this ends up instantiating a FileResourceStream with
a file that both has the correct path and exist()s...
--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Download-serves-empty-files-with-correct-number-of-pages-tp4670117p4670121.html
Sent from the Users forum mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: Download serves empty files with correct number of pages !?!
Posted by Francois Meillet <fr...@gmail.com>.
path = new ClassPathResource("descriptors/hc").getFile();
the path isn't null ?
François
Le 30 mars 2015 à 18:03, ChambreNoire <aw...@tentelemed.com> a écrit :
> Sure but no exception is thrown!
>
> --
> View this message in context: http://apache-wicket.1842946.n4.nabble.com/Download-serves-empty-files-with-correct-number-of-pages-tp4670117p4670119.html
> Sent from the Users forum mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
Re: Download serves empty files with correct number of pages !?!
Posted by ChambreNoire <aw...@tentelemed.com>.
Sure but no exception is thrown!
--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Download-serves-empty-files-with-correct-number-of-pages-tp4670117p4670119.html
Sent from the Users forum mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: Download serves empty files with correct number of pages !?!
Posted by Francois Meillet <fr...@gmail.com>.
printing the exception could help
} catch (IOException exception) {
return null;
--> print stack
}
François
Le 30 mars 2015 à 17:44, ChambreNoire <aw...@tentelemed.com> a écrit :
> Hello,
>
> I have a strange problem. Ever since I have moved the files I'm linking to
> in the following code to the classpath, they are downloading as empty files
> but *with the correct number of pages*!
>
> Any ideas?
>
> Thanks
>
> class AlarmLink extends Link<Alarm> implements IResourceListener {
>
> private IResource resource;
>
> AlarmLink(String id, final IModel<Alarm> model) {
> super(id, model);
>
> resource = new ResourceStreamResource(null) {
>
> @Override
> protected IResourceStream getResourceStream() {
>
> File path;
> try {
> path = new
> ClassPathResource("descriptors/hc").getFile();
> } catch (IOException exception) {
> return null;
> }
> return new FileResourceStream(new File(path,
> getModelObject().getFile()));
> }
> };
> }
>
> public final void onResourceRequested() {
>
> Attributes a = new Attributes(RequestCycle.get().getRequest(),
> RequestCycle.get().getResponse(), null);
> resource.respond(a);
> onLinkClicked();
> }
>
> @Override
> protected final CharSequence getURL() {
> return urlFor(IResourceListener.INTERFACE, null);
> }
>
> @Override
> public void onClick() {}
>
> @Override
> public IModel<?> getBody() {
> return PropertyModel.of(getModel(), "label");
> }
>
> @Override
> protected void onComponentTag(ComponentTag tag) {
> super.onComponentTag(tag);
> tag.getAttributes().put("target", "_blank");
> }
> }
>
> --
> View this message in context: http://apache-wicket.1842946.n4.nabble.com/Download-serves-empty-files-with-correct-number-of-pages-tp4670117.html
> Sent from the Users forum mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
Re: Download serves empty files with correct number of pages !?!
Posted by ChambreNoire <aw...@tentelemed.com>.
Nevermind I just used a ResourceLink and it works fine!
--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Download-serves-empty-files-with-correct-number-of-pages-tp4670117p4670128.html
Sent from the Users forum mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: Download serves empty files with correct number of pages !?!
Posted by ChambreNoire <aw...@tentelemed.com>.
Is there an easy way of overloading the ContentDisposition.ATTACHMENT already
used in DownloadLink?
--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Download-serves-empty-files-with-correct-number-of-pages-tp4670117p4670127.html
Sent from the Users forum mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: Download serves empty files with correct number of pages !?!
Posted by Francois Meillet <fr...@gmail.com>.
org.apache.wicket.request.resource.ContentDisposition
ContentDisposition.INLINE
ContentDisposition.ATTACHMENT
resourceResponse.setContentDisposition(contentDisposition);
François
Le 31 mars 2015 à 13:35, ChambreNoire <aw...@tentelemed.com> a écrit :
> OK so the empty PDFs where due to some strangeness with the build config
> which is fixed. The filename and extensions are added by
> item.getModelObject().getFile(). So it works fine now however using
> DownloadLink the file still downloads rather than is opened in a new tab.
>
> Any ideas?
>
> --
> View this message in context: http://apache-wicket.1842946.n4.nabble.com/Download-serves-empty-files-with-correct-number-of-pages-tp4670117p4670125.html
> Sent from the Users forum mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
Re: Download serves empty files with correct number of pages !?!
Posted by ChambreNoire <aw...@tentelemed.com>.
OK so the empty PDFs where due to some strangeness with the build config
which is fixed. The filename and extensions are added by
item.getModelObject().getFile(). So it works fine now however using
DownloadLink the file still downloads rather than is opened in a new tab.
Any ideas?
--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Download-serves-empty-files-with-correct-number-of-pages-tp4670117p4670125.html
Sent from the Users forum mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: Download serves empty files with correct number of pages !?!
Posted by Martin Grigorov <mg...@apache.org>.
On Mon, Mar 30, 2015 at 7:32 PM, ChambreNoire <aw...@tentelemed.com> wrote:
> I was using the AjaxDownload outlined in
>
> https://cwiki.apache.org/confluence/display/WICKET/AJAX+update+and+file+download+in+one+blow
> before with the same problem.
>
> I switched to DownloadLink :
>
> IModel<File> model = new LoadableDetachableModel<File>() {
>
> @Override
> protected File load() {
>
> File path;
> try {
> path = new ClassPathResource("descriptors/hc").getFile();
>
'hc' has no extension. Neither the server, nor the browser will have idea
how to present it. So I think it is expected that the browser downloads it
instead of showing it in a tab/window.
> } catch (IOException exception) {
> return null;
> }
> return new File(path, item.getModelObject().getFile());
> }
> };
>
> add(new DownloadLink(ID_ALARM, model) {
>
> @Override
> protected void onComponentTag(ComponentTag tag) {
> super.onComponentTag(tag);
>
> tag.getAttributes().put("target", "_blank");
> }
> });
>
> Now the file downloads rather than opening in a new tab and it's still
> blank
> with the correct number of pages...
>
"correct number of pages"
I'd say the correct file is delivered. It is your viewer that doesn't
represent it correctly.
Check the sizes of the original file and the downloaded one.
I guess the file is binary so also try with 'cmp' (Linux command line) or
something similar.
>
> --
> View this message in context:
> http://apache-wicket.1842946.n4.nabble.com/Download-serves-empty-files-with-correct-number-of-pages-tp4670117p4670123.html
> Sent from the Users forum mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>
Re: Download serves empty files with correct number of pages !?!
Posted by ChambreNoire <aw...@tentelemed.com>.
I was using the AjaxDownload outlined in
https://cwiki.apache.org/confluence/display/WICKET/AJAX+update+and+file+download+in+one+blow
before with the same problem.
I switched to DownloadLink :
IModel<File> model = new LoadableDetachableModel<File>() {
@Override
protected File load() {
File path;
try {
path = new ClassPathResource("descriptors/hc").getFile();
} catch (IOException exception) {
return null;
}
return new File(path, item.getModelObject().getFile());
}
};
add(new DownloadLink(ID_ALARM, model) {
@Override
protected void onComponentTag(ComponentTag tag) {
super.onComponentTag(tag);
tag.getAttributes().put("target", "_blank");
}
});
Now the file downloads rather than opening in a new tab and it's still blank
with the correct number of pages...
--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Download-serves-empty-files-with-correct-number-of-pages-tp4670117p4670123.html
Sent from the Users forum mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: Download serves empty files with correct number of pages !?!
Posted by Martin Grigorov <mg...@apache.org>.
Hi,
Why don't you use DownloadLink or ResourceLink ?
At least check their sources for inspiration.
Martin Grigorov
Freelancer, available for hire!
Wicket Training and Consulting
https://twitter.com/mtgrigorov
On Mon, Mar 30, 2015 at 6:44 PM, ChambreNoire <aw...@tentelemed.com> wrote:
> Hello,
>
> I have a strange problem. Ever since I have moved the files I'm linking to
> in the following code to the classpath, they are downloading as empty files
> but *with the correct number of pages*!
>
> Any ideas?
>
> Thanks
>
> class AlarmLink extends Link<Alarm> implements IResourceListener {
>
> private IResource resource;
>
> AlarmLink(String id, final IModel<Alarm> model) {
> super(id, model);
>
> resource = new ResourceStreamResource(null) {
>
> @Override
> protected IResourceStream getResourceStream() {
>
> File path;
> try {
> path = new
> ClassPathResource("descriptors/hc").getFile();
> } catch (IOException exception) {
> return null;
> }
> return new FileResourceStream(new File(path,
> getModelObject().getFile()));
> }
> };
> }
>
> public final void onResourceRequested() {
>
> Attributes a = new Attributes(RequestCycle.get().getRequest(),
> RequestCycle.get().getResponse(), null);
> resource.respond(a);
> onLinkClicked();
> }
>
> @Override
> protected final CharSequence getURL() {
> return urlFor(IResourceListener.INTERFACE, null);
> }
>
> @Override
> public void onClick() {}
>
> @Override
> public IModel<?> getBody() {
> return PropertyModel.of(getModel(), "label");
> }
>
> @Override
> protected void onComponentTag(ComponentTag tag) {
> super.onComponentTag(tag);
> tag.getAttributes().put("target", "_blank");
> }
> }
>
> --
> View this message in context:
> http://apache-wicket.1842946.n4.nabble.com/Download-serves-empty-files-with-correct-number-of-pages-tp4670117.html
> Sent from the Users forum mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>