Spring Integration JMX support not work - jmx

As far as I know Spring Integration has out of the box JMX support. What documentation says is that I can obtain numerous statistics regarding channels, routers, etc.
I have the following configuration added to Spring context file:
<context:mbean-server />
<context:mbean-export/>
However, only one element has been auto detected for JMX exposure. It is a simple delayer.
I have multiple flows defined and no more elements are exposed through JMX.
I have no clue what is wrong.
Are there any other configuration changes I need to make?
Thank you for any help.

You need to use <int-jmx:mbean-export> instead.
Sorry for the short answer, but there is no more to say, if already have taken a look into Docs.
However here is a sample on the matter.
UPDATE
H-m. No, wrong sample. See Spring Integration tests.
UPDATE2
<context:mbean-export/> registers MBeans for those Spring Beans which are #ManagedResource. The <int-jmx:mbean-export> goes a bit further and wraps to MBeans almost all Spring Integration components: channels, MessageHandlers, MessageSources.
And yes, adds for them #ManagedMetrics.

Related

Adding security (SSL) to a Spring web service

I've followed this guide: https://spring.io/guides/gs/rest-service/ to create a web service using Spring Rest. But now I need to add a SSL to the communication, I've tried following this other guide: http://www.radcortez.com/ssl-tls-rest-server-client-with-spring-and-tomee/ but a lot of code is in the web.xml file, wich the first guide said isn't used. I imagine now it's supposed to be in some kind of annotation. I would really appreciate some help with this!

Apache Shiro versus Spring Security

We have an existing Jetty Application using Shiro that we are moving to Spring Boot, and were wondering which is more straightforward to integrate with our Spring Application, Apache Shiro or Spring Security? We're looking into implementing OAuth2 soon, and we were recommended Spring Security since we were moving this to Spring Boot. Does anyone have any input they could give us?
As you already have Apache Shiro as your security framework. It would be wise to let it be as is. Shiro easily integrates with spring and works with OAuth2 (https://github.com/zhangkaitao/shiro-example/blob/master/shiro-example-chapter17-client/src/main/java/com/github/zhangkaitao/shiro/chapter18/oauth2/OAuth2Realm.java). In case you swith to spring security you will have to reconsider everything again and a large changeset.
If you have a rather small application with not too many users and roles and don’t need to use any overly advanced features, feel free to use Java EE Security. It provides a solid base just for that. Java EE Security possibilities are quickly exhausted though. For example, you can specify only one authentication mechanism for the whole application. Also, if the application needs to be portable, one should definitely use one of the other two frameworks.
Now if there is need for a largely independent, lightweight and extensible security solution, Apache Shiro is the way to go. The downside, however, is that it might take some time to overcome problems. One might also have to implement some features by themselves. Shiro’s design (interface-driven and POJO-based) facilitates this, however.
At last, if the application is already Spring-based, one might as well stay on the train and use Spring Security, there aren’t any real downsides in this case (beside Spring Security being somewhat harder to implement). This is different for spring-less applications, even more if one never has worked with Spring before. Implementation of advanced features is even harder at first and annotations cannot be used unless Spring itself or AspectJ are included. Also, if there is need for Spring OAuth2, one must use spring-mvc, instead of Jersey or RESTeasy, to create REST resources.
With this, our comparison comes to an end. Again, a small reminder about the relativity of our observation. Experiment with the frameworks by yourself and use the one that suits your needs best.

Use neo4j server instead of embedded mode

I'm working on a webapp running on Tomcat which using spring-data to connect to a neo4j graph in embedded mode.
I would like to use neo4j server instead of the embedded mode and I am looking for some help to be sure about how to do that.
Some of my application services are quite difficult and combine, in a single transaction, the result of several cypher requests in a dto sent back to the user.
First I thought that I have to create a server unmanaged extension and I think I should follow these following steps.
- Keep my webapp with springMVC and spring security to hold and secure users sessions.
- Regroup all my transactional services in a specific jar my-app.jar
- Use Jax-RS to add a REST access point on each of my service of my-app.jar
- use something like spring restTemplate from my spring controller to call services from my-app.jar
First question : is this way of doing things is the good way ?
Second question : I have many spring injection in my services layer. How can I keep them working (how can I add dependencies in the server extension ?
Then I discovered graphAware and I wonder if I should use it instead.
And finally I just read this post http://jexp.de/blog/2014/12/spring-data-neo4j-improving-remoting-performance/ and it seems that I should use
the SpringCypherRestGraphDatabase (as explain in the bold text at the end of the article).
Well, I'm a little bit lost and I would appreciate any help to use neo4j server instead the embedded mode for my application which contain some complexe transactions.
You have a number of options here and you are on the right track with your thinking.
Option 1:
If your use cases are business-logic-heavy, and your question suggests that they are, going the unmanaged extension route is one option.
Essentially, you can then combine the most performant Java API and Cypher (if you wish) to perform your use case. I wouldn't use SDN here by the way, so you have to do your mapping manually, but is there really any mapping? Maybe you just want to execute traversals / Cypher queries for each one of your use cases.
Each use case then exposes a simple REST API, which is consumed by your Spring-powered application running Spring MVC, Spring Security, and all that. You can use the RestTemplate from Spring in your app's Controllers.
To add a twist to all that, you can use the GraphAware Framework to develop the "unmanaged extension" using Spring MVC as well. That would be my preferred option, knowing nothing about your domain/app.
Option 2:
Use the new version of SDN (v4) as Michael suggests. This allows you to run your application with annotated domain objects, Spring MVC, Security, et al. Operations (CRUD and other) are automatically translated to Cypher and sent across the wire to Neo4j running in server mode (no extensions needed). Results are then marshalled back to Java objects.
We're about to release Milestone 1 of SDN v4. It shouldn't take more than a week. That said, it is still going to be a Milestone release, thus not ready for production. A GA release is expected in May (ish).
You can already try SDN v4 yourself. Clone this repo: https://github.com/spring-projects/spring-data-neo4j, make sure you're on the 4.0 branch, and do an mvn clean install on it. Here's a sample app, built using Angular JS and Spring Boot.
Please do get in touch with feedback / questions / problems (best by email info at graphaware dot com). Cheers!
I suggest you wait a bit until SDN4 Milestone 1 comes out (developed by GraphAware) this was written from scratch for Neo4j-Server.

Using spring security

I am using spring security in my application for authenticating. I want to fail all logins which happened within a specific time period since session start(e.g 150ms). I can write code to achieve this. I wanted to know if spring security has this functionality built in where I can specify a timeperiod and all login request within that specified time fails.
Thanks,
I think there is no such built-in mechanism in spring for this usecase. Your requirement seems not really a common requirement and therefore could not be expected to find something like this in a general programming framework.

Spring Data Neo4j in combination with Spring-Social and Spring-Security

I am in an early stage of a small Spring-based project which utilizes Spring Data Neo4j with an embedded database (but possibly could use a server instance in a later development , too).
My data model and relationships have been designed, Spring Security (with Neo4j), MVC and tiles are set up and also seem to be fully functional.
Now I have the additional requirement to allow login with social networks.
I'm really stuck with trying to integrate Spring Social with my above mentioned setup. Basically I have a rough idea that I need to make use of the cross-store Neo4j component but have no real clue, how I could start with it.
I tried to find something useful for my case (SDN Neo4j + Spring Social Security) on github but was not really successful with that either.
Can anyone provide me an example configuration or even point me to some examples (I obviously didn't find before) ... any help is highly appreciated.
I don't think there is a Spring Social connector yet, but it shouldn't be too hard to write (there is one for Mongo). If nothing else, you can use the https://code.google.com/p/google-api-java-client/ directly form a service, exposing the google oauth callback from a Spring Controller, should work too.
https://code.google.com/p/google-api-java-client/
Neo4j connection repository for Spring social has been implemented here using neo4j-ogm. You can reuse that. https://github.com/maciossek/spring-social-neo4j

Resources