Project

General

Profile

can't compile Tigase HTTP API Component in the XMPP project

Keren Meir
Added over 5 years ago

Hi,

I'm using eclipse to run the XMPP tigase server, and recently i'v added the HTTP API to the server.

The API contains groovy files, which some java file has "import" to the groovy files:

for example: file HttpServer.java contatins

import tigase.http.rest.RestMessageReceiver;

RestMessageReceiver is a groovy file and therefore I can't compile the program.

I install all the groovy sdk in eclipse.

Someone can help me with that?

thank you all.


Replies (16)

Added by Keren Meir over 5 years ago

It is work now!

for some reason, i couldn't add the groovy library and DSL properly to the project. I just open a new java project, created one groovy class file, and the eclipse let me the option to add the groovy library automatically to the project. Then I import the tigase server src.

Now I have problems with the configuration. I addad:

@--comp-name-3=rest

--comp-class-3=tigase.http.rest.RestMessageReceiver

--use-local-server=true@

to init.properties, and run the project. I get:

WARNING: no HttpRegistrator instance where useLocal = true

How can I fix it?

Do I need to add another lines to init.properties?

Thanks

Added by Wojciech Kapcia TigaseTeam over 5 years ago

It's easier to compile the project using gradle and then add resulting jars as dependencies.

I assume you familiarize yourself with the Wiki for the HTTP API component? It covers all configuration options as well as required dependencies.

Could you provide output logs from server startup?

Added by Keren Meir over 5 years ago

finally, I succeed to run the server with the ATTP API!

BUT, now I'm trying to figure out how I use the scripts such as ad-hoc, user lists, etc.... the browser ask me to enter username and password, I enter one of available user and it was not ok. Do you know what do I need to enter?

Thanks again

Added by Wojciech Kapcia TigaseTeam over 5 years ago

Please try using account with admin privileges.

Added by Keren Meir over 5 years ago

Ok - it works!

I want to add my own groovy script under /rest/ folder.

I create a new folder named myExample and copy getAvatar.groovy file into it. I changed the name of the file to "example_HelloWorld.groovy" and change the name of the handler inside the file to:

class AvatarHandler extends tigase.http.rest.Handler {

@ public AvatarHandler() {

.

.

.

 }

}

@

Now, if I enter "http://localhost:8080/rest/avatar/user@domain.com" form browser I get user's avatar.

So, if I enter "http://localhost:8080/rest/myExample/user@domain.com" from browser the same things supposed to happen. but i get 404 error.

Is there another place to define the new groovy scripts? or something in init.properties??

Thank you

Added by Andrzej Wójcik IoT 1 CloudTigaseTeam over 5 years ago

You need to reload scripts registred by Tigase HTTP API Component to add/remove/update scripts.

You can do that by:

  1. running adhoc command from your XMPP client to reload scripts - command is available to execute from any xmpp admin account and is located in component adhoc commands

  2. restarting whole Tigase XMPP Server

Added by Keren Meir over 5 years ago

I restart the whole Tigase XMPP server, didn't help.

According to the first issue, I want to execute adhoc command only from browser, not from XMPP client. How do I do that?

In general, where can I find the parameters for each groovy script? for example, what are the parameters of adhoc.groovy? (http://localhost:8080/rest/adhoc/PARAM) what do I need to enter instead of PARAM?

Thanx

Added by Andrzej Wójcik IoT 1 CloudTigaseTeam over 5 years ago

In general (@yyy@) what is passed after /rest/xxx/ depends on a script and is result of processing of yyy by regular expression defined in each script. Regular expression groups are results of processing and are passed to handler methods as latest parameters - so for AdHocHandler regular expression defines two groups and two latest parameters are localPart and domain which are later used as destination address for packet containg adhoc command.

If you use GET HTTP method script will return result list of available adhoc commands for passed destination address.

To execute adhoc command you need to use POST HTTP method, pass destination address as url parameter and pass XML as content of request which will be processed into fields of adhoc command.

More informations about executing adhoc commands using HTTP API Component is available at project wiki pages -> https://projects.tigase.org/projects/tigase-http-api/wiki/ where under Scripting introduction you can find informations about writing custom HTTP API Component scripts and under Usage examples are examples of using HTTP protocol to execute HTTP API Component scripts (It includes examples of usage for adhoc script)

Added by Keren Meir over 5 years ago

Ok, now my own script work! thanks!

but again, I'm trying to execute adhoc command (read how to do that in the project wiki pages).

I'm trying POST with

+URL:+ http://localhost:8080/rest/adhoc/sess-man@mydomain.com

+Body:+

@

http://jabber.org/protocol/admin#get-active-users

<item>

  <var>user6</var>

  <value>mydomain.com</value>

</item>

<item>

  <var>max_items</var>

  <value>25</value>

</item>

@

I get "500 server error" in response and this exception in eclipse:

What am I doing wrong?

@2013-07-16 12:10:59 java_util_logging_Logger$warning.call() WARNING: got calling with params = [tigase.http.rest.RestMessageReceiver@b35bed, tigase.http.rest.RestSerlvet$_execute_closure4@1b9e8f9, admin@mydomain.com, (POST /rest/adhoc/sess-man@mydomain.com)@7227343 org.eclipse.jetty.server.Request@6e47cf, sess-man, mydomain.com]

2013-07-16 12:10:59 java_util_logging_Logger$log.call() SEVERE: exception processing request

groovy.lang.MissingPropertyException: No such property: command for class: org.eclipse.jetty.server.Request

at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:50)

at org.codehaus.groovy.runtime.callsite.GetEffectivePojoPropertySite.getProperty(GetEffectivePojoPropertySite.java:63)

at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callGetProperty(AbstractCallSite.java:227)

at tigase.rest.adhoc.AdHocHandler$_closure2.doCall(AdHoc.groovy:87)

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)

at java.lang.reflect.Method.invoke(Unknown Source)

at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:90)

at org.codehaus.groovy.runtime.metaclass.TransformMetaMethod.invoke(TransformMetaMethod.java:55)

at org.codehaus.groovy.runtime.metaclass.ClosureMetaClass$1.invoke(ClosureMetaClass.java:259)

at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:233)

at org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:272)

at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:909)

at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.call(PogoMetaClassSite.java:39)

at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:45)

at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:108)

at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116)

at tigase.http.rest.RestSerlvet.execute(RestServlet.groovy:274)

at tigase.http.rest.RestSerlvet$execute.callCurrent(Unknown Source)

at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:49)

at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:133)

at tigase.http.rest.RestSerlvet.executeAsync(RestServlet.groovy:167)

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)

at java.lang.reflect.Method.invoke(Unknown Source)

at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:90)

at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:233)

at org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:361)

at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:909)

at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.callCurrent(PogoMetaClassSite.java:66)

at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:49)

at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:133)

at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:153)

at tigase.http.rest.RestSerlvet$_processRequest_closure3.doCall(RestServlet.groovy:136)

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)

at java.lang.reflect.Method.invoke(Unknown Source)

at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:90)

at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:233)

at org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:272)

at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:909)

at groovy.lang.Closure.call(Closure.java:411)

at groovy.lang.Closure.call(Closure.java:427)

at org.codehaus.groovy.runtime.DefaultGroovyMethods.each(DefaultGroovyMethods.java:1325)

at org.codehaus.groovy.runtime.DefaultGroovyMethods.each(DefaultGroovyMethods.java:1297)

at org.codehaus.groovy.runtime.dgm$148.invoke(Unknown Source)

at org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite$PojoMetaMethodSiteNoUnwrapNoCoerce.invoke(PojoMetaMethodSite.java:271)

at org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite.call(PojoMetaMethodSite.java:53)

at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:45)

at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:108)

at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116)

at tigase.http.rest.RestSerlvet.processRequest(RestServlet.groovy:109)

at tigase.http.rest.RestSerlvet$processRequest.callCurrent(Unknown Source)

at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:49)

at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:133)

at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:145)

at tigase.http.rest.RestSerlvet.service(RestServlet.groovy:79)

at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)

at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:698)

at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:505)

at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:138)

at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:540)

at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1096)

at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:432)

at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1028)

at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:136)

at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:97)

at org.eclipse.jetty.server.Server.handle(Server.java:445)

at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:267)

at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:224)

at org.eclipse.jetty.io.AbstractConnection$ReadCallback.run(AbstractConnection.java:358)

at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:601)

at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:532)

at java.lang.Thread.run(Unknown Source)@

Added by Wojciech Kapcia TigaseTeam over 5 years ago

Did the HTTP request had Content-Type: application/xml set?

Added by Keren Meir over 5 years ago

I added the content-type and now I don't have errors, but the response I get is always the same (no matter what I enter in the node)

For example - The request and response are shown in the image.

What is wrong?

1.PNG (19.1 KB) 1.PNG Request
2.PNG (34.5 KB) 2.PNG Response

Added by Andrzej Wójcik IoT 1 CloudTigaseTeam over 5 years ago

You passed correct parameters and content to execute adhoc command and you received results of execution of adhoc command but as you can see in results inside <instructions/> tag you need to fill form passed to you by adhoc command, which means that you passed INCOMPLETE list of parameters (fields) to adhoc command. You are to passing field with identifier (@var@) user1 while adhoc script is expecting field with identifier accountjid as you can see in response from adhoc command.

Added by Keren Meir over 5 years ago

I tried it again, and now with the full list of parameters as you say:

@

sess-man@qa-dc.local

http://jabber.org/protocol/admin#get-user-roster

FORM_TYPE

hidden

http://jabber.org/protocol/admin

user1@qa-dc.local

jid-single

Getting a User's Roster

Fill out this form to get a user's roster.

@

I still get the same answer:

@

sess-man@qa-dc.local

http://jabber.org/protocol/admin#get-user-roster

FORM_TYPE

hidden

http://jabber.org/protocol/admin

accountjid

jid-single

Getting a User's Roster

Fill out this form to get a user's roster.

@

What's wrong now..?

Thanks

Added by Andrzej Wójcik IoT 1 CloudTigaseTeam over 5 years ago

The content you are passing to HTTP POST request is still wrong. I suppose the content you wanted to pass to request should be:

<command>
<jid>sess-man@qa-dc.local</jid>
<node>http://jabber.org/protocol/admin#get-user-roster</node>
<fields>
<item>
<var>FORM_TYPE</var>
<label>hidden</label>
<value>http://jabber.org/protocol/admin</value>
</item>
<item>
<var>accountjid</var>
<label>jid-single</label>
<value>user1@qa-dc.local</value>
</item>
</fields>
</command>

as I mentioned in post above accountjid is name of field to pass, not a value of field to pass!

Added by Keren Meir over 5 years ago

Silly me..... :)

didn't pay attention for that.

I tried to change password with the command node http://jabber.org/protocol/admin#change-user-password, and it succeed.

But still, I don't get user's roster with http://jabber.org/protocol/admin#get-user-roster, I just get:

@

sess-man@qa-dc.local

http://jabber.org/protocol/admin#get-user-roster

accountjid

jid-single

user1@qa-dc.local

@

Added by Andrzej Wójcik IoT 1 CloudTigaseTeam over 5 years ago

If I remember correctly you need to pass values for fields accountjid and FORM_TYPE in content for this command to work correctly.

    (1-16/16)