You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello! I just completed your tutorial and I am so grateful for your contribution! It helped me greatly in my Spring studies.
I am not sure if you still actively manage this repository/tutorial, but I wanted to call out that the use of Problem.create() did not work for me in my code. I am not sure if I was implementing something incorrectly, but Intellij could not find a create() method on a Problem class, and I couldn't find it on the Problem class on the Spring documentation
Maybe I am missing something, but what ended up working for me was:
@DeleteMapping("/orders/{id}/cancel")
ResponseEntity<?> cancel(@PathVariable Long id) {
Order order = orderRepository
.findById(id)
.orElseThrow(() -> new OrderNotFoundException(id));
if(order.getStatus() == Status.IN_PROGRESS) {
order.setStatus(Status.CANCELLED);
return ResponseEntity.ok(assembler.toModel(orderRepository.save(order)));
}
return ResponseEntity
.status(HttpStatus.METHOD_NOT_ALLOWED)
.header(HttpHeaders.CONTENT_TYPE, MediaTypes.HTTP_PROBLEM_DETAILS_JSON_VALUE)
.body("You can't cancel an order that is in the " + order.getStatus() + " status");
}
Obviously I am just learning, I am not sure if this would be a preferred method in a real-world example. I'd love feedback (from anyone) if someone takes a look.
Again, thank you so much! <3
The text was updated successfully, but these errors were encountered:
Hi @sidneyrens, I had the same problem using Eclipse STS, then I googled the error and found a solution:
java.lang.IllegalArgumentException: Invalid character found in method name [0x160x030x010x000xf70x010x000x000xf30x030x03H0x160xe30xc9Z0x1cr0xc00xc60x7f0x05Y0x08[0x150xa70xaf0xa70xdc0x1b0xf9'0xa5q0x8d;0xe10xd20x180xca0x840xe8 ]. HTTP method names must be tokens
It has to do with using https / http ->
Employee API makes the following call:
$ curl -v localhost:8080/employees
or
$ curl -v https://localhost:8080/employees
Orders API makes the following call:
$ curl -v http://localhost:8080/orders
Essentially, swapping "http" with "https" will fix the problem.
Hi @sidneyrens. Thank you for the issue. I think I see the problem.
The Problem class you linked to comes from the Spring Framework project. You are correct that this class does not have a create() method, so that code would cause an error.
The correct Problem class should be the one that comes from the Spring HATEOAS project. This one does have an implementation of create().
While the code has the correct implementation in the form of the import: import org.springframework.hateoas.mediatype.problem.Problem;
The text in the README doesn't call out the imports explicitly, leaving it to the user and their IDE to infer.
I will close the issue for now as I don't think it is a bug. If others have the same issue we can revisit the README and add the import explicitly like we've done in other situations.
Hello! I just completed your tutorial and I am so grateful for your contribution! It helped me greatly in my Spring studies.
I am not sure if you still actively manage this repository/tutorial, but I wanted to call out that the use of
Problem.create()
did not work for me in my code. I am not sure if I was implementing something incorrectly, but Intellij could not find a create() method on a Problem class, and I couldn't find it on the Problem class on the Spring documentationMaybe I am missing something, but what ended up working for me was:
Obviously I am just learning, I am not sure if this would be a preferred method in a real-world example. I'd love feedback (from anyone) if someone takes a look.
Again, thank you so much! <3
The text was updated successfully, but these errors were encountered: