<pre style="word-wrap: brak-word; white-space: pre-wrap;">OK</pre>
instead of just:
OK
The servlet basically responds with:
response.setContentType("text/plain");
response.getWriter().write("OK");
I have tried with curl to post something and servlet (GAE/J SDK) sends
only "OK" but in GWT application I see *<pre style="word-wrap: brak-
word; white-space: pre-wrap;">OK</pre>* when calling event.getResults
().
Any clue what am I doing wrong?
--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To post to this group, send email to google-we...@googlegroups.com.
To unsubscribe from this group, send email to google-web-tool...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.
private static final long serialVersionUID = -7859156850837921885L;
private final Logger logger = Logger.getLogger(getClass().getName());
@SuppressWarnings("unchecked")
@Override
protected void doPost(final HttpServletRequest request, final
HttpServletResponse response) throws ServletException,
IOException {
response.setContentType("text/plain");
if (!ServletFileUpload.isMultipartContent(request))
return;
final PersistenceManager pm = PMF.get().getPersistenceManager();
final ServletFileUpload upload = new ServletFileUpload();
upload.setSizeMax(1024*1024-256);
try {
final FileItemIterator iterator = upload.getItemIterator(request);
while (iterator.hasNext()) {
final FileItemStream fis = iterator.next();
if (!fis.isFormField()) {
final String name = fis.getName();
final String mimeType = fis.getContentType();
// TODO overwrite existing if owner matches
final InputStream is = fis.openStream();
final Blob blob = new Blob(IOUtils.toByteArray(is));
final Document document = new Document(name, mimeType, blob);
final UserService us = UserServiceFactory.getUserService();
final User user = us.getCurrentUser();
document.setOwner(user);
pm.makePersistent(document);
Cache cache = null;
try {
CacheFactory cacheFactory = CacheManager.getInstance
().getCacheFactory();
cache = cacheFactory.createCache(Collections.emptyMap());
cache.put("docname~" + name, blob.getBytes());
cache.put("doctype~" + name, mimeType);
} catch (CacheException e) {
logger.log(Level.SEVERE, "failed to configure cache", e);
}
}
}
response.getWriter().write("OK");
} catch (SizeLimitExceededException e) {
response.getWriter().write("Too big");
} catch (FileUploadException e) {
logger.log(Level.SEVERE, null, e);
} finally {
pm.close();
}
}
}
On 28 pro, 10:56, Andrés Cerezo <acerezoguil...@gmail.com> wrote:
> I need more information, can yoyu sen the source code of the program.java ?
>
> Thanks.
>
> 2009/12/26 Peter Ondruska <peter.ondru...@gmail.com>
>
>
>
> > My upload servlet successfully accepts data however the response sent
> > is not what I expect:
>
> > <pre style="word-wrap: brak-word; white-space: pre-wrap;">OK</pre>
>
> > instead of just:
>
> > OK
>
> > The servlet basically responds with:
>
> > response.setContentType("text/plain");
> > response.getWriter().write("OK");
>
> > I have tried with curl to post something and servlet (GAE/J SDK) sends
> > only "OK" but in GWT application I see *<pre style="word-wrap: brak-
> > word; white-space: pre-wrap;">OK</pre>* when calling event.getResults
> > ().
>
> > Any clue what am I doing wrong?
>
> > --
>
> > You received this message because you are subscribed to the Google Groups
> > "Google Web Toolkit" group.
> > To post to this group, send email to google-we...@googlegroups.com.
> > To unsubscribe from this group, send email to
> > google-web-tool...@googlegroups.com<google-web-toolkit%2Bunsubscr...@googlegroups.com>
> > .
> > For more options, visit this group at
> >http://groups.google.com/group/google-web-toolkit?hl=en.– Skrýt citovaný text –
>
> – Zobrazit citovaný text –
On 28 déc 2009, 14:58, Peter Ondruska <peter.ondru...@gmail.com>
wrote:
On 27 jan, 00:43, mably <fm2...@mably.com> wrote:
> A solution to this problem anyone ?
The JavaDoc says "send back text/html". Follow this advice, really
(just pay attention to "<" and "&" chars that might appear in your
output).
> On 28 déc 2009, 14:58, Peter Ondruska wrote:
>
> > response.setContentType("text/plain");
"Returns: the result html, or null if there was an error reading it"
perhaps it would be more clear to state "Returns: HTML encoded result
regardless of content type returned by servlet..."
> > > response.setContentType("text/plain");– Skrýt citovaný text –
>
> – Zobrazit citovaný text –
On Jan 27, 9:12 am, Peter Ondruska <peter.ondru...@gmail.com> wrote:
> Thanks Thomas, for me it was not obvious:http://google-web-toolkit.googlecode.com/svn/javadoc/2.0/com/google/g...()
>
> "Returns: the result html, or null if there was an error reading it"
> perhaps it would be more clear to state "Returns: HTML encoded result
> regardless of content type returned by servlet..."
FormPanel submits to a hidden iframe, so it gets the result from the
iframe's content (hence the 'null' when you don't submit to the same
domain, because of the SOP), which is always seen as an HTML document,
even if it "represents" a text/plain or an image.
The hint is in FormPanel's no-arg constructor's javadoc:
http://google-web-toolkit.googlecode.com/svn/javadoc/2.0/com/google/gwt/user/client/ui/FormPanel.html#FormPanel()
"""
The back-end server is expected to respond with a content-type of
'text/html', meaning that the text returned will be treated as HTML.
If any other content-type is specified by the server, then the result
HTML sent in the onFormSubmit event will be unpredictable across
browsers, and the onSubmitComplete event may not fire at all.
Tip:
The initial implementation of FormPanel specified that the server
respond with a content-type of 'text/plain'. This has been
intentionally changed to specify 'text/html' because 'text/plain'
cannot be made to work properly on all browsers.
"""
François
On 27 led, 12:18, Thomas Broyer <t.bro...@gmail.com> wrote:
> On Jan 27, 9:12 am, Peter Ondruska <peter.ondru...@gmail.com> wrote:
>
> > Thanks Thomas, for me it was not obvious:http://google-web-toolkit.googlecode.com/svn/javadoc/2.0/com/google/g...()
>
> > "Returns: the result html, or null if there was an error reading it"
> > perhaps it would be more clear to state "Returns: HTML encoded result
> > regardless of content type returned by servlet..."
>
> FormPanel submits to a hidden iframe, so it gets the result from the
> iframe's content (hence the 'null' when you don't submit to the same
> domain, because of the SOP), which is always seen as an HTML document,
> even if it "represents" a text/plain or an image.
>
> The hint is in FormPanel's no-arg constructor's javadoc:http://google-web-toolkit.googlecode.com/svn/javadoc/2.0/com/google/g...()
I don't know if this is a good idea, but I return an HTML document
like...
<html><head><title>results</title></head><body><!-- [put anything you
want to process on submit complete inside this XML comment] --></
body></html>
... and then process the string I get from getResults(), which will be
"<!-- ... -->".
I actually want to send some XML back as the response to the form
submission, and initially tried putting the XML directly inside the
body element, but that has strange results, and so embed it in an XML
comment, then extract from there and parse.
This is an ugly hack, so any other suggestions very welcome.
In particular, the fact that you cannot get access to the status code
of the response is particularly annoying. It means you have to rely on
parsing the value of getResults() to determine whether the upload
failed or succeeded, which isn't consistent with the good practice of
relying on sensible HTTP status codes.
Cheers,
Alistair