RE: Getting images from Interbase database

2003-12-16 Thread Remke Rutgers
His Janusz,

I think the problem is that you store your connection in your session.
Alle threads are sharing the same session object, and are therefore using
the same connection object.
Subsequent access (within the same session) to your ImageAction will
probably succeed, but concurrent access will fail.
As you said, your application gets only few request, so I think that is why
the problem did not occur before. (Concurrent requests in the same session
will have the same problem)

I guess you want to 'cache' your connection to avoid the overhead of
creating and openening a connection every time.
You should really use a different mechanism to achieve this.
Take a look at DBCP (database connection pooling), one of the
jakarta-commons components (http://jakarta.apache.org/commons/dbcp/).

There is one other thing that can go wrong in your code:
You call response.setContentLength(len); after you've written the complete
image to your OutputStream.
The call to response.setContentLength(len); attempts to send a HTTP header
value. If the the response was already flushed to the client, this header
will never be sent.
The same remark is valid for response.setContentType(image/jpeg);
I suggest you to call response.setContentType(image/jpeg); before you
stream the binary image.
Since you know the size of the retrieved image only after you've read the
binary stream, you cannot call response.setContentLength(len) earlier. 
An alternative might be (if your driver supports it):
java.sql.Blob blob = rs.getBlob(1);
len = blob.length();
response.setContentLength(len);
InputStream is = blob.getBinaryStream();
etc.

Good luck,

Remke 

 -Oorspronkelijk bericht-
 Van: Janusz Dziadon [mailto:[EMAIL PROTECTED]
 Verzonden: dinsdag 16 december 2003 0:37
 Aan: [EMAIL PROTECTED]
 Onderwerp: Getting images from Interbase database
 
 
 Hi all!
 
 I am using Struts from about half a year, and it works good. 
 I have small
 webapp using Interbase database by Interclient driver.
 When I wanted to use only text data from queries all was fine 
 and simply,
 even when single jpegs from blob fields. But now I must display some
 images on one page and I have some errors with doing that.
 
 My action classes do their work in normal way - using 
 database connection
 they get data by ResultSets, transfer them to my java beans, 
 and jsp page is
 responsible for formatting and displaying this data. But, 
 like I've told it
 is related only to text data. All pages till now displayed no 
 more than one
 image from database. To achieve that, on required jsp pages is placed
 html:img tag with proper properties (ie. image id) which is 
 linked to
 special action (ImageAction) descendant properly configured 
 in struts.xml
 file. His work is to:
 - extract parameters from request (imageid=87)
 - get one-row ResultSet (rs) with image (select image from 
 images where
 imageid=87)
 - gets this image by rs.getBinaryStream(1)
 - copy this stream to ServletOutputStream
 - set response mime type and len
 - send response by closing its output stream
 (code of this class is attached below)
 When I need one image on browser page then jsp page contains one tag
 html:img page=/smallImage.do?imageid=87 /. And all works FINE.
 SmallImage action simply calls ImageAction. Requests from 
 users goes to
 server not often.
 
 But now I need display html-table with five images and this 
 technique not
 work. Jsp page contains
 table
   tr
 tdhtml:img page=/smallImage.do?imageid=87 //td
 tdhtml:img page=/smallImage.do?imageid=88 //td
   /tr
   tr
 tdhtml:img page=/smallImage.do?imageid=89 //td
 tdhtml:img page=/smallImage.do?imageid=90 //td
  /tr
 /table
 As you see one big change to previous page is that 
 ActionImage class is
 called four times to fill one page, and this request goes to 
 server almost
 at once.
 
 Errors suggest me, that responsible for this situation goes 
 from ImageAction
 to Interclient, but I'm not sure. Generally most frequently I 
 get no images,
 sometimes only one image, but never all four required. All images in
 database table are in good format, because when I want to get 
 only one image
 on page they are displayed correctly.
 
 So I've started my investigation on How ImageAction doesn't work
 correctly. I've put into ImageAction class some additional 
 code to write
 out whats going on. I must say that it looks like action gets 
 four request,
 starts simultaneously create statements, and gets 
 ResultSets. Problems is
 when its starts to copy blob stream (place is marked in code).
 I've get JDBC IOException: Invalid operation to read on 
 closed blob stream.
 See API reference for exception 
 interbase.interclient.BlobIOEception. All
 subsequent tries to copy ends with error [interclient] Client/server
 protocol error: Unexpected token in network message received from
 Interserver. The internal code is 101. See Api reference for exception
 interbase.interclient.RemoteProtocolException. Connection to 
 database is

RE: Character Encoding

2003-10-01 Thread Remke Rutgers
Hi Stephan, 

The instruction you use to force UTF-8 looks fine to me, so I don't know why
it does not work. This is the way we do it in several web applications too.
They are non-public sites, so I am sorry I can not simply let you try them
out.
Manual transformation should not be necessary.
First of all can you make sure that the contenttype header is really sent to
the browser?
A simple utility that shows you all HTTP requests and response headers
(plugin for IE) can be found at:
http://www.blunck.info/ieHTTPHeaders.html

Also (assuming you are using IE), right-click in your page, move to Encoding
and see what is selected there. It should be UTF-8.

If you come to the conclusion the response is indeed sent as UTF-8, but
still characters are not showing correctly, than I think something is wrong
with the source data.

Remke
 -Oorspronkelijk bericht-
 Van: Stephan Wiesner [mailto:[EMAIL PROTECTED]
 Verzonden: woensdag 1 oktober 2003 10:10
 Aan: Struts Users Mailing List
 Onderwerp: Character Encoding
 
 
 Hi,
 I have a web application that needs to support arabic, so I 
 use UTF8 for 
 encoding:
 %@ page language=java contentType=text/html; charset=UTF-8%
 
 This leads to some characters beeing displayed wrong (works fine with 
 Latin-1), like the German 'Ü'. However I can mix them if I write them 
 like '\u05E9' by hand.
 My text strings come from a database and from my ressource bundles. I 
 could use a Servlet filter to change the Strings before serving them, 
 just have no idea how to transform them?
 
 Stephan
 
 
 -
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]
 

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



RE: Image cache problem

2003-06-19 Thread Remke Rutgers
Hi David,

I think it has nothing to do with browser versions, I think this is only
caused by caching settings. You must realize that caching can occur both in
browser cache (configure this using Tools-Internet
Options-General-Temporary Internet Files-Settings) and in proxy server
cache. You should force your createimage.do to be non cachable. (Instruct
proxy servers and browsers to always retrieve a fresh version)
You can achieve this by setting a HTTP header:
response.setHeader(Cache-Control,no-cache);
see the javadocs for more on the setHeader method of the response object.

See http://www.mnot.net/cache_docs/ for a very good tutorial on caching.

Remke


-Oorspronkelijk bericht-
Van: David Bolsover [mailto:[EMAIL PROTECTED]
Verzonden: donderdag 19 juni 2003 13:51
Aan: Struts User
Onderwerp: Image cache problem


Hi all

I have been using struts for some time now but a new problem has come up:

I use a form to select some options needed retrieve some data required to
generate a graph.

For the sake of clarity, I'll call this retrieveDataAction.

retrieveDataAction gets the data and places it into session scope under key
'GRAPHDATA' the user is then forwarded to displaydata.jsp.

displaydata.jsp contains the following (simplfied):

logic:present name=GRAPHDATA scope=session 

phtml:img page=/createimage.do //p

/logic:present

The createimageAction retrieves the GRAPHDATA from session scope, generates
a
gif image and writes it to response.OutputStream(), closes the stream and
returns null.

The problem I have is that at least one client (using IE 5) finds that the
same
image is always presented even though he has requested some different data.
I
have not been able to reproduce the problem using an IE 6 client - does
anyone
know if this is an IE 5 'feature' and - is there a solution?

David Bolsover


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



RE: bean:message problems with i18n

2003-02-13 Thread Remke Rutgers
Hello Bernard,

I agreen with James, that it sounds very much like a caching issue. Could
you be behind a caching server without knowing it? (I don't know enough
about proxy setups to tell how you could verify this.)
Why I think it looks very much like a caching issue, is because you say
unvisited pages show up in English, and already visited pages show up in
German.

Anyway, I think an easy way to check if this is a caching issue or not, is
to include a current date (server code of course, not javascript) on your
pages. Just try it out on a couple of different pages.

By the way, you can avoid caching (both by servers and browsers) by
including the following lines first thing in your jsp(s):
% 
response.setHeader(Pragma, No-cache);
response.setHeader(Cache-Control, no-cache);
response.setDateHeader(Expires, 1);
%

In our application we are using tiles. I found that it did not work to
insert these lines in an inserted tile, they have to be in the top layout
file.
(Look in the javadocs for the setHeader functions to get a hint why. I don't
remember exactly why this was soand I am not even sure I fully understood
the reason at the moment I investigated it.)

Good luck,

Remke Rutgers

-Oorspronkelijk bericht-
Van: Hirschmann, Bernhard [mailto:[EMAIL PROTECTED]]
Verzonden: vrijdag 14 februari 2003 8:18
Aan: 'Struts Users Mailing List'
Onderwerp: AW: bean:message problems with i18n



Hello all!

this is still an open thread for me. It's horrifying... 

Any help highly appreciated!

Regards,
Bernhard



-Ursprüngliche Nachricht-
Von: Hirschmann, Bernhard 
Gesendet: Donnerstag, 13. Februar 2003 19:15
An: 'Struts Users Mailing List'
Betreff: AW: bean:message problems with i18n



James, thanks for your help!

I tried it in different browser types and in different windows. So this
appears also in different HTTPSessions. I can reload as much as I want, and
I do not use any proxies for that. So I guess it is not a caching issue.

I checked the html:html tag. The lang attribute has always the correct
value, like set in the Action.setLocale() method. However, the wrong
messages are always in the language, in which the bean:message tag has
requested the message the very first time. The fallback mechanism just
doesn't work anymore.

Does the bean:message tag use some kind of caching using the resources?

I also tried to switch back to struts 1.1b2, but with the same result.

Bernhard


-Ursprüngliche Nachricht-
Von: James Childers [mailto:[EMAIL PROTECTED]]
Gesendet: Donnerstag, 13. Februar 2003 18:57
An: Struts Users Mailing List
Betreff: RE: bean:message problems with i18n


Have you tried opening up a new browser and trying again? Sounds like it may
be a caching issue. Also, check that your html:html tag is generating the
correct lang attribute. Reload the page and view source, then check the
HTML tag.

-= J

 -Original Message-
 From: Hirschmann, Bernhard [mailto:[EMAIL PROTECTED]]
 Sent: Thursday, February 13, 2003 11:41 AM
 To: Struts User Mailing List (E-Mail)
 Subject: bean:message problems with i18n
 
 We have big problems with the use of the i18n messages, used with the
 bean:message tag. But the problems encounter only in a 
 special scenario:
 
 1.) A German user loggs in - a German locale is set using
 Action.setLocale()
 
 - exploring some JSPs, all messages are in German, that's good.
 
 2.) The German user loggs out.
 
 3.) A English user loggs in - a English locale is set using
 Action.setLocale()
 
 - all messages already show in 1.) are still shown in 
 German. But messages
 from other JSPs not visited in 1.) are shown correctly in English.
 
 
 We use two ApplicationResources:
 ApplicationResources.properties (the fallback version, in 
 English language)
 ApplicationResources_de.properties (the German variant)
 
 
 It seems to me, that the mechanism using the 
 ApplicationResources is the
 reason, but I'm not sure... I debuged through the sources but 
 didn't find
 the problem.
 
 Another strange thing is, that this has worked earlier, but 
 now something
 must have happend while our further developing processes, so 
 that this 'bug'
 is appearing. So I tried some older versions of this product 
 we delivered to
 our customers, and suddenly in those versions is this bug 
 also present.
 Maybe something on our application server has happend (WS 
 4.0.4), but I have
 no clue what this could be... In WSAD 4.0.2 it's the same 
 like in WS 4.0.4.
 
 Any hint is highly appretiated. (I'm working on this the 
 whole day now...)

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

-
To unsubscribe, e-mail: [EMAIL

RE: Securing a download

2002-12-23 Thread Remke Rutgers
Hi Christophe,

This looks very similar to a problem I had (and I bet we are not the only
ones).

Some codes snippets from the RetrieveFileServlet I wrote (a modified version
of code from Wrox 'Professional JSP, 2nd edition').

In your doGet():
// I omitted the exception handling and stream manipulation stuff

String file = request.getParameter(file);

// perform your logic to find out whether the current user may access this
file.
// if not allowed: response.setStatus(HttpServletResponse.SC_FORBIDDEN);

// if allowed continue
String mimetype = null;
if (file != null)
mimetype = getServletContext().getMimeType(file);
if (mimetype != null)
{
// set the content type to the parameter passed.
response.setContentType(mimetype);
}

/*
Store the files in a directory not accessible as a webresource, but
accessible by the useraccount under which your webserver is running.
*/
String basedir = ..; // some directory, hardcodes, properties,
JNDI, whatever
fis = new FileInputStream(basedir+file);
byte[] buffer = new byte[8192];
int size;

size = fis.read(buffer);

while (size != -1)
{
out.write(buffer, 0, size);
size = fis.read(buffer);
}

This should help to handle your security requirements. This lets the browser
determine if the file can be opened in the window (recognized filetypes) or
not.

As for always offering the save as... dialog with the correct filename, you
should be able to achieve that using:
response.addHeader(Content-Disposition, attachment;
filename=+file); 

Good luck,

Remke

-Oorspronkelijk bericht-
Van: Christophe Vigouroux [mailto:[EMAIL PROTECTED]]
Verzonden: maandag 23 december 2002 15:37
Aan: 'Struts Users Mailing List'; [EMAIL PROTECTED]
Onderwerp: Securing a download


Hi all,

Here is my problem: I have a user which is granted access to some files to
download. I want to put all the files downloadable by all the users in a
common directory (many users may download the same file), but with the
possibility to deny the download to users not identified by my application
(I've put a bean in the session scope to identify the user).

I first tried to create an Action class taking the filename of the file to
download in parameter, forwarding to the path of my file with a redirect. It
works fine for the first requirement, but it fails to deny the download to
not identified users, because the file is in a public directory. If I try to
put my file directory within WEB-INF, I'm getting the access deny message
from my servlet container (because of the redirect).

Even if my solution does not show the URL to get directly the file (so,
nobody should know the URL), it is not a good one because the security
relies on that hypothesis... I'd prefer to have a servlet or an action or a
jsp which checks the identification of the user, then modifies the HTTP
header with the good mime type (but which one? my files could be .exe, pdf
and so on...), and include the file. But as far as I tried this, my problem
is that my browser give a filename that I don't want (for example I have a
download.do?file=myApp.exe and the browser wants to save download.do where
I wanted it to be myApp.exe.

Hope anybody has a suggestion ;)
Thanks !!



--
To unsubscribe, e-mail:
mailto:[EMAIL PROTECTED]
For additional commands, e-mail:
mailto:[EMAIL PROTECTED]

--
To unsubscribe, e-mail:   mailto:[EMAIL PROTECTED]
For additional commands, e-mail: mailto:[EMAIL PROTECTED]




ConvertUtilts.register(): where to call?

2002-05-02 Thread Remke Rutgers

Hi fellowstrutsers,

What is the best (logical, efficient, safe...) place to call
ConvertUtils.register() in a Struts Webapp?

Anyone?

Remke Rutgers - [EMAIL PROTECTED]
Technisch Consultant

Bright Alley  Knowledge  Learning B.V.
Media Park - Sumatralaan 45
Postbus 10 - 1200 JB Hilversum
web  www.brightalley.com
tel +31 35 6774000 / fax +31 35 6774355

--
To unsubscribe, e-mail:   mailto:[EMAIL PROTECTED]
For additional commands, e-mail: mailto:[EMAIL PROTECTED]