OK, please disregard. Issue resolved.
org.apache.commons.codec.binary.Base64().encode()
adds control characters \r\n to the end of the authorization string.
Although this should keep the response code add 401, it doesn't, so I
was looking at the wrong spot last night. Hope this helps somebody
else out who might run into a similar problem.




On Mar 2, 9:49 pm, Joa <joachim.pfeif...@gmail.com> wrote:
> Any takers? I've carried the code over to a regular Java Application
> and it runs through without a hitch. Hmm, looks I am stuck with a GAE
> bug?
>
> On Mar 2, 6:54 am, Joa <joachim.pfeif...@gmail.com> wrote:
>
> > I am having difficulty POSTing and reading from a web server from GAE.
> > I can authenticate but the webserver does not accept the XML file I am
> > POSTing (which includes a query). I am not running the webserver in
> > question, so I have no insight into what might be wrong at that end
> > (or set it up differently).
>
> > First, a sanitized snippet of the curl statement that returns the
> > desired result (on OSX):
> > $ curlhttp://targetwebserver.org/servlet-uusername:password -d '<?
> > xml version="1.0" encoding="UTF-8" standalone="yes"?><Tag> .... </
> > Tag>'
> > That to me confirm the webserver works alright.
>
> > Below now a snippet of the code (sanitized and rough) that I cannot
> > get to work. Again, authentication seems to work (I am not getting
> > responseCode 401), but whatever I have tried, I cannot get over
> > responseCode 400 and a corresponding boilerplate error message from
> > the webserver.
>
> > <--------- snip ------->
> > String requestString = "<?xml version="1.0" encoding="UTF-8"
> > standalone="yes"?><Tag> .... </Tag>"; // Also tried all sorts of
> > encoding, no luck
> > URL url = new URL("targetwebserver.org/servlet ");
> > HttpURLConnection conn = (HttpURLConnection)url.openConnection();
> > conn.setRequestMethod("POST");
> > conn.setDoOutput(true);
> > conn.setDoInput(true);
> > conn.addRequestProperty("Content-type", "text/xml"); // tried
> > "application/xml" as well, no luck
>
> > // Authenticate (seems to work OK)
> > String authData = "username:password";
> > byte[] encodedAuthData = new
> > org.apache.commons.codec.binary.Base64().encode (authData.getBytes());
> > String authString = "Basic ";
> > for (int i = 0; i < encodedAuthData.length; i++)
> >         authString += (char)encodedAuthData[i];
> > conn.addRequestProperty ("Authorization", authString);
>
> > // Post request
> > PrintWriter pw = new PrintWriter(conn.getOutputStream()); // tried
> > OutputStreamWriter as well, no luck
> > pw.println(requestString);
> > pw.close();
>
> > responseCode = conn.getResponseCode();
> > if (responseCode == 200) {
> >         InputStream in = conn.getInputStream();
> >         BufferedReader rd = new BufferedReader(new
> > InputStreamReader(conn.getInputStream()));
> >         String line; while ((line = rd.readLine()) != null)
> > { log.info(line); }}
>
> > <--------- snip ------->
>
> > Please have a look at this - help's appreciated!

-- 
You received this message because you are subscribed to the Google Groups 
"Google App Engine for Java" group.
To post to this group, send email to google-appengine-j...@googlegroups.com.
To unsubscribe from this group, send email to 
google-appengine-java+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-appengine-java?hl=en.

Reply via email to