[appengine-java] Difficulty querying webserver through POSTing XML text
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): $ curl http://targetwebserver.org/servlet -u username:password -d ' ' 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 = " "; // 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.
[appengine-java] Re: Difficulty querying webserver through POSTing XML text
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 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-u username:password -d ' xml version="1.0" encoding="UTF-8" standalone="yes"?> 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 = " standalone="yes"?> "; // 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.
[appengine-java] Re: Difficulty querying webserver through POSTing XML text
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 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 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>' > > 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 = " > standalone="yes"?> "; // 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.
[appengine-java] Update to GAE/J 1.3.2 -> Project in Eclipse broken
I've tried to update GAE to 1.3.2. Now the project is broken and I seem to be not even able to revert back to 1.3.1. I've taken the following steps: - Trying to locate instructions. Couldn't find any, so this must be simple... - Updated Google plugin through Help -> Check for updates. Checks out - Then downloaded GAE 1.3.2 for Java, unzip - Set Project Properties using Google > App Engine. "Use specific SDK" set to 1.3.2. Now the project root in the Eclipse Package Explorer is marked with an error. The project won't start any longer without an error message and dumps stack traces. To my dismay, any changes in this panel do not seem to have an impact whatsoever now. -- 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.
[appengine-java] Re: Update to GAE/J 1.3.2 -> Project in Eclipse broken
On Mar 29, 9:24 am, Jason Parekh wrote: > Hi Moritz, > > Could you try the following: Thanks guys - I had to toy with this some more to find out to update GAE through Eclipse's plugin update mechanism. No downloading of the SDK and manually pointing to the new SDK 'round here. Would be a nice touch if the GAE team included some instructions like their peers on Android (and prolly other projects) do... -- 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.
[appengine-java] Handling ISO-8559-1 encoded parameter values in request
I've run into a problem reading parameters with values that are encoded in ISO-8559-1 (I think). Here's an example of a request string: GET /ws/V1/routes?agency=CIT%20Vall%E9e-du-Richelieu When reading the value of parameter "agency", the space character "%20" correctly decodes to a space, but the "%E9" character (this is a "é") does not. I tried to manually set the request encoding like this: @Override public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { request.setCharacterEncoding("ISO-8859-1"); String agency = request.getParameter("agency"); But to no avail. Does anybody have an idea how to handle this? -- 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-java@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.
[appengine-java] Re: Group Welcome & Read Me
hi amanda i just joined your group what r we supposed todo?? -- You received this message because you are subscribed to the Google Groups "Google App Engine for Java" group. To view this discussion on the web visit https://groups.google.com/d/msg/google-appengine-java/-/TrW4UMJV9j4J. To post to this group, send email to google-appengine-java@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.