I try to pass an object to my backend (spring boot), but it doesn't work. I have other post method and they work. I don't understand what I am missing.
error:
XNIO-1 task-1] o.z.problem.spring.common.AdviceTraits : Method Not Allowed: Request method 'POST' not supported
Front-end (angular):
service:
create(report: IReport): Observable<HttpResponse<any>> {
return this.http.post<IReport>(this.resourceUrl, report, { observe: 'response' });
}
Model:
export class Report implements IReport {
constructor(
public companiesId?: number[],
public jobsId?: number[],
public customersId?: number[],
public usersId?: number[],
public dates?: Moment[],
public projectsId?: number[]
) {}
Backend:
controller:
@RestController
@RequestMapping("/api")
public class ReportRessource {
private final Logger log = LoggerFactory.getLogger(ReportRessource.class);
@Value("${jhipster.clientApp.name}")
private String applicationName;
private static final String NAME = "report";
private ReportService reportService;
public ReportRessource(ReportService reportService) {
this.reportService = reportService;
}
...
@PostMapping("/report}")
@PreAuthorize(
"hasAnyAuthority(\"" +
AuthoritiesConstants.ADMIN +
"\"+\"," +
AuthoritiesConstants.CUSTOMER_ADMIN +
"\"+\"," +
AuthoritiesConstants.INSPECTOR +
"\")"
)
public ResponseEntity<Boolean> createFullReport( @RequestBody ReportDTO report) throws URISyntaxException, IOException {
log.debug("REPORTDTO : {}", report);
this.reportService.makeFullReport(report);
return ResponseEntity
.noContent()
.headers(HeaderUtil.createEntityCreationAlert(applicationName, true, NAME, report.toString()))
.build();
}
ReportDTO:
import java.time.LocalDate;
import java.util.HashSet;
import java.util.Set;
public class ReportDTO {
private Set<Long> companiesId = new HashSet<>();
private Set<Long> jobsId = new HashSet<>();
private Set<Long> customersId = new HashSet<>();
private Set<Long> usersId = new HashSet<>();
private Set<LocalDate> dates = new HashSet<>();
private Set<Long> projectsId = new HashSet<>();
public ReportDTO() {
// Empty constructor needed for Jackson.
}
I don't now where should I search. Any idea? Thank you!
EDIT:
Problem => "report}" should be "report"
"/report}"
in yourPostMapping
copied from your code? Because that closing brace doesn't really belong there. – daniu Jan 19 at 10:49