• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

AngularJs and Spring: a Rocky Marriage?

 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Craig! Having read the earlier version(s) of your Spring In Action book and having met you before at a No Fluff / Just Stuff conference, I guess I can say that I am a fan of your work.

For some time now, I have been attempting to blend the deceivingly simple Mongo application tutorial, together with the CORS tutorial on Spring.io to create a REST service which can be accessed by an angular client running on another server and under a different domain name.

Here are links to the two tutorials:

CORS tutorial: http://spring.io/guides/gs/rest-service-cors/

MongoDB with REST http://spring.io/guides/gs/accessing-mongodb-data-rest/

...and here is a link to my [lack of] progress thusfar:

http://stackoverflow.com/questions/26109094/how-to-configure-cors-with-a-spring-java-mongo-rest-application

I seem to be stuck on a CORS-related authentication issue, as I can successfully access my service using the following curl command (where user = "myUser" and password= "myPassword" ):

curl http://myUser:myPassword@servername/restServiceUri

...but I seem to wind up on the login page when I try to use the same URL from my Angular Rest service call:



In my case, I am also attempting to use JHipster (http://jhipster.github.io/) for my Angular based client application.

There appear to be a wide variety of different blogs on the subject of trying to use Angular and Spring in general, and many of the issues seem to revolve around the different CSRF tokens used by Angular (X-XSRF-TOKEN), versus Spring (X-CSRF-TOKEN): https://github.com/jhipster/generator-jhipster/issues/363

I also get the feeling that the CORS issue only scratches the surface, as in my case, I am also running into issues attempting to use Eclipse (STS in my case) for Node-centric projects such as JHipster to begin with - since, for example, Eclipse attempts [unsuccessfully] to validate the entire "node_modules" subdirectory in my Yomen built JHipster Maven project. I suppose I could simplify things a little by creating a simpler Angular client app to use in debugging this problem.

So where am I going with this reply? My goal here is to get your take on the proposed marriage of AngularJs and Spring in general and possibly also on the new Angular & Spring based JHipster initiative. I have read several books on Angular and it seems to be a relatively exciting framework, but frankly I am not having much happiness these days trying to deal with integrating the two technologies - at least not when REST and CORS is involved.

I know that you were also a proponent of Cujojs and so I am wondering whether maybe I am barking up the wrong tree in trying to use AngularJs in the first place? Assuming you are releasing a newer revision of your book, I am wondering whether your latest book revision touches on any of these topics? In either case, please feel free to pontificate on these subjects here as well. More specifically, do you know of any Cujojs client sample applications which do something similar to this? Thanks!
 
author
Posts: 422
13
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Long question, but I'll try a short answer:

Honestly, I've never run into any trouble with an Angular client consuming a Spring REST service. Admittedly, I've not written much code like that, but when I have, it has worked well. I certainly haven't encountered the CORS issue you describe, but I have no doubt that there is some concern there. In the end, Spring itself doesn't deal with CORS and you must write your own filter to deal with it. If AngularJS has it's own peculiarities in that regard, then there's no reason why you can't write the server-side piece to make Angular happy. In fact, it might be a good blog article if you do!

I have some reservations about Angular, but that's out of scope for this forum. What I can say is that I like many parts of Angular and dislike other parts. I'm also a big fan of what is done in CujoJS. I'm also a big fan of some other client-side choices (React, for example). In the end, I see no reason why Spring can't be the backend for any of them.


David McLure wrote:Hi Craig! Having read the earlier version(s) of your Spring In Action book and having met you before at a No Fluff / Just Stuff conference, I guess I can say that I am a fan of your work.

For some time now, I have been attempting to blend the deceivingly simple Mongo application tutorial, together with the CORS tutorial on Spring.io to create a REST service which can be accessed by an angular client running on another server and under a different domain name.

Here are links to the two tutorials:

CORS tutorial: http://spring.io/guides/gs/rest-service-cors/

MongoDB with REST http://spring.io/guides/gs/accessing-mongodb-data-rest/

...and here is a link to my [lack of] progress thusfar:

http://stackoverflow.com/questions/26109094/how-to-configure-cors-with-a-spring-java-mongo-rest-application

I seem to be stuck on a CORS-related authentication issue, as I can successfully access my service using the following curl command (where user = "myUser" and password= "myPassword" ):

curl http://myUser:myPassword@servername/restServiceUri

...but I seem to wind up on the login page when I try to use the same URL from my Angular Rest service call:



In my case, I am also attempting to use JHipster (http://jhipster.github.io/) for my Angular based client application.

There appear to be a wide variety of different blogs on the subject of trying to use Angular and Spring in general, and many of the issues seem to revolve around the different CSRF tokens used by Angular (X-XSRF-TOKEN), versus Spring (X-CSRF-TOKEN): https://github.com/jhipster/generator-jhipster/issues/363

I also get the feeling that the CORS issue only scratches the surface, as in my case, I am also running into issues attempting to use Eclipse (STS in my case) for Node-centric projects such as JHipster to begin with - since, for example, Eclipse attempts [unsuccessfully] to validate the entire "node_modules" subdirectory in my Yomen built JHipster Maven project. I suppose I could simplify things a little by creating a simpler Angular client app to use in debugging this problem.

So where am I going with this reply? My goal here is to get your take on the proposed marriage of AngularJs and Spring in general and possibly also on the new Angular & Spring based JHipster initiative. I have read several books on Angular and it seems to be a relatively exciting framework, but frankly I am not having much happiness these days trying to deal with integrating the two technologies - at least not when REST and CORS is involved.

I know that you were also a proponent of Cujojs and so I am wondering whether maybe I am barking up the wrong tree in trying to use AngularJs in the first place? Assuming you are releasing a newer revision of your book, I am wondering whether your latest book revision touches on any of these topics? In either case, please feel free to pontificate on these subjects here as well. More specifically, do you know of any Cujojs client sample applications which do something similar to this? Thanks!

 
Bartender
Posts: 1682
7
Android Mac OS X IntelliJ IDE Spring Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Gunnar and David both recently blogged about security related things with Angular and Spring. Gunnar I know likes angular a lot, and I have not had any specific issues with it either. The Jhipster stuff is a little to busy for my liking. Here are some distilled angular security examples

https://github.com/ghillert/botanic-ng
https://github.com/SpringOne2GX-2014/microservice-security
 
It's just a flesh wound! Or a tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic