Reputation: 56
that's my first question on stackoverflow ; i need to make a post request (using an inputBean/pojo class for needed paramaters) and get a response (using an outputBean/pojo class to map the json response) using the jira rest api , currently i'm using jersey to do the unmarshallowing thing with json and for annotations, here's the code :
public Resource create(CreateIssueRequest createIssueRequest) {
//creating the issue builder with project key and issuetype
IssueInputBuilder issueBuilder = new IssueInputBuilder(
createIssueRequest.getFields().getProject().getKey()
,createIssueRequest.getFields().getIssueType().getCodeName());
//setting issue fields using the inputBean
issueBuilder.setSummary(createIssueRequest.getFields().getSummary());
issueBuilder.setDescription(createIssueRequest.getFields().getDescription());
//requesting the issue creation method , BasicIssue contains the same fields as my outputbean , this whole thing is the request
BasicIssue issue = jiraClient.getClient().getIssueClient().createIssue(issueBuilder.build()).claim();
//creating the output bean
CreateIssueResponse createIssueResponse = new CreateIssueResponse(
issue.getId(),
issue.getKey(),
issue.getSelf());
try {
jiraClient.getClient().getMetadataClient().getStatus(new URI("localhost:8080/rest/api/2/issue"));
} catch (URISyntaxException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
Resource resource = new Resource();
try {
jiraClient.getClient().close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
resource.setData(createIssueResponse);
return resource;
}
what i managed to achieve using this code is creating an issue and obtaining the corresponding outputbean , what i would like instead is getting a Response instance like a jersey one , which has more information attached to it like the status of that response + the entity response (using this code the only thing i get is the entity) ; i've looked for something similar in the jira rest api but i found nothing .
i might have been unclear , if enyone is willing to help me , i'll be glad to clarify any doubts
i solved surrounding the "post request" with a try catch (when the request doesnt return 201 it throws that exception witch holds some useful data like
try{
issue = jiraClient.getClient().getIssueClient().createIssue(issueBuilder.build()).claim();
}catch(RestClientException e){
ErrorResource error = new ErrorResource();
error.setStatus(e.getStatusCode().get());
error.setDetail(e.getLocalizedMessage());
error.setTitle("An error occurred while creating the issue");
resource.setErrors(new ArrayList<ErrorResource>());
resource.getErrors().add(error);
return resource;
}
Upvotes: 1
Views: 1187
Reputation: 2947
As you can see, the official JIRA REST Client abstracts away the response and only gives you the object(s) returned from it.
If you want to keep using the client you need to create a filter or an interceptor or something that catches the response before it gets to the Client.
Upvotes: 1