404 error for REST API app

1,554 views
Skip to first unread message

Zhe Zhang

unread,
Jul 19, 2016, 9:26:16 AM7/19/16
to onos...@onosproject.org
Hi All,

I have created an ONOS REST API app and the repo is at: https://github.com/zhangzhehust/onos_gridftp_application

After I installed the app and activated it, I cannot make my implemented REST API work. It always return the 404 error: {"code"404,"message":"null for uri":http://10.0.3.11:8181/onos/v1/gridftp}

I am using the VM from ONOS website for testing purpose.

Is there something obviously wrong with my configuration or code? I will be really appreciated if anyone can take a look and give some advice here.

Thanks,
-Zhe

Chiara Contoli

unread,
Jul 19, 2016, 10:00:05 AM7/19/16
to Zhe Zhang, ONOS Developers
Hi Zhe,
I had a glance at the web.xml  and the pomxml file,  seem ok to me. Since you are using onos 1.6 version, Swagger should have automatically auto-generated REST API doc, that should be reached at http://10.0.3.11:8181/onos/v1/docs. What do you see if you try to access http://10.0.3.11:8181/onos/v1/docs/ ? Theoretically, you should be able to see ONOS core REST API, and from the upper menu  you should be able to select your REST API (the URL should switch to something like http://10.0.3.11:8181/onos/v1/docs/#/gridftp when you click on the Show/Hide link).

Best,

Chiara
Il giorno 19/lug/2016, alle ore 15:26, Zhe Zhang <zhangz...@gmail.com> ha scritto:

Hi All,

I have created an ONOS REST API app and the repo is at: https://github.com/zhangzhehust/onos_gridftp_application

After I installed the app and activated the app, I cannot make my implemented REST API work. It always return the 404 error: {"code"404,"message":"null for uri":http://10.0.3.11:8181/onos/v1/gridftp}

I am using the VM for ONOS website for testing purpose.


Is there something obviously wrong with my configuration or code? I will be really appreciated if anyone can take a look and give some advice here.

Thanks,
-Zhe

--
You received this message because you are subscribed to the Google Groups "ONOS Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to onos-dev+u...@onosproject.org.
To post to this group, send email to onos...@onosproject.org.
Visit this group at https://groups.google.com/a/onosproject.org/group/onos-dev/.
To view this discussion on the web visit https://groups.google.com/a/onosproject.org/d/msgid/onos-dev/465a02ab-8402-4b81-9ed7-63602c4c0228%40onosproject.org.

Zhe Zhang

unread,
Jul 19, 2016, 11:57:01 AM7/19/16
to ONOS Developers, zhangz...@gmail.com
Hi Chiara,

Thanks for the reply.

I did see my own RESTful API doc on the link you indicated. However, it still could not work properly. I further found out that it seems like the framework does not like empty Path annotation. For example, one of the simple test RESTful API is to return "hello world" message. The path annotation for that API call is "" and after I add a specific path annotation other than the empty string, the API can return the message.

My other APIs still have the same 404 error though. I will continue playing with the code and tweak the path annotation to see whether I can make it work.

But in general, is there any typical common traps that can be encountered for some new ONOS app developers in terms of creating a RESTful API app?

Thanks,
-Zhe

Chiara Contoli

unread,
Jul 19, 2016, 12:48:13 PM7/19/16
to Zhe Zhang, ONOS Developers
You should remove the @Path(“”) annotation from getGreeting(), in this way, you should be able to see something like

GET /gridftp

in the doc, and if you click the GET button you should get the hello message.

If you are able to see your whole REST API, i.e,

GET /gridftp
GET /gridftp/{ipAddr}/{port}
POST /gridftp
DELETE /gridftp/{ipAddr}/{port}
DELETE /gridftp

but you still get 404 error, you should not only check if you are sending the request to the proper URI (especially if you use curl command), but you should also check if the actions implemented inside each REST API endpoint are working properly. I’m saying this because 404 does not necessarily mean that you’re sending a bad request, it indicates that the requested resource is not found. You can also check onos log to see if your getting any kind of error, or add some logging messages to your web app to discover what’s going wrong.

Best,

Chiara
> To view this discussion on the web visit https://groups.google.com/a/onosproject.org/d/msgid/onos-dev/926fd57f-d548-4c2a-a968-7adea5a3e905%40onosproject.org.

Mahesh Poojary

unread,
Jul 20, 2016, 12:01:36 AM7/20/16
to Chiara Contoli, Zhe Zhang, ONOS Developers, Suchitra h n
Hi Zhe,

You can check karaf.log what is going on and why that error message is returning. Also you can debug and check which flow is making this to happen by IntelliJ.

-Mahesh
To view this discussion on the web visit https://groups.google.com/a/onosproject.org/d/msgid/onos-dev/1ECF52F4-C939-4613-9D20-14FF895DB52E%40gmail.com.

Zhe Zhang

unread,
Jul 20, 2016, 10:18:34 AM7/20/16
to ONOS Developers, chiara....@gmail.com, zhangz...@gmail.com, suchi...@huawei.com, Mahesh....@huawei.com
Thanks for Chiara and Mahesh's help here. I have been able to fix my problem and make my RESTful API work. I have to change the path prefix in pom.xml to be /onos/v1/gridftp (where "gridftp" is my app's artifact ID) and then also set a root path in the GridftpWebResource.java file. Previously I have the prefix as /onos/v1 in pom.xml and set the root path in the GridftpWebResource.java to be "gridftp", which cannot find the URI and always gave me the 404 error.

-Zhe
Reply all
Reply to author
Forward
0 new messages