Using play and restlet together - heroku

I've developed a pretty extensive rest API using restlet, but now I need to serve web pages. I've looking into the play framework and it seems like a pretty good solution to my problem. There's a lot of code to share so I'd like to have both running from the same server/jvm (for eventual deployment on Heroku.
Is it possible to configure the application server, like jetty, to split the calls up based on URL path to go to either restlet or play? If so how? Do I start with a play project or a restlet project, and how do I modify it?
thanks!

There are several options here
You could use a fronted Apache layer, so that you can completely separate the Restlet part from your Play part. As you are deploying to Heroku though, I am not sure if you will be able to do this as Heroku doesn't give you a fronted http layer
Modify the HTTP handler. This would involve creating your own module or modifying the core source of Play. This certainly would solve your use case, but I don't think modifying core is a great answer, and the module approach is quite overkill.
Using Play 1.x you could have a single controller action for all your Restlet API that simply calls your Restlet services. In Play 2.x you can use the Global object onRouteRequest method.
If you are thinking of deploying to a PaaS like Heroku, I think I would go with option 3.

Related

Create a web service client in Hybris

Im new in Hybris and I need to build a web service client that consumes a web service rest.
Someone have an example? or something that give me an idea, I dont know if is the same like build a web service client in spring.
Thank you.
For REST you can use the default Spring framework for rest client. See this tutorial. here You can create a new extension or use one of yours. See below for more info.
I used Apache Axis2 for consuming the WSDL (the web service). There are a lot of examples and tutorials on the internet for this. It can easily be integrated in Hybris.
The clearest solution is to create another extension using extgen
. Some tips here . You have to modify other the
extensioninfo.xml file of the other extension, where you want to use
the client. (more info in the link above).
The easiest solution is to just add the axis2 lib to the extension
you want to handle the client and use it there. If you want to play
around and test it as a prove of concept, you can do that. Later you
can move it to a separate extension.

Does Spring have any solution for Web Scraping?

I need to build a web application which is going to scrape and crawl some websites and extract data and crawlers will have scheduler. I know there are plenty of tools for parsing and extracting data like Jsoup, but I just want to know whether I can implement this with Spring Tools or not?
There is no one single template project available from Spring which fits your case. But you can definitely achieve what you want through Spring. Spring provides many template projects to develop different kind of applications. There is Spring Boot project to quickly get started with a web application. There is Spring Scheduler project for scheduling tasks. I would suggest combine these two and develop your application.
For crawling and Scraping, I believe there are no templates available from Spring. But you can do it using jSpider and jSoup.

Dart with Maven (in Spring Boot App)

I like Dart, I have been playing with it for a while. I'd like to integrate with my Maven web app project based on Spring Boot.
I suppose the correct way is to use dart-maven-plugin. But I'm not sure how to properly glue it in place. Spring Boot has its own structure, Maven as well and Dart makes that none the better.
I will need probably the entry point for Dart part, means Spring Boot templates folder needs to include the html resources from Dart.
I would appreciate any idea, best practices.
PS: the aforementioned dart-maven-plugin is not really vivid, should I be afraid using it at all, as I don't see any progress there, compared to Dart itself.
UPDATE
So this can be solution(note I have only one so called "entry point"- .dart file so far)
normal Dart structure in src/main/dart
user dart-maven-plugin's pub build command into ${project.build.directory}/dart
maven-resources-plugin:copy-resources from ${project.build.directory}/dart/web to ${project.build.directory}/classes/public/
make war
I'm still able to use Intellij's Dart integration from src/main/dart.
The Spring Boot maps classes/public/ folder to / so the dart file and html files are loaded properly.
It's not ideal, but it works so far. Please fell free to write down any comments.
I have tried a few times to use dart in a maven project myself and always ran into some problems. Right now I'm developing my dart apps in a separate module that I build with pub which connects to the maven based java backends with rest.
This has several advantages for me, for example:
I can use pub and avoid problems with outdated maven plugins
I use the serving mechanism that fits best for the static dart code and assets (in my case a docker image with nginx)
I have a clean separation of backend and frontend code with a tailored REST API
As I like the microservice approach I also use spring session together with zuul (via spring-cloud).
If you want to combine dart with generated html from for example JSPs or another templating engine, then this isn't a good approach for you. But IMHO dart is not yet very well suited for these kind of architectures.

Secure Spring REST Service using spring-security-oauth2 2.0.5.RELEASE

I have been searching for an example Spring Webservice which is being protected using oauth 2.0..
Looking around I found https://github.com/spring-projects/spring-security-oauth/tree/master/samples/oauth2 but there some files seems to be missing from the project.
Two things that I am looking for is :
When user authenticates, user name and password goes to /login.do , now I can not understand how this Servlet is being configured, if its not controller. web.xml is missing.
When I try to see how beans configured then applicationContext.xml is also missing. I am not able to find those files in order to see how things are configured.
Help Required :
Should I use annotation in order to configure my web service or xml configuration. I am willing to use the latest version, and leverage advanced configurations, for better security.
I have another Single page application ( HTML5 ) , which accesses data from this spring web service, which is being hosted on Google App Engine. My ultimate objective is to create a chrome plugin of (html5) pages and use my service from there..
Please suggest a better path so that I can achieve my objectives.
Best regards,
Shashank Pratap
Apologize for late reply.
1) Regarding Oauth2.0 implementation : Since GAE does not support Servlet 3.0 therefore, developer is restricted to servlet 2.5. Therefore I found that we are restricted to 1.0.5.RELEASE. I was able to configure it successfully.
Best Practice on GAE : Rather than following this approach, I would suggest others to use Google Endpoints. As it supports oauth2.0 as well as we can develop REST API relatively quickly.
Scale ability and Response time : Since I was using Spring dependency injection along with spring security, application responded slower than the combination of Google Endpoints and Google Juice, as juice does injection just in time, where as spring prepares everything as soon as new instance starts, which created problem for me.
2) Chrome Plugin is completely different story. :-)
Please correct if I am wrong.
Thanks,
Shashank Pratap

Easiest way to add GWT to a Spring MVC application?

I've got a Spring MVC application and I've decided that I'd like to try using GWT for the front end. I'd like to continue using MVC as I'll also be using Spring Security and some other springy stuff.
I'm aware of the GWT-SL project, and I guess I'll use it. The documentation is light on examples unfortunately.
What I'm wondering now is.... how do I reconfigure my project so that I can use GWT? I'm assuming that I'll lose the ability to run in hosted mode, and I suppose that's ok. Do I just add the GWT and GWT-SL jars, reconfigure my web.xml, and add a package to my project for the GWT code?
I'm using Eclipse 3.4. My existing project is standard web project.
With the new version of the GWT plugin, you'd have all the benefits of the hosted mode browser without having to modify any options. The GWTHandler from the GWT-SL will take care of your rpc call mapping. However, you will have a problem with your existing domain objects structure. You will either have to put them in GWT's 'client' package, or mirror your existing domain objects to enable them to be compiled to javascript. I have been looking for a stable non-invasive framework for doing this, but have yet to find one. Gilead looks promising, but you will have to extend its classes on your domain.
I have posted a view month ago my simple project (3 classes) how to integrate GWT with existing Spring MVC application. Simple sample also provided.
Try it, it is clear and simple: http://code.google.com/p/gspring.
You won't lose hosted mode. I don't know if you're using the internal server for that - I use -noserver so I can't help you there.
Other than that, I guess the documentation is quite clear. Have you hit any specific problems?

Resources