Я пытаюсь отправить запрос в другое приложение Spring, но получаю ошибку 404.
UriComponentsBuilder builder = UriComponentsBuilder
.fromUriString(config.getUrl() +
"jobs/create_job");
log.info("Sending job to api at " + builder.toUriString());
try {
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
HttpEntity<EnrichmentJob> entity = new HttpEntity<>(job, headers);
return restTemplate.exchange(builder.toUriString(), HttpMethod.POST,
entity, Job.class);
} catch (HttpServerErrorException ex) {
log.info("Error creating job " + ex.getResponseBodyAsString());
throw new EnrichmentException(ex.getResponseBodyAsString(), ex.getStatusCode());
} catch (ResourceAccessException ex) {
log.info("Error creating job " + ex.getMessage());
throw new EnrichmentException(ex.getMessage());
} catch (HttpClientErrorException ex) {
log.info("Error creating job " + ex.getMessage());
throw new EnrichmentException(ex.getMessage(), ex.getStatusCode());
}
2019-01-30 18:46:58.002 INFO 25897 --- [nio-8082-exec-5] c.t.m.c.repository.EnrichmentRepository : Sending job to api at http://localhost:8080/v1/enrichment_jobs/create_job
2019-01-30 18:46:58.008 INFO 25897 --- [nio-8082-exec-5] c.t.m.c.repository.EnrichmentRepository : Error creating job 404 Not Found
2019-01-30 18:46:58.009 INFO 25897 --- [nio-8082-exec-5] c.t.m.c.l.ApplicationEventListener : Event ServletRequestHandledEvent: url=[/enrichment_jobs/v1/create_job]; client=[0:0:0:0:0:0:0:1]; method=[POST]; servlet=[dispatcherServlet]; session=[null]; user=[null]; time=[9ms]; status=[OK]
Выполнение запроса к этой конечной точке
@PostMapping(path = "/create_job",
consumes = MediaType.APPLICATION_JSON_VALUE,
produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<Jobs> createJob(
@RequestBody JobsRequest enrichmentJob)
throws DuplicateJobException {
Jobs job = service.convertToJobs(enrichmentJob);
try {
return new ResponseEntity<>(
service.createJob(job), HttpStatus.OK);
} catch (DuplicateJobException ex) {
return new ResponseEntity<>(job, HttpStatus.OK);
}
}
Ведение журналаURL-адрес показывает, что URL-адрес правильный, и я могу успешно использовать конечную точку с почтальоном.Есть ли дополнительные заголовки, которые мне нужно установить?
, используя почтальон для того же URL:
http://localhost:8080/v1/enrichment_jobs/create_job
с телом запроса:
{
"status": "IN_PROCESS",
"host_name": "host",
"job_type": "UPLOAD",
"job_id": "3934582d-ed3e-4dr5-86b6-ad17f9ed7543",
"asset_id": "3934582d-ed3e-4dr5-86b6-ad17f9ed7315"
}
создает и возвращает ресурс какожидается.
Класс работы:
@JsonIgnoreProperties(ignoreUnknown = true)
@JsonNaming(PropertyNamingStrategy.SnakeCaseStrategy.class)
public class JobsRequest {
private String jobId;
private String assetId;
private String status;
private String jobType;
private String hostName;
private String jobStatus;
private String createdBy;
private String lastUpdatedBy;
}