Hello folks,
I'm trying to do a wfs post request via java to the geoserver. I just want to do a simple getFeature Requst. For testing I took the xml body from the demo page. (WFS_getFeature_1.0.xml). Error and Java Code following...
Error response:
------------------------------------------------
"<?xml version="1.0" encoding="UTF-8"?>
<ows:ExceptionReport version="1.0.0"
xsi:schemaLocation="http://www.opengis.net/ows http://localhost:8080/geoserver/schemas/ows/1.0.0/owsExceptionReport.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ows="http://www.opengis.net/ows">
<ows:Exception exceptionCode="MissingParameterValue" locator="request">
<ows:ExceptionText>Could not determine geoserver request
from http request org.apache.catalina.connector.RequestFacade@anonymised.com</ows:ExceptionText>
</ows:Exception>
</ows:ExceptionReport>"
------------------------------------------------
Here's my Java Code:
------------------------------------------------
public void postTest() throws Exception{
URL url = new URL ("http://localhost:8080/geoserver/wfs"\);
String xml ="<wfs:GetFeature service='WFS' version='1.0.0' outputFormat='GML2' xmlns:topp='http://www.openplans.org/topp’ xmlns:wfs='http://www.opengis.net/wfs’ xmlns:ogc='http://www.opengis.net/ogc’ xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance’ xsi:schemaLocation='http://www.opengis.net/wfs http://schemas.opengis.net/wfs/1.0.0/WFS-basic.xsd’><wfs:Query typeName='topp:states'><ogc:Filter><ogc:FeatureId fid='states.3'/></ogc:Filter></wfs:Query></wfs:GetFeature>";
String tmp = null;
// Get connection
URLConnection urlConn = url.openConnection();
urlConn.setDoInput (true);
urlConn.setDoOutput (true);
urlConn.setUseCaches (false);
urlConn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
// Write output
DataOutputStream printout = new DataOutputStream (urlConn.getOutputStream ());
String data = URLEncoder.encode("url", "UTF-8") + "=" + URLEncoder.encode("http://localhost:8080/geoserver/wfs", "UTF-8");
data += "&" + URLEncoder.encode("body", "UTF-8") + "=" + URLEncoder.encode(xml, "UTF-8");
data += "&" + URLEncoder.encode("username", "UTF-8") + "=" + URLEncoder.encode("admin", "UTF-8");
data += "&" + URLEncoder.encode("password", "UTF-8") + "=" + URLEncoder.encode("geoserver", "UTF-8");
printout.writeBytes (data);
printout.flush ();
printout.close ();
// Get response
DataInputStream input = new DataInputStream (urlConn.getInputStream ());
while (null != ((tmp = input.readLine())))
System.out.println (tmp);
input.close();
}
------------------------------------------------
The console says:
09 Jun 14:07:48 INFO [geoserver.filters] - 127.0.0.1 "POST /geoserver/wfs" took 221ms
09 Jun 14:08:16 INFO [geoserver.filters] - 127.0.0.1 "POST /geoserver/wfs" "Java/1.6.0_03" ""
09 Jun 14:08:16 WARN [geoserver.ows] -
org.geoserver.platform.ServiceException: Could not determine geoserver request from http request org
.apache.catalina.connector.RequestFacade@anonymised.com
....
What's the problem? Maybe someone of you can help me.
Regards,
Sebastian