Skip to main content



      Home
Home » Eclipse Projects » Remote Application Platform (RAP) » How to get the Output Stream of the Servlet?
How to get the Output Stream of the Servlet? [message #71214] Wed, 23 January 2008 07:44 Go to next message
Eclipse UserFriend
Originally posted by: benjamin.wolff.web.de

Hi!

my problem originates in creating pdf files im my rap application.
allthough there are a few topics in this newsgroup, i'm note able to
recreate this solutions.

http://dev.eclipse.org/newslists/news.eclipse.technology.rap /msg00256.html
http://dev.eclipse.org/newslists/news.eclipse.technology.rap /msg00944.html
http://dev.eclipse.org/newslists/news.eclipse.technology.rap /msg00498.html
http://dev.eclipse.org/newslists/news.eclipse.technology.rap /msg00407.html

i tried to use the org.eclipse.equinox.http.registry.resources extension
point in my application so that i can put the generated pdf's in the
folder an pass the url to an externalBrowser. but this just won't work,
following this instructions:
http://www.eclipse.org/equinox/server/http_writing_applicati on.php
there is a extension in my plugin.xml looking like this:

<extension
point="org.eclipse.equinox.http.registry.resources">
<resource
alias="/test"
base-name="/reports">
</resource>
</extension>

/reports is the folder in my plugin. i put a test.html file into the
folder, but when i launch the app with eclipse and enter the url
http://localhost:<port>/<appname>/test/test.html
it doesn't work. (the folder is included in the build.properties)

maybe anyone knows what i'm doing wrong??

another plan is to use the org.eclipse.equinox.http.registry.servlets
extension as described here:
http://dev.eclipse.org/newslists/news.eclipse.technology.rap /msg00946.html

so i included an extension but i don't know what to do/where to call the
new servlet class.... unfortunately there was no source attached :(

browsing the internet didn't help me much, i'm just missing the point how
to use the extended servlet or how to get the output stream.

i'm really clueless, so i hope anyone can send some clues into my
direction :)
thx!!
Re: How to get the Output Stream of the Servlet? [message #71334 is a reply to message #71214] Thu, 24 January 2008 04:39 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: lars.martin.smb-tec.com

Have a look at org.eclipse.rwt.service.IServiceHandler sources. The header
documentation provides all wanted information for you on how to use a
custom service handler.
Re: How to get the Output Stream of the Servlet? [message #71410 is a reply to message #71334] Thu, 24 January 2008 08:30 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: benjamin.wolff.web.de

hi!

i tried to recreate the steps described in the header but it doesn't work,
the custom service handler is never called. i used the snippets from the
header docu and changed the myhandlerservice class to the proper qualifing
class. no success.
the "classpath root" is the root of my project directory (where the
plugin.xml is located for example), isn't it? or where do i have to put
the servicehandler.xml?


i have another question, i have added the extension point

<extension
point="org.eclipse.equinox.http.registry.resources">
<resource
alias="/test"
base-name="/reports">
</resource>
</extension>

to my plugin.xml

what would the code look like to register a resource, respectively store a
created pdf file, for example, in the /reports directory?!


Document document = new Document();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
PdfWriter.getInstance(document, baos);
document.open();
document.add(new Paragraph("Hello World"));
document.close();
ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());

RWT.getResourceManager().setContextLoader(getClass().getClas sLoader());
RWT.getResourceManager().register("/reports/test2.pdf", bais);
System.out.println(RWT.getResourceManager().getResource("/reports/test2.pdf "));

i tried it this way but the sysout returns null... iText is used for the
pdf creation.

got any idea?
Re: How to get the Output Stream of the Servlet? [message #71447 is a reply to message #71410] Thu, 24 January 2008 08:47 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: lars.martin.smb-tec.com

You are right. The registration gets never called. That's a known problem.
Until bug fixing the workaround is to explicitely register your custom
service handler.

public Activator() {
// default registration get never called, so explicitely register handler
here
org.eclipse.rwt.internal.service.ServiceManager.registerServ iceHandler(
"YourService", new YourServiceHandler() );
}
Re: How to get the Output Stream of the Servlet? [message #71464 is a reply to message #71447] Thu, 24 January 2008 09:23 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: benjamin.wolff.web.de

hmm, when i put this line the Activator constructor or anywhere else in
Activator.java the app won't start anymore (entrypoint does not exist). i
put it in preWindoOpen(), this works for now. thank you very much lars!

but are all these "Discouraged access" warnings are annoying somehow...


now only the problem with the resources remains :).
Re: How to get the Output Stream of the Servlet? [message #71501 is a reply to message #71464] Thu, 24 January 2008 09:46 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: lars.martin.smb-tec.com

Ben W. wrote:

> hmm, when i put this line the Activator constructor or anywhere else in
> Activator.java the app won't start anymore (entrypoint does not exist). i
> put it in preWindoOpen(), this works for now. thank you very much lars!

I can't believe this. We've successfully implemented custom service
handlers several times before. The registerServiceHandler() method simply
put the given handler into a map. That's all. Can you run your application
in debug mode. I'm sure there is some other exception catched and wrapped
with this "entry point does not exist" execption.

> but are all these "Discouraged access" warnings are annoying somehow...

Yes.

> now only the problem with the resources remains :).

You don't need to register a resource when using your own service handler.
You can implement whatever your want to write into the request
outputstream.

public void service() throws IOException, ServletException {
HttpServletResponse response = ContextProvider.getResponse();
response.setContentType( "..." );
response.setHeader( "Content-Disposition", "attachment;
filename=\"...\"" );
response.getOutputStream().write( ... );
}
Re: How to get the Output Stream of the Servlet? [message #71520 is a reply to message #71501] Thu, 24 January 2008 10:01 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: benjamin.wolff.web.de

Lars Martin wrote:

> Ben W. wrote:

>> hmm, when i put this line the Activator constructor or anywhere else in
>> Activator.java the app won't start anymore (entrypoint does not exist). i
>> put it in preWindoOpen(), this works for now. thank you very much lars!

> I can't believe this. We've successfully implemented custom service
> handlers several times before. The registerServiceHandler() method simply
> put the given handler into a map. That's all. Can you run your application
> in debug mode. I'm sure there is some other exception catched and wrapped
> with this "entry point does not exist" execption.

yes indeed, there was something in MyServiceHandler() that threw an
exceptions. sry, my mistake, didn't think that far...

>> but are all these "Discouraged access" warnings are annoying somehow...

> Yes.

as long as they don't interfere with the execution of the programm...

>> now only the problem with the resources remains :).

> You don't need to register a resource when using your own service handler.
> You can implement whatever your want to write into the request
> outputstream.

> public void service() throws IOException, ServletException {
> HttpServletResponse response = ContextProvider.getResponse();
> response.setContentType( "..." );
> response.setHeader( "Content-Disposition", "attachment;
> filename="..."" );
> response.getOutputStream().write( ... );
> }

thats what i did, but with a file i copied into the folder in eclipse.
when i dynamically generate a pdf file i have to store it in order to do
the
?custom_service_handler=myServiceHandler&file=pdftest.pd f trick. i can
read the resource and put it as bytearray into the response content with
the proper mime type. but the pdf is created in another point in the
application... so i need to do a data exchange, and i don't know how to do
it except register the created pdf as a resource and read it in the
service() method...
Re: How to get the Output Stream of the Servlet? [message #71538 is a reply to message #71520] Thu, 24 January 2008 10:30 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: lars.martin.smb-tec.com

Ben W. wrote:

> thats what i did, but with a file i copied into the folder in eclipse.
> when i dynamically generate a pdf file i have to store it in order to do
> the
> ?custom_service_handler=myServiceHandler&file=pdftest.pd f trick. i can
> read the resource and put it as bytearray into the response content with
> the proper mime type. but the pdf is created in another point in the
> application... so i need to do a data exchange, and i don't know how to do
> it except register the created pdf as a resource and read it in the
> service() method...

Then register your resource via

RWT.getResourceManger().register( "itext.pdf", ... InputStream );

and serve the requested file in your custom service handler via

RWT.getResourceAsStream( "itext.pdf" );
Re: How to get the Output Stream of the Servlet? [message #71557 is a reply to message #71538] Thu, 24 January 2008 10:35 Go to previous message
Eclipse UserFriend
Originally posted by: benjamin.wolff.web.de

Lars Martin wrote:

> Ben W. wrote:

>> thats what i did, but with a file i copied into the folder in eclipse.
>> when i dynamically generate a pdf file i have to store it in order to do
>> the
>> ?custom_service_handler=myServiceHandler&file=pdftest.pd f trick. i can
>> read the resource and put it as bytearray into the response content with
>> the proper mime type. but the pdf is created in another point in the
>> application... so i need to do a data exchange, and i don't know how to do
>> it except register the created pdf as a resource and read it in the
>> service() method...

> Then register your resource via

> RWT.getResourceManger().register( "itext.pdf", ... InputStream );

> and serve the requested file in your custom service handler via

> RWT.getResourceAsStream( "itext.pdf" );



this is what i tried:


Document document = new Document();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
PdfWriter.getInstance(document, baos);
document.open();
document.add(new Paragraph("Hello World"));
document.close();
ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());

RWT.getResourceManager().setContextLoader(getClass().getClas sLoader());
RWT.getResourceManager().register("/reports/test2.pdf", bais);
System.out.println(RWT.getResourceManager().getResource("/reports/test2.pdf "));

the sysout returns "null", so i assume that the register failed...
Previous Topic:Do you replace Classes in rt.jar?
Next Topic:RAP Webinar - Feb. 13
Goto Forum:
  


Current Time: Fri May 02 11:09:12 EDT 2025

Powered by FUDForum. Page generated in 0.04920 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top