Skip to content

Commit

Permalink
[GEOS-7888] ClassCastException when posting WFS Transaction request o…
Browse files Browse the repository at this point in the history
…n a URL containing a valid GetFeature request
  • Loading branch information
aaime committed Dec 13, 2016
1 parent 1868774 commit 47c08ab
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 11 deletions.
32 changes: 21 additions & 11 deletions src/ows/src/main/java/org/geoserver/ows/Dispatcher.java
Expand Up @@ -500,19 +500,19 @@ Service service(Request req) throws Exception {
//check the body
if (req.getInput() != null) {
Map xml = readOpPost(req.getInput());
if (req.getService() == null) {
if (xml.get("service") != null) {
req.setService(normalize((String) xml.get("service")));
}
if (req.getVersion() == null) {
if (xml.get("version") != null) {
req.setVersion(normalizeVersion(normalize((String) xml.get("version"))));
}
if (req.getRequest() == null) {
if (xml.get("request") != null) {
req.setRequest(normalize((String) xml.get("request")));
}
if (req.getOutputFormat() == null) {
if (xml.get("outputFormat") != null) {
req.setOutputFormat(normalize((String) xml.get("outputFormat")));
}
if (req.getNamespace() == null) {
if ((String)xml.get("namespace") != null) {
req.setNamespace(normalize((String)xml.get("namespace")));
}
}
Expand Down Expand Up @@ -623,12 +623,11 @@ Operation dispatch(Request req, Service serviceDescriptor)
}

// ensure the requested operation exists
boolean exists = false;
for ( String op : serviceDescriptor.getOperations() ) {
if ( op.equalsIgnoreCase( req.getRequest() ) ) {
exists = true;
break;
}
boolean exists = operationExists(req, serviceDescriptor);
// did we have a mixed kvp + post request and trusted the body for the request?
if(!exists && req.getKvp().get("request") != null) {
req.setRequest(normalize(KvpUtils.getSingleValue(req.getKvp(), "request")));
exists = operationExists(req, serviceDescriptor);
}

// lookup the operation, initial lookup based on (service,request)
Expand Down Expand Up @@ -790,6 +789,17 @@ else if (parameterType.isAssignableFrom(InputStream.class)) {
return fireOperationDispatchedCallback(req,op);
}

private boolean operationExists(Request req, Service serviceDescriptor) {
boolean exists = false;
for ( String op : serviceDescriptor.getOperations() ) {
if ( op.equalsIgnoreCase( req.getRequest() ) ) {
exists = true;
break;
}
}
return exists;
}

Operation fireOperationDispatchedCallback(Request req, Operation op ) {
for ( DispatcherCallback cb : callbacks ) {
Operation o = cb.operationDispatched( req, op );
Expand Down
23 changes: 23 additions & 0 deletions src/wfs/src/test/java/org/geoserver/wfs/TransactionTest.java
Expand Up @@ -159,6 +159,29 @@ public void testInsert() throws Exception {
assertEquals(2, dom.getElementsByTagName("gml:featureMember")
.getLength());
}

@Test
public void testInsertWithGetFeatureInThePath() throws Exception {
// perform an insert
String insert = "<wfs:Transaction service=\"WFS\" version=\"1.0.0\" "
+ "xmlns:cgf=\"http://www.opengis.net/cite/geometry\" "
+ "xmlns:ogc=\"http://www.opengis.net/ogc\" "
+ "xmlns:wfs=\"http://www.opengis.net/wfs\" "
+ "xmlns:gml=\"http://www.opengis.net/gml\"> "
+ "<wfs:Insert > "
+ "<cgf:Lines>"
+ "<cgf:lineStringProperty>"
+ "<gml:LineString>"
+ "<gml:coordinates decimal=\".\" cs=\",\" ts=\" \">"
+ "494475.71056415,5433016.8189323 494982.70115662,5435041.95096618"
+ "</gml:coordinates>" + "</gml:LineString>"
+ "</cgf:lineStringProperty>" + "<cgf:id>t0002</cgf:id>"
+ "</cgf:Lines>" + "</wfs:Insert>" + "</wfs:Transaction>";

Document dom = postAsDOM("wfs?service=WFS&version=1.0.0&request=GetFeature&typeName=cgf:Lines", insert);
assertTrue(dom.getElementsByTagName("wfs:SUCCESS").getLength() != 0);
assertTrue(dom.getElementsByTagName("wfs:InsertResult").getLength() != 0);
}

@Test
public void testUpdate() throws Exception {
Expand Down

0 comments on commit 47c08ab

Please sign in to comment.