Konstantina
Thank you! This saved me after a long time wondering why PUT was not working.
Konstantina
Thank you! This saved me after a long time wondering why PUT was not working.
Will F
I had A LOT of trouble with http requests being resolved but not supported, and this is the solution I found that worked for me. If you’re getting “Request method ‘PUT’ not supported” or “Request method ‘PUSH’ not supported”, try this.
Originally, I was having issues with editing groups, with the error message “Request method ‘PUT’ not supported”. I checked the comments on this tutorial and implemented Hocine’s code, but a part of it broke PUSHing. Though, a part of Hocine’s solution should be implemented so that the code in GroupEdit.js looks like this:
…
async handleSubmit(event) {
event.preventDefault();
const {item} = this.state;
await fetch(’/api/group/’+(item.id), {
method: (item.id) ? ‘PUT’ : ‘POST’,
headers: {
‘Accept’: ‘application/json’,
‘Content-Type’: ‘application/json’
},
body: JSON.stringify(item),
});
this.props.history.push(’/groups’);
}
…
Next, in GroupController.java, make sure that each mapping has an id in its path. i.e…
@PostMapping("/group/{id}")
…
@PutMapping("/group/{id}")
…
@DeleteMapping("/group/{id}")
With these two changes, POSTing and PUTing should work fine.
Matt Raible
This typically happens when the call to get groups fails, or there is no data. Can you check your developer console and see if the network call succeeds?
Matt Raible
That’s strange. I didn’t experience these issues myself. Maybe it’s related to the browser you’re using? With Chrome, all the code in this tutorial works as expected.
Konstantina
Hi Matt,
I’m trying to adjust your example to my app. My article controller (=your group controller) communicates with a service, which communicates with a repository. I have automatic ID generation from my MySQL database. On my User object, I have some other properties - userType (enum, which is always ADMIN for article publisher), dateUserCreated (set to ‘now’ in the User class), and a set of articles published by the user (currently I have 1 user of type ADMIN who publishes everything but once I get your example to work, I’ll apply it to my Comment object which can have multiple publishers of user type VISITOR).
I can’t understand the following error with the User constructor (I use Lombok so the constructor is defined behind the scenes). Could you help? https://uploads.disquscdn.c…
Matt Raible
Hello Konstantina - it sounds like you might be missing an @AllArgsConstructor annotation on your User class. Here’s what I used in this post.
@Data
@NoArgsConstructor
@AllArgsConstructor
@Entity
public class User {
…
}
No Name
how can i deploy this to public?
vijit2222
I am not using RequestCache, csrf repository and react-cookies as I don’t need logout functionality and i have hardcoded frontend redirect url, rest all are almost same. Problem is call to /api/user always return null as OAuth2User, after login through okta as well. I am using proxy to redirect to /api/user as my react and backend is running on different domains. When running both frontend and backend on localhost they are working but on different domains and through proxy either react proxy or nginx Oauth2 user is always null because of which react stucks in ifinite redirection loop as isAuthenticated always remain false. But when I directly hit backend url /api/user user is not null. any suggestions how to pass this cross domains?
Although, calling directly <backend domain="">/api/user from frontend without proxy by allowing cors for frontend domain on server. But looking for solution with proxy and without cors settings.
Matt Raible
You probably have to configure your proxy to send/receive cookies and headers. I’m not sure as I haven’t tried this type of scenario. I’d suggest you ask this question on Stack Overflow where more people can see it.
Matt Raible
I’d recommend using Heroku or Cloud Foundry.
* Heroku: Deploying Executable JAR Files
* Cloud Foundry: Deploying a Spring Boot Application to Cloud Foundry
Stacksimus
Hi Matt,
Thank you so much for this tutorial. I have been wanting to learn React + Spring Boot and this tutorial along with several other ones you wrote have been really helpful.
I was able to get everything working fine, but there was one thing I had to do in the Okta developer console that I don’t think was mentioned in the tutorial or maybe I missed it.
After adding Okta to the app, I got an error when trying to log in “User is not assigned to the client application”. I went to Applications->JUG Tour Example->Assignments->Assign to People and added myself. After that I was able to log in and see my JUG tours. Was there a step I missed to have this done automatically or did it have to be done manually?
Thanks!
Andrés Jácome
Hey, I had the same error, because I put the “client-i”, “client-secret” inside “{}”. I removed that and it worked for me.
Andrés Jácome
Good work, I had the same error with the PUT requests, and I did anything but it doesnt work
vijit2222
this issue is resolved by setting common sub domain in session cookie, now struggling how to make this work when running two instances of same service on same domain behind load balancer, session id generated by one instance is getting rejected by other when request redirected to other instance and hence giving 403. Trying to find solution without going for redis or jdbc distributed session storage
Matt Raible
If you clone the example from GitHub and change it to use your Okta org, do you still get issues with the PUT request?
Do you get errors in your browser or when using HTTPie? If it’s in your browser, what browser are you using?
vinny parker
Hi, I’m found some issues, for exemple, what use instead of findbyname(), cos, it seems thers no such methode in springboot 2.1.7
Matt Raible
It should work. Are you following the tutorial and using Maven to build the server side, or an IDE? Note that this tutorial uses Spring Boot 2.1.0, not 2.1.7. However, I doubt the Spring team broke backwards compatibility in a minor release.
You can compare your code to the example on GitHub, which I know works.
vinny parker
yep it worked. I change some things, like using gradle instead of maven, and postgresql insted of h2. My problem was with intellij Idea, that wasnt processing annotations.
Andrés Jácome
Hey Matt, I needed to add this line --await fetch(’/api/groups/’+(item.id?item.id:’’), {— to use PUT and POST request. On handleSubmit function.
Matt Raible
That’s good to know Andrés. If it’s not too much trouble, could you create a pull request for the example app on GitHub with your suggested change. Also, please include steps to reproduce and what browser you’re using. Here’s a guide for creating a pull request from a fork.
To help motivate you, I’d be happy to send you one of Okta’s “I find your lack of security disturbing t-shirts”. 