0

Good day all,

I am having problems adding Rest Services to mdm-admin

I had some troubles with mdm-android-* I created the service and reference in the permission.xml file

Creating a rest service in mdm-admin it has sefinitin as below

@GET
@Path("{type}/{id}/logs")
public List<? extends Application> getDeviceLogs(

    @PathParam("type") String type,
    @PathParam("id") String id)
        throws MDMAPIException {

        List<Application> applications;
        ApplicationManagementProviderService appManagerConnector;
        DeviceIdentifier deviceIdentifier = new DeviceIdentifier();

        try {

            deviceIdentifier.setType(type);
            deviceIdentifier.setId(id);
            appManagerConnector = MDMAPIUtils.getAppManagementService();

            applications = appManagerConnector.getApplicationListForDevice(deviceIdentifier);

        } catch (ApplicationManagementException e) {

            String msg = "Error occurred while fetching the apps of the device.";
            log.error(msg, e);
            throw new MDMAPIException(msg, e);
        }
        return applications;
    }
}

It is a clone of the get list of application method with just the path and function name changed.

When I deploy it. my webapp returns a 404 error status Code. when I try to call the function

To replicate this, Download v2.0.1 Open with Netbeans, Modify WSO2 MDM - Mobile Device Management Admin Services Copy and paste one of the rest functions, rename the function Deploy and call that new function

How can I resolve this?

Community
  • 1
  • 1

2 Answers2

0

You are getting the 404 since you have to included the nely aded rest api permission to the user.

Please include the related permission to the one of the user's role and try that again.

Reffer to the documentation for more info.

Kamidu Punchihewa
  • 1,241
  • 10
  • 18
0

Your code snippet is working for me without any issue. You need to add permission entry in permission.xml as follows to make this work

<Permission>
    <name>log device</name>
    <path>/device-mgt/emm-admin/devices/logs</path>
    <url>/operations/*/*/logs</url>
    <method>GET</method>
</Permission>

The curl command I used is as below. don't forget to add a content type as application/json.

curl -X GET -H "Content-Type: application/json" -H "Authorization: Bearer 3c28103c1992c9e57d7091fb9f38732e" -k -v https://localhost:9443/mdm-admin/operations/android/000000000000000/logs
lakshman
  • 2,641
  • 6
  • 37
  • 63
  • Lakshman I modified the function to look like this `@GET @Path("{type}/{id}/logs") public String getLogs(@PathParam("id") String id) throws MDMAPIException{ return "[{\"id\":11,\"log\":\"No logs\"}]"; }` on running I get this in my console Uncaught SyntaxError: Unexpected end of JSON input – user2955481 Jun 15 '16 at 13:52
  • what is the complete error on log and response you got? – lakshman Jun 16 '16 at 06:13