Error Creating an Issue using RedMine API & Java Eclipse
Added by Nelson Gomes almost 8 years ago
I am recieving this error : HTTP/1.1 422 Unprocessable Entity [Date: Tue, 14 Mar 2017 14:50:22 GMT, Server: Apache, cache-control: no-cache, x-runtime: 0.004027, x-frame-options: SAMEORIGIN, x-xss-protection: 1; mode=block, x-content-type-options: nosniff, x-request-id: d413a646-48f7-49af-9bf6-4c5b11276989, Connection: close, X-Powered-By: Phusion Passenger 5.0.6, Vary: Cookie, Status: 422 Unprocessable Entity, Content-Length: 0, Content-Type: application/xml] org.apache.http.conn.BasicManagedEntity@32cf83b8
Java Method
public void CreateAnIssue() throws GenericException {
ClientRequest req = new ClientRequest(ROOT_ADDRESS + "issues/new");
req.accept(MediaType.APPLICATION_XML);
req.queryParameter("key", apiKey);
//req.queryParameter("key", apiKey);
IssueDetail newIssue = new IssueDetail();
// Project Info
BasicInfo basicProjectInfo = new BasicInfo();
basicProjectInfo.setId(selectedProject.getId());
basicProjectInfo.setName(selectedProject.getName());
newIssue.setProject(basicProjectInfo);
// Tracker Info
BasicInfo basicTrackerInfo = new BasicInfo();
basicTrackerInfo.setId(selectedIssue.getTracker().getId());
basicTrackerInfo.setName(selectedIssue.getTracker().getName());
newIssue.setTracker(basicTrackerInfo);
// Priority Info
BasicInfo basicPriorityInfo = new BasicInfo();
basicPriorityInfo.setId(4L);
basicPriorityInfo.setName("Normal");
newIssue.setPriority(basicPriorityInfo);
// Status Info
BasicInfo basicStatusInfo = new BasicInfo();
basicStatusInfo.setId(1L);
basicStatusInfo.setName("New");
newIssue.setStatus(basicStatusInfo);
// Author Info
BasicInfo basicAuthorInfo = new BasicInfo();
basicAuthorInfo.setId(1L);
basicAuthorInfo.setName("UserName LastName Admin");
newIssue.setAuthor(basicAuthorInfo);
// Bug Subject
newIssue.setSubject(bugTitle);
// // Open Date
newIssue.setCreated_on(new Date());
try {
JAXBContext jaxbContext = JAXBContext.newInstance(IssueDetail.class);
Marshaller jaxbMarshaller = jaxbContext.createMarshaller();
StringWriter sw = new StringWriter();
jaxbMarshaller.setProperty("jaxb.fragment", Boolean.TRUE);
jaxbMarshaller.marshal(newIssue, sw);
req.body(MediaType.APPLICATION_XML, sw.toString());
logger.debugv("--- SW: {0}", sw.toString());
} catch (JAXBException e) {
throw new GenericException("Marshall object FAIL", e);
}
ClientResponse<String> res = null;
try {
res = req.put(String.class);
} catch (Exception e) {
logger.errorv(e, "Error getting issues");
throw new GenericException("error", e);
}
Please Help.
XHTML is creating with this line = jaxbMarshaller.marshal(newIssue, sw);
<issue>
<project id="148" name="DocumentoTestePrimefaces"/>
<tracker id="11" name="Infarmed - Testes Internos"/>
<status id="1" name="New"/>
<priority id="4" name="Normal"/>
<author id="1" name="UserName LastName Admin"/>
<subject>TITLE</subject>
<created_on>2017-03-14T14:56:50.827Z</created_on>
</issue>
I recieved an error using create_on or without it.