String st = "<query xmlns='http://basex.org/rest'>"+ "<text> insert node <user> <name>qusai</name> "+ "<username>qu</username> <password>qu</password>"+ " </user> into //elib/users</text>"+ "<parameter name='wrap' value='yes'/></query>" conn = (HttpURLConnection) url.openConnection();
conn.setDoOutput(true); conn.setRequestMethod("POST"); conn.setRequestProperty("Content-Type", "application/xml"); conn.setRequestProperty("Authorization", "Basic " + encoded);
out = conn.getOutputStream(); out.write(res.getBytes("UTF-8")); out.close(); System.out.println(conn.getResponseMessage());
*and the result from server is : Bad Request* *????* *any answer* * *
Dear Khaled,
it would be great if could you provide us with some valid Java code. Otherwise, it will be rather difficult to keep track of the problem in reasonable time.
Best regards, Christian ___________________________
On Sun, May 13, 2012 at 7:23 PM, khaled refai khaled.refai@gmail.com wrote:
String st = "<query xmlns='http://basex.org/rest'>"+ "<text> insert node <user> <name>qusai</name> "+ "<username>qu</username> <password>qu</password>"+ " </user> into //elib/users</text>"+ "<parameter name='wrap' value='yes'/></query>" conn = (HttpURLConnection) url.openConnection();
conn.setDoOutput(true); conn.setRequestMethod("POST"); conn.setRequestProperty("Content-Type", "application/xml"); conn.setRequestProperty("Authorization", "Basic " + encoded);
out = conn.getOutputStream(); out.write(res.getBytes("UTF-8")); out.close(); System.out.println(conn.getResponseMessage());
and the result from server is : Bad Request ???? any answer
Dear Christian,
I am really thankful for your attention, I wrote some jsp pages with servlets to read from and write on the data base using REST webservice it works when I run a query that read a data, but it does not work when I run a query to insert a node:
public boolean insert(Vector<String> values) throws BaseXException { Enumeration elnum = elems.elements(); Enumeration valenum = values.elements(); String elem; String val; String st = " insert node <" + parentElem + "> "; String res; String user="admin"; String pass="admin"; String encoded=Base64.encode(user+":"+pass); while (elnum.hasMoreElements()) { elem = elnum.nextElement().toString(); val = valenum.nextElement().toString(); st = st + " <" + elem + ">" + val + "</" + elem + "> "; } st = st + "</" + parentElem + ">" + " into //elib/" + tableName;
res="<query xmlns='http://basex.org/rest'>\n"+ " <text>"+st+"</text>\n"+ " <parameter name='wrap' value='yes'/>\n" + "</query>"; // the res would be : // <query xmlns='http://basex.org/rest'> // <text> insert node <user> <name>khaledRefai</name> // //<username>khaled89</username> //<password>khaled</password> </user> //into //elib/users</text> // <parameter name='wrap' value='yes'/> //</query> try { conn = (HttpURLConnection) url.openConnection(); conn.setDoOutput(true); conn.setRequestMethod("POST"); conn.setRequestProperty("Content-Type", "application/xml"); conn.setRequestProperty("Authorization", "Basic " + encoded);
out = conn.getOutputStream(); out.write(res.getBytes("UTF-8")); out.close(); int code = conn.getResponseCode(); System.out.println(conn.getResponseMessage()); //it print "Bad Request" if(code==200) return true; else return false;
} catch (IOException ex) { return false; }
}
thank you in advance
Dear Khalef,
sorry for being persistent, but due to our never ending, or ever growing, list of unpaid todos (which may be the destiny, or curse, of every open source project), I'd like to ask once more for a short, self-contained example that runs out of the box and saves us valuable time (see e.g. http://sscce.org/ for more details). In your example, I'd first have to guess what the variables elems, parentElem, tableName are, what "url" refers to, etc.
Thanks a lot, Christian _________________________________
I am really thankful for your attention, I wrote some jsp pages with servlets to read from and write on the data base using REST webservice it works when I run a query that read a data, but it does not work when I run a query to insert a node:
public boolean insert(Vector<String> values) throws BaseXException { Enumeration elnum = elems.elements(); Enumeration valenum = values.elements(); String elem; String val; String st = " insert node <" + parentElem + "> "; String res; String user="admin"; String pass="admin"; String encoded=Base64.encode(user+":"+pass); while (elnum.hasMoreElements()) { elem = elnum.nextElement().toString(); val = valenum.nextElement().toString(); st = st + " <" + elem + ">" + val + "</" + elem + "> "; } st = st + "</" + parentElem + ">" + " into //elib/" + tableName;
res="<query xmlns='http://basex.org/rest'>\n"+ " <text>"+st+"</text>\n"+ " <parameter name='wrap' value='yes'/>\n" + "</query>"; // the res would be : // <query xmlns='http://basex.org/rest'> // <text> insert node <user> <name>khaledRefai</name> // //<username>khaled89</username> //<password>khaled</password> </user> //into //elib/users</text> // <parameter name='wrap' value='yes'/> //</query> try { conn = (HttpURLConnection) url.openConnection(); conn.setDoOutput(true); conn.setRequestMethod("POST"); conn.setRequestProperty("Content-Type", "application/xml"); conn.setRequestProperty("Authorization", "Basic " + encoded);
out = conn.getOutputStream(); out.write(res.getBytes("UTF-8")); out.close(); int code = conn.getResponseCode(); System.out.println(conn.getResponseMessage()); //it print "Bad Request" if(code==200) return true; else return false;
} catch (IOException ex) { return false; }
}
thank you in advance
basex-talk@mailman.uni-konstanz.de