On 22 oct, 19:37, Alex Rice <
mindl...@gmail.com> wrote:
> My cms server (Alfresco) requires form POSTs to have the tag
> enctype="multipart/form-data" (even if no files or uploads are in the
> form).
Extensively working with Alfresco, I can assure you Web Scripts can
actually accept application/x-www-form-urlencoded data. You'll just
get them into args and argsM instead of formdata. Note that this is a
side-effect of running the Web Script within a servlet context (and
probably constrained to running within Tomcat) as it depends on the
implementation of ServletRequest.getParameterMap(), which (at least in
Tomcat) decodes application/x-www-urlencoded request bodies.
I was with Michael Uzquiano (Director of Alfresco WCM Products) and
David Caruana (Alfresco Chief Architect) last week and we talked about
it. I asked them if they could at least document it, or even better
guarantee this behavior even in non-servlet environments (such as the
unit-testing standalone Web Script runtime).
But this is all going to change with Alfresco 3 though...
(if you can read French, I wrote some notes about the new Alfresco
Surf platform on my company's blog, and some of this is available on
the Web Script side:
http://blog.atolcd.com/?p=26 )
> Since GWT doesn't provide any methods for constructing the body/
> payload of post requests, I am trying to roll my own but so far my
> server isn't recognizing the data.
I wrote one too for GWT-in-the-AIR (it outputs to a ByteArray, which
is specific to Adobe AIR, but you could easily change it to append to
a StringBuilder):
http://code.google.com/p/gwt-in-the-air/source/browse/trunk/src/net/ltgt/gwt/air/user/client/ui/impl/MultipartFormDataGenerator.java
> This is not an SOP issue; I am
> hitting the server successfully. Can anyone spot any errors in the
> following? I have GWT.Logged the requestData and it looks correct
> AFAIK based on the RFC and web articles I've read about this.
>
> In a subclass of RequestBuilder I have:
>
> // post body delimiters and headers:
> public static final String BOUNDARY = "c0ff33";
> public static final String CONTENT_DISP_LINE = "Content-disposition:
> form-data; filename=\"\" name=\"";
If you don't send files, don't output filename=""
> public static final String TEXT_PLAIN = "Content-type: text/plain;
> charset=utf-8";
>
> // http headers:
> public static final String CONTENT_TYPE_HEADER = "Content-type";
> public static final String CONTENT_LENGTH_HEADER = "Content-
> length";
> public static final String CONTENT_TYPE = "multipart/form-data;
> boundary="+BOUNDARY;
>
> // builds the body of the request, and sets appropriate
> headers
> public void setMultipartFormData(final String key, final String
> value)
> {
> StringBuffer body = new StringBuffer();
> body.append("--" + BOUNDARY+"\n");
Line separator should be CRLF (\r\n)
> body.append(CONTENT_DISP_LINE+ key+"\"\n");
> body.append(TEXT_PLAIN+"\n\n");
> body.append(value);
> body.append("\n--" + BOUNDARY+"--\n");
> setHeader(CONTENT_TYPE_HEADER, CONTENT_TYPE);
> setHeader(CONTENT_LENGTH_HEADER, String.valueOf(body.length()));
Content-Length is expressed in bytes, while body.length() is a
character count; you shouldn't set the Content-Length (the browser
will do it for you eventually)
> setRequestData(body.toString());
> }
>
> // in another class:
> MyRequestBuilder rb = new MyRequestBuilder(RequestBuilder.POST, url);
> rb.setMultipartFormData("json", jsonStr);
> rb.setCallback(new RequestCallback() ...);
> rb.send();
>
> An alternate idea would be to have a hidden FormPanel that I setup and
> let the browser do the Posting for me. However, a drawback there
> would be that the FormHandler is less useful than the
> RequestCallback.
>
> Any suggestions appreciated. Thanks
The best advice I could give you is to use application/x-www-form-
urlencoded with your Alfresco Web Script ;-)