Junos Space Developer
Junos Space Developer

Exception trying to execute an asynchronous RPC call

[ Edited ]
‎07-17-2013 01:52 AM
I have a Junos Space 13.1R1 instance running correctly. But I'm getting some problems interacting with REST API. I'm trying to execute a RPC requests on a discovered MX480 Router following these instructions. As explained in the documentation, I need to create a queue because the call needs to be asynchronous. I found this documentation about managing asynchronous calls, and I followed it.
 
All the calls have a valid Basic HTTP Authentication header using valid credentials. I'm using a REST client 
 
I created a queue with:
 
1st Request

POST https://10.10.0.107/api/hornet-q/queues

Content-Type: application/hornetq.jms.queue+xml

<queue name="test-queue">
   <durable>false</durable>
</queue>


And I got the correct response:

 
1st Response

201 Created


Content-Type: text/plain; charset=UTF-8
Location: http://space-00163e418ba6:8080/api/hornet-q/queues/jms.queue.test-queue

In this case, the queue location seems to point to an strange host name and port (http://space-00163e418ba6:8080) while the host has no name and I'm using HTTPS port (443).
 
 
Anyway, I can request information about this queue with:
 
2nd Request
 
And I get:
 
2nd Response
200 OK

Content-Type: application/xml

<queue>
    <name>jms.queue.test-queue</name>
</queue>
 
But when I tried to use this queue I was having problems. I have my MX480 router discovered and https://10.10.0.107/api/space/device-management/devices/131086 is a valid URL that provides router information and REST endpoints. I tried this request:
 
3rd Request
Content-Type: application/vnd.net.juniper.space.device-management.rpc+xml;version=3;charset=UTF-8
 
<netconf> 
  <rpcCommands>
    <rpcCommand>
      <![CDATA[<get-system-information/>]]>
    </rpcCommand>
  </rpcCommands>
</netconf>
 
3rd Response
500 Internal Server Error
Content-Type: text/html;charset=utf-8
 
And a weird Java stack trace in the body:
 
<html><head><title>JBossWeb/2.0.1.GA - Error report</title><style><!--H1 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:22px;} H2 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:16px;} H3 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:14px;} BODY {font-family:Tahoma,Arial,sans-serif;color:black;background-color:white;} B {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;} P {font-family:Tahoma,Arial,sans-serif;background:white;color:black;font-size:12px;}A {color : black;}A.name {color : black;}HR {color : #525D76;}--></style> </head><body><h1>HTTP Status 500 - </h1><HR size="1" noshade="noshade"><p><b>type</b> Exception report</p><p><b>message</b> <u></u></p><p><b>description</b> <u>The server encountered an internal error () that prevented it from fulfilling this request.</u></p><p><b>exception</b> <pre>org.jboss.resteasy.spi.UnhandledException: java.lang.NullPointerException
	org.jboss.resteasy.core.SynchronousDispatcher.handleApplicationException(SynchronousDispatcher.java:351)
	org.jboss.resteasy.core.SynchronousDispatcher.handleException(SynchronousDispatcher.java:220)
	org.jboss.resteasy.core.SynchronousDispatcher.handleInvokerException(SynchronousDispatcher.java:196)
	org.jboss.resteasy.core.SynchronousDispatcher.getResponse(SynchronousDispatcher.java:551)
	org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:513)
	org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:125)
	org.jboss.resteasy.plugins.server.servlet.ServletContainerDispatcher.service(ServletContainerDispatcher.java:208)
	org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:55)
	org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:50)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
	org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
</pre></p><p><b>root cause</b> <pre>java.lang.NullPointerException
	net.juniper.jmp.cems.devicemanager.service.v3.JSDeviceManagerSvcImpl.performOperationsScheduled_v3(JSDeviceManagerSvcImpl.java:75)
	sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
	sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	java.lang.reflect.Method.invoke(Method.java:616)
	org.jboss.resteasy.core.MethodInjectorImpl.invoke(MethodInjectorImpl.java:167)
	org.jboss.resteasy.core.ResourceMethod.invokeOnTarget(ResourceMethod.java:257)
	org.jboss.resteasy.core.ResourceMethod.invoke(ResourceMethod.java:222)
	org.jboss.resteasy.core.ResourceMethod.invoke(ResourceMethod.java:211)
	org.jboss.resteasy.core.SynchronousDispatcher.getResponse(SynchronousDispatcher.java:536)
	org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:513)
	org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:125)
	org.jboss.resteasy.plugins.server.servlet.ServletContainerDispatcher.service(ServletContainerDispatcher.java:208)
	org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:55)
	org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:50)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
	org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
</pre></p><p><b>note</b> <u>The full stack trace of the root cause is available in the JBossWeb/2.0.1.GA logs.</u></p><HR size="1" noshade="noshade"><h3>JBossWeb/2.0.1.GA</h3></body></html>
I looked at JBoss log, but I saw the same Java stack trace with a java.lang.NullPointerException.
 
I tried other requests using the queue, but I got always the same error response. I tried the same procedure using HTTP port 8080 and the result was exactly the same.
 
Am I doing anything wrong? My final goal is discovering device OP scripts and to execute them.
6 REPLIES 6
Junos Space Developer

Re: Exception trying to execute an asynchronous RPC call

‎07-17-2013 04:33 PM
Hi,

Can you try restarting jboss and try again?
Also, for exec-rpc, you can use version 1 of the API which is synchronous.

For OP scripts the best option is to use the Script management APIs.

Regards
Yesh
Junos Space Developer

Re: Exception trying to execute an asynchronous RPC call

[ Edited ]
‎07-18-2013 04:53 AM

Thank you for the response.

 

I'm reading the documentaion about Script management APIs, but I have some doubts.

 

1) Can I discover all the OP Scripts of a Junos Space registered device using REST API?

 

I know how to do it using Junos CLI, but I have not found the way to do it with Junos Space REST API. I have tried:

 

GET /api/space/device-management/devices/{device_id}/view-associated-scripts

 

but it returns: 404 Not Found, Device not associated to any scripts. And the router has some OP Scripts installed.

 

2) Can I execute a discovered OP Script using REST API?

 

I know how to do it using Junos CLI

 

3) Can I discover parameters of each discovered script using REST API?

Junos Space Developer

Re: Exception trying to execute an asynchronous RPC call

‎07-19-2013 01:32 AM

Hi,

 

Please take a look under script-management, not device management

https://developer.juniper.net/shared/jdn/html/browserhelp/com.juniper.junos_space.sdk.help/ScriptMan...

/api/space/script-management/scripts 

 

 

1) Can I discover all the OP Scripts of a Junos Space registered device using REST API?

 

Yes you can. You said that there are some op scripts on the device. Are those scripts enabled? It is not enough to deploy them

/api/space/script-management/scripts/exec-deploy

 

they have to be enabled

/api/space/script-management/scripts/exec-enable

 

2) Can I execute a discovered OP Script using REST API?

 

Regarding your 3rd question:

 Can I discover parameters of each discovered script using REST API?

 

You have to discover script, retrieve script and script HAS TO have header which describes the parameter it takes. Then from the header you can discover what parameters are required.

Another option is to have a script that returns error if not all parameters are invoked and lists the usage.

Junos Space Developer

Re: Exception trying to execute an asynchronous RPC call

[ Edited ]
‎07-19-2013 03:36 AM

Hi, thank you for the response.

 

I have a aproblem. I told you that I have some scripts on the device. But I only see it in Junos CLI connecting by SSH to the router. Doing:

 

edit
show system scripts op

 I see the scripts in the router.

 

But when in Junos Space REST API I send:

 

GET http://10.10.0.106:8080/api/space/script-management/scripts/

 

The response is:

 

204 No content

 

I know that I need to deploy the scripts using the Script Managment API, but I need an Script URL parameter in hte XML or JSON body of the request (like <script href="/api/space/script-management/scripts/294912" /> as explained in the documentation. I don't know how to discover or publish these script URLs.

 

EDIT:

 

I know I can import scripts as explained here, but I want to add existing device scripts. Should I discover these scripts from each device configuration and then publish them?

Junos Space Developer
Solution
Accepted by topic author logoff
‎08-26-2015 01:27 AM

Re: Exception trying to execute an asynchronous RPC call

‎07-19-2013 05:20 AM

I think there are 2 issues here. First, the query parameter should be queue and not queue-url.

Secondly, there is a known issue with providing hornet-q URLs as https on async API calls. So, can you please try the API with the queue URL as http://localhost:8080/api/hornet-q/queues/jms.queue.test-queue?

 
 
 
Hope this helps.
Highlighted
Junos Space Developer

Re: Exception trying to execute an asynchronous RPC call

[ Edited ]
‎07-19-2013 05:37 AM

Great!

 

I executed:

 

POST http://10.10.0.106:8080/api/space/device-management/devices/131086/exec-rpc?queue=http://10.10.0.106...

<netconf> 
  <rpcCommands>
    <rpcCommand>
      <![CDATA[<get-system-information/>]]>
    </rpcCommand>
  </rpcCommands>
</netconf>

 

and I got:

 

202 Accepted

Content-Type: application/vnd.net.juniper.space.device-management.rpc+xml;version=3;charset=UTF-8

<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<task href="/api/space/job-management/jobs/458754">
    <id>458754</id>
</task>

 

Then, documentation should indicate that the param is queue and not queue-url. Moreover, IMHO I think Junos Space REST API should not launch a 500 Server Error when the query param queue is not present, it should warn about the absence of it.

 

EDIT:

 

I tested the same operation with HTTPS URLs and it worked.

 

POST https://10.10.0.107/api/space/device-management/devices/131086/exec-rpc?queue=https://10.10.0.107/ap...

<netconf> 
  <rpcCommands>
    <rpcCommand>
      <![CDATA[<get-system-information/>]]>
    </rpcCommand>
  </rpcCommands>
</netconf>

It produced the same result with a new job.