Hi, list.

I recently installed the Python plugin and got a simple test going, and also 
built a Java-style REST endpoint just to compare.

The Java endpoint and the Python endpoint both work fine via GET, but I've 
found that I'm unable to POST requests to either of the URLs. Instead, I get 
back HTTP/1.1 405 Method Not Allowed. Based off of the logs, it looks like 
Geoserver doesn't even receive the request since Tomcat just sends back the 405 
right away.

Here's how I'm set up in Python (after having successfully swapped out 
jython-2.5.2.jar for jython-2.7.0.jar):

# /var/lib/tomcat/webapps/geoserver/data/scripts/apps/Analysis/main.py
# Adapted from exercise in Colin Henderson's "Mastering Geoserver"

from flask import Flask, Response

app = Flask('Analysis')
if __name__ == "__main__":
    app.run()

# Works perfectly fine:
@app.route("/<type>/within/<x>/<y>/<radius>")
def CategoryRadius(type):
    return Response('{"You searched for type":' + '"' + type + 
'"}',mimetype='application/json')

# Doesn't work:
@app.route("/within",methods=["POST"])
def CategoryRadiusPost():
    type = request.form['type']
    return Response('{"You searched for type":' + '"' + type + 
'"}',mimetype='application/json')

And in Java:

package org.geoserver.rest.hello;

import java.util.List;
import org.geoserver.rest.AbstractResource;
import org.geoserver.rest.format.DataFormat;
import org.restlet.data.Request;
import org.restlet.data.Response;

import java.util.ArrayList;
import org.geoserver.rest.format.StringFormat;
import org.restlet.data.MediaType;

public class HelloResource extends AbstractResource {

       @Override
       protected List<DataFormat> createSupportedFormats(Request request, 
Response response) {

          List<DataFormat> formats = new ArrayList();
          formats.add(new StringFormat( MediaType.TEXT_PLAIN ));

          return formats;
       }


       @Override
       public void handleGet() {
          //get the appropriate format
          DataFormat format = getFormatGet();

          //transform the string "Hello World" to the appropriate response
          getResponse().setEntity(format.toRepresentation("Hello World"));
       }

       @Override
       public void handlePost() {
              getResponse().setEntity("Hello World", MediaType.TEXT_PLAIN);
       }

} // HelloResource class OUT

With applicationContext.xml looking like:

<?xml version="1.0"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" 
"http://www.springframework.org/dtd/spring-beans.dtd";>
<beans>
       <bean id="hello" class="org.geoserver.rest.hello.HelloResource"/>
       <bean id="helloMapping" class="org.geoserver.rest.RESTMapping">
              <property name="routes">
                     <map>
                           <entry>
                                  <key>
                                         <value>/hello.{format}</value>
                                  </key>
                                  <value>hello</value>
                           </entry>
                     </map>
              </property>
       </bean>
</beans>

>From shell, I'm trying to retrieve the pages like so:

curl http://localhost:8080/geoserver/script/apps/Analysis/within -u 
'admin:<password>' -d "type=mammals" -d "x=1" -d "y=2" -d "radius=3" -i
curl http://localhost:8080/geoserver/rest/hello.txt -u 'admin:<password>' -d 
"greeting=howdy" -i
# Note: the -d flag causes POST to be used. Including -X POST does not change 
the outcome shown below.

But both pages give me back the response:

HTTP/1.1 405 Method Not Allowed
Allow: GET
Date: Wed, 21 Sep 2016 00:37:51 GMT
Server: Noelios-Restlet-Engine/1.0..8
Transfer-Encoding: chunked

I looked at the gs-rest and gs-restconfig sources a little bit but from what I 
can tell this is a higher-level Tomcat configuration issue. Where do I make the 
adjustment to allow fetching pages after POST-ing at them? I already tried 
specifying 
<init-param><param-name>cors.allowed.methods</param-name><param-value>GET,POST</param-value></init-param>
 in Tomcat's web.xml under the CORS filter, but it's clearly being overridden 
by something that's buried down deeper.

Thanks

- Patrick O'Toole

Application Developer
Wyoming Natural Diversity Database<uwyo.edu/wyndd>
UW Berry Biodiversity Conservation Center
Department 3381, 1000 E. University Av.
Laramie, WY 82071
P: 307-766-3018
------------------------------------------------------------------------------
_______________________________________________
Geoserver-users mailing list
Geoserver-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/geoserver-users

Reply via email to