Hi openHABians,
I am involved in developing a Rest API of my own. Development is carried out under Eclipse smart namespace. My Resource classes (say ResourceA and ResourceB ) implements RESTResource interface and all these classes got Service Component (DS) xmls and listed same in MANIFEST.MF .
Here my issue ,
Only one class got registered as Rest service (i.e i can access only one Resource not both )
Codes as below
ResourceA
package org.eclipse.smarthome.binding.restportal.internal.Services;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import org.eclipse.smarthome.io.rest.RESTResource;
@Path("/pathA")
public class ResourceA implements RESTResource {
@GET
@Produces(MediaType.TEXT_PLAIN)
public String sayController() {
return "Hello Resource A";
}
}
And its Service - component xml as below
A.xml
<?xml version="1.0" encoding="UTF-8"?>
<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" immediate="true" name="org.eclipse.smarthome.binding.restportal">
<implementation class="org.eclipse.smarthome.binding.restportal.internal.Services.ResourceA"/>
<service>
<provide interface="org.eclipse.smarthome.binding.restportal.internal.Services.ResourceA"/>
<provide interface="org.eclipse.smarthome.io.rest.RESTResource"/>
</service>
</scr:component>
And here goes ResourceB
package org.eclipse.smarthome.binding.restportal.internal.Services;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import org.eclipse.smarthome.io.rest.RESTResource;
@Path("/pathB")
public class ResourceB implements RESTResource {
@GET
@Produces(MediaType.TEXT_PLAIN)
public String sayController() {
return "Hello Resource B";
}
}
And B’s service - component xml as below,
B.xml
<?xml version="1.0" encoding="UTF-8"?>
<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" immediate="true" name="org.eclipse.smarthome.binding.restportal">
<implementation class="org.eclipse.smarthome.binding.restportal.internal.Services.ResourceB"/>
<service>
<provide interface="org.eclipse.smarthome.binding.restportal.internal.Services.ResourceB"/>
<provide interface="org.eclipse.smarthome.io.rest.RESTResource"/>
</service>
</scr:component>
And my MANIFEST.MF picks all the service components
Service-Component: OSGI-INF/*.xml
also tried with
Service-Component: OSGI-INF/A.xml, OSGI-INF/B.xml
Don’t know why it takes only ResourceA (only http://localhost:8080/rest/pathA gives response as expected) .The ResourceB (http://localhost:8080/rest/pathB) give Not found (404) Exception .
Erros response for http://localhost:8080/rest/pathB
{
"error": {
"message": "HTTP 404 Not Found",
"http-code": 404,
"exception": {
"class": "javax.ws.rs.NotFoundException",
"message": "HTTP 404 Not Found",
"localized-message": "HTTP 404 Not Found"
}
}
}
Can any help me to solve the issue?
Advance Thanks.