IIQ plugin rest endpoint response

Which IIQ version are you inquiring about?

8.3

Share all details about your problem, including any error messages you may have received.

I created a simple REST resource in my IIQ plugin.

package com.my.app.rest;

import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.Consumes;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;

import com.my.app.*;
import sailpoint.rest.plugin.AllowAll;
import sailpoint.rest.plugin.BasePluginResource;
import sailpoint.rest.plugin.Deferred;
import sailpoint.tools.GeneralException;

@Path("plugin")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
@AllowAll
public class RestResources extends BasePluginResource {
	@Override
	public String getPluginName() {
		return Consts.PLUGIN_NAME;
	}

    @POST
    @Path("test")
    @Deferred
    public Response testConnection() throws GeneralException {

        return Response.ok("{\"ok\":true}")
                .type(MediaType.APPLICATION_JSON)
                .build();
   }
}

When calling the endpoint, I always get 405.

If I change my endpoint to return a string instead of a Response, it works and I get 200.

package com.my.app.rest;

import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.Consumes;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;

import com.my.app.*;
import sailpoint.rest.plugin.AllowAll;
import sailpoint.rest.plugin.BasePluginResource;
import sailpoint.rest.plugin.Deferred;
import sailpoint.tools.GeneralException;

@Path("plugin")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
@AllowAll
public class RestResources extends BasePluginResource {
    @Override
    public String getPluginName() {
        return Consts.PLUGIN_NAME;
    }

    @POST
    @Path("test")
    @Deferred
    public String testConnection() throws GeneralException {

        return "ok";
    }
}

I want to be able to construct complex responses with different codes.

How can I achieve it?

Hi Liza
Try this one just to check.

return Response.status(Response.Status.OK).entity(“Hello”).build();

Add Annotation @Produces(MediaType.APPLICATION_JSON) and try this

JSONObject responseData = new JSONObject();
responseData.put(“var”, “Val1”);
responseData.put(“count”, 30);
JSONObject data = new JSONObject();
data.put(“data”, responseData);
response = Response.ok(data.toString());

	return response.build();