[Geoserver-devel] About scripting in geoserver

Hi to all.
I did resolve (after a lot of research), my first problem:
I can get from geoserver, in a wps jython process, the layer’s catalog authorized to me.
The little program:

from geoserver.wps import process
from geoscript.geom import Geometry
from geoserver.catalog import Catalog, Workspace, Layer, Store
import org.springframework.security.core.context.SecurityContextHolder as SecurityContextHolder
import org.geoserver.catalog as catalog
from org.geoserver.platform import GeoServerExtensions

@process(
title=‘Sample’,
description=‘Sample’,
inputs={‘login’: (str, ‘login’),
‘password’: (str, ‘password’)},
outputs={‘result’: (str, ‘login status’)})

def run(login, password):
user=SecurityContextHolder.getContext().getAuthentication()
debug_file=“/tmp/geoserver.log”
f=open(debug_file, “a”)
f.write(str(user.getAuthorities().size()))
if user==None or user.getAuthorities().size()==0:
f.write(“anonymous access\n”)
else:
f.write(str(SecurityContextHolder.getContext().getAuthentication().getAuthorities()))

Devuelve: [ROLE_AUTHENTICATED, ROLE_ADMINISTRATOR, ROLE_CARTOGRAFIA_RO, ROLE_GROUP_ADMIN]

f.write(“\n”)

cat=Catalog()
try:
for workspace in cat.keys():
w=Workspace(workspace)
for datastore in w.keys():
d=Store(datastore)
for layer in d.keys():
l=Layer(layer)
cat1=GeoServerExtensions.bean(‘catalog’)
store1=cat1.getStoreByName(workspace, datastore, catalog.StoreInfo)
if store1 is None:
type=“”
else:
ft=cat1.getFeatureTypeByDataStore(store1, layer)
type=str(ft.getFeatureType().getGeometryDescriptor().getType())
type=type.split(" “)[1]
f.write(type+”|“+workspace+”:“+layer+”|“+l.title+”|“+”\n")

except Exception, e:
f.write(str(e)+“\n”)
pass

But, now, I need:
a) wath is the vartype on outputs to return a string list?. I’m writting to a local file, to do debug, but, I’m thinking to talk with a specific plugin in qgis.
b) I’d like to do better code (I’m using catalog, workspace, store and layer extensions, but, I’m thinking I can to access to the java api, like I’m using springframework api). Any idea? All information I did obtain from the source code.
c) I’d like to know my access level to each layer, to show to the user.

Can any help me?

Thanks a lot in advance

jorge infante
rosario - santa fe - argentina

···

2016-07-07 7:40 GMT-03:00 Jorge Infante <joluinfante@anonymised.com>:

I’m seeing my problem is:

  • The caller is putting user and password.
  • The wps python script is running in anonymous mode.
  • What is the method to init the session on geoserver (from wps python script) with the user and password received?

TIA

jorge infante

2016-07-05 17:40 GMT-03:00 Jorge Infante <joluinfante@anonymised.com>:

Is not working.
I did try with --user and --http-user, and, I’m receiving:

–2016-07-05 17:38:12-- http://localhost:8080/geoserver/wps?service=WPS&version=1.0.0&request=Execute&identifier=py:sample1&datainputs=param1=xx;param2=xx
Resolving localhost (localhost)… ::1, 127.0.0.1
Connecting to localhost (localhost)|::1|:8080… connected.
HTTP request sent, awaiting response… 200 OK
Length: unspecified [application/xml]
Saving to: ‘STDOUT’

  • [<=> ] 0 --.-KB/s <
    ?xml version=“1.0” encoding=“UTF-8”?><wps:ExecuteResponse xmlns:xs=“http://www.w3.org/2001/XMLSc
    hema” xmlns:wps=“http://www.opengis.net/wps/1.0.0” xmlns:ows=“http://www.opengis.net/ows/1.1” xm
    lns:xlink=“http://www.w3.org/1999/xlink” xml:lang=“en” service=“WPS” serviceInstance=“http://loc
    alhost:8080/geoserver/ows?” version=“1.0.0”><wps:Process wps:processVersion=“1.0.0”><ows:Identif
    ier>py:sample1</ows:Identifier>ows:TitleSample</ows:Title>ows:AbstractSample</ows:Abstract><
    /wps:Process><wps:Status creationTime=“2016-07-05T20:38:12.595Z”>wps:ProcessFailed<ows:Excepti
    onReport version=“1.1.0”><ows:Exception exceptionCode=“NoApplicableCode”>ows:ExceptionTextProc
    ess failed during execution
    Traceback (most recent call last):
    File "pyclasspath/geoserver/wps.py", line 19, in wrapped
    File "/instalar/geoserver/geoserver-2.8.1/bin/…/data_dir/scripts/wps/sample1.py&
    quot;, line 24, in run
    manzanas=Layer('muni:manzanas') ← I can’t to access because the access was by anonymous
    File "pyclasspath/geoserver/catalog/layer.py", line 54, in init
    Exception: Unable to find store for layer muni:manzanas
    </ows:ExceptionText></ows:Exception></ows:ExceptionReport></wps:ProcessFailed></wps:Status></wps
  • [ <=> ] 1.22K --.-KB/s in 0s

2016-07-05 17:38:12 (78.7 MB/s) - written to stdout [1251]

The wps/python script:

from geoserver.wps import process
from geoserver.catalog import Catalog, Workspace, Layer

@process(
title=‘Sample’,
description=‘Sample’,
inputs={‘login’: (str, ‘login’),
‘password’: (str, ‘password’)},
outputs={‘result’: (str, ‘login status’)})

def run(login, password):
debug_file=“/tmp/geoserver.log”
f=open(debug_file, “a”)
f.write(“login=”+login+" password=“+password+”\n")
cat=Catalog()
f.write(str(cat.keys()))
f.write(“\n”)

topp=Workspace(‘muni’)
f.write(topp.name+“\n”)
f.write(topp.uri+“\n”)
f.write(str(topp.keys()))
f.write(“\n”)
manzanas=Layer(‘muni:manzanas’)
f.write(manzanas.name+“\n”)
f.write(str(manzanas.data.schema)+“\n”)
f.write(str(manzanas.data.count())+“\n”)
f.close()
return “OK”;

2016-07-05 9:05 GMT-03:00 Ian Turton <ijturton@anonymised.com>:

You need to provide the --user & --password options to WGET or if you use curl the option is -u username:passwd

Ian

On 5 July 2016 at 12:16, Jorge Infante <joluinfante@anonymised.com> wrote:

Hi!
I’m trying to execute my wps script, using wget (to test), but, I need “login to geoserver” (like “Authenticate (will run the request as anonymous otherwise” checkbox on “WPS request builder”).
What is the method to do it?

I’m using the sentence:
wget “http://localhost:8080/geoserver/wps?service=WPS&version=1.0.0&request=Execute&identifier=py:sample1&datainputs=param1=xx;param2=yy” -O -

Thanks

jorge infante
rosario - santa fe - argentina


Attend Shape: An AT&T Tech Expo July 15-16. Meet us at AT&T Park in San
Francisco, CA to explore cutting-edge tech and listen to tech luminaries
present their vision of the future. This family event has something for
everyone, including kids. Get more information and register today.
http://sdm.link/attshape


Geoserver-devel mailing list
Geoserver-devel@anonymised.comsourceforge.net
https://lists.sourceforge.net/lists/listinfo/geoserver-devel

Ian Turton

2016-06-29 8:21 GMT-03:00 Jorge Infante <joluinfante@anonymised.com>:

Ok. I did resolve it:

from geoserver.wps import process
#from geoscript.geom import Geometry
from StringIO import StringIO

@process(
title=‘Sample’,
description=‘Sample’,
inputs={‘arg1’: (int, ‘first argument’),
‘arg2’: (int, ‘second argument’)},
outputs={‘result’: (str, ‘The buffered geometry’)}
)
def run(arg1, arg2):
#return “hello world”;
return str(arg1+arg2);

I’ll continue working on it. Thanks for the help.

2016-06-29 8:06 GMT-03:00 Jorge Infante <joluinfante@anonymised.com>:

Ok, Justin.
I’m trying to use wps to implement my service.
I did try a basic “hello world” sample. My sample try to return a string with “hello world”:

#more scripts/wps/sample.py

from geoserver.wps import process
from StringIO import StringIO

@process(
title=‘Sample’,
description=‘Sample’,
inputs={},
outputs={‘result’: (StringIO, ‘The constant hello world’)}
)
def run():
buff = StringIO(“hello world”)
return buff;

When I try to execute the process with:
wget “http://localhost:8080/geoserver/wps?service=WPS&version=1.0.0&request=Execute&identifier=py:sample” -O -

I don’t have errors, but, I can’t to see the “hello world” text.
I’m thinking the problem is the output definition. What is the list of datatypes on this?

2016-06-02 10:33 GMT-03:00 Justin Deoliveira <jdeolive@…403…>:

Hi Jorge,

The docs you are looking at are for the old “python” extension that pre-dates the “script” extension. You should follow the documentation located here:

http://docs.geoserver.org/stable/en/user/community/scripting/index.html

In particular if you are looking to hook into wps you can find some details and samples here:

http://docs.geoserver.org/stable/en/user/community/scripting/hooks.html#web-processing-service

Hope that helps.

-Justin

On Thu, Jun 2, 2016 at 5:36 AM Jorge Infante <joluinfante@anonymised.com> wrote:

Hi.
I’m using geoserver 2.8.1, builded from sources, and on runtime format.

I’m trying to run python code to do customs, in geoserver.

I did install the wps extension, create the data_dir/scripts/wps directory, and put my sample.py on it.
I’m not getting type py:sample on the demo/wps request builder.
I did detect (in the builded from sources version), a message “2016-06-01 18:14:22,784 DEBUG [script.wps] - Skipping sample.py, no hook found”

I did try, too, to install the python extension (documented on http://docs.geoserver.org/2.6.x/en/user/community/python/installation.html).
This method is no longer available in versions 2.8.x or higher? It was replaced by something else?

Surely I’m wrong in the process. someone can give me a hint?

TIA

jorge infante
rosario - santa fe - argentina


What NetFlow Analyzer can do for you? Monitors network bandwidth and traffic
patterns at an interface-level. Reveals which users, apps, and protocols are
consuming the most bandwidth. Provides multi-vendor support for NetFlow,
J-Flow, sFlow and other flows. Make informed decisions using capacity
planning reports. https://ad.doubleclick.net/ddm/clk/305295220;132659582;e_______________________________________________
Geoserver-devel mailing list
Geoserver-devel@anonymised.comsourceforge.net
https://lists.sourceforge.net/lists/listinfo/geoserver-devel