I call an API function and it fails with a message, for example, this one:
{"error":
{
"message":"The specified operation could not be
completed.",
"detail":"HTTP 403 Forbidden"
}
}
The first line of the body of the function is marked by a breakpoint, but it is never reached. So, the problem happens at reading of the JSON input and turning it into the POJO. Or, maybe, even close to protocol - around getting the body of the request or request itself. Or, maybe, some step I don't know about (I am a newbie in API construction)
The logging of problems won't help, for that unreachable first line IS the logging. How can I find the problem place?
Edit: Please, notice, I am not asking for my errors in this code. (One of them is found by Marcus and mallikarjun and I know about one more) I am asking about some process that will allow me to localize the error. Yes, reading the code always can help. But often the problem is more hidden or not obvious even if the author looks at it. Then we need to know where exactly the error happens, and we want to find the place in some automate way, such as debugging by line or inserting asserts. But where and how can I do that here? How could I find this or similar problem using the running code?
The class that contains the example problem function starts so:
@Path("/api/v1/documentTypes")
@Api(value = "DocumentTypes")
public class DocumentType {
Appropriate imports are:
import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.Consumes;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
The start of the method looks so:
@POST
@Consumes(value = { MediaType.APPLICATION_JSON + ";charset=utf-8" })
@Produces(value = { MediaType.APPLICATION_JSON + ";charset=utf-8" })
@ApiOperation(value = "Create a document type",
notes = "creates a document type from Json and returns the created type",
response = Response.class)
@Session(roles = { Role.ROLE_ADMINISTRATOR })
@PublicApi
public Response create(
@ApiParam(value = "Created DocumentType", required = true)
@SwaggerDataType(type =
com.infor.daf.icp.internal.rest.models.DocumentType.class)
com.infor.daf.icp.internal.rest.models.DocumentType documentType
) {
RestHelper.logRequest(request, LOGGER); // Here is the never reached breakpoint
The testing curl call for the function:
curl -X POST
--header 'Content-Type: application/json;charset=utf-8'
--header 'Accept: application/json;charset=utf-8'
-d
'{
"uniqueIdEnabled": "true",
"versionEnabled": "true",
"name": "shortAttempt"
}'
'https://czpanpgangnus1:25000/ca/api/v1/documentTypes'
are you sure that you are posting your request in context of an role as Administrator. At
you state that only Administrators can use this function. Im not an expert at curl but it does not seem that you set your role anywhere