Embedding Java libraries (Solr) in Play Framework? - java

I recently asked this question and got the answer. I have another related query before proceeding. I am processing possibilities of using Play Framework (any Java framework for that matter) for frontend to reduce the load of calling a java application running Solrj and making output in Json and reading on frontend via PHP to display. I am wondered if I use Play Framework and as we know, Solrj can work inherently with Java, I can have a class for Solrj in my application and can work on it directly without need of reading any JSON. Does it sounds a good idea? Or will it greatly slowdown site load time due to loading of Solrj everytime. It can be considered a general question as well, not just for Solj.
Is it feasible to use different Java libraries with Play Framework, or
should I do all processing in a different application, provide output
to Play Framework as Json , read it from there. Does it make any
difference ?

The maven repository even generates Scala/SBT code for including it into project/Build.scala. Its kinda easy to add Solrj into your project.
http://mvnrepository.com/artifact/org.apache.solr/solr-solrj/4.3.1
You can call Solr from Play using its HTTP and JSON libraries:
Call Solr asynchronous from Play Framework

Related

Is it possible to use more than one framework at the backend(Spring boot + Django)?

tl;dr: Is Spring + Django back-end possible?
When I was new to industry and was still working my way around the office, I got interested in Django and created a very small, basic-level application using the framework. When I got to meet my team after a few weeks, they said to go for Spring framework. After spending half a year on the framework and the main proj, I finally started to get time to start working off-hours. But, I don't want to lose both the skills - My teammate(when we were still in office ;) ) once told me that they worked on a project that started with python code, and then later added features using Java. And I am unable to find any helpful google searches(mostly showing Spring vs Django).
How should I go about it? Is it too much to ask for? Is it worthwhile? Will I learn some new concepts of application architecture a noob like me would have missed. Please provide me with some insight.
Are there resources(docs) I can go through?
P.S. I'm not a diehard fan of either of the frameworks right now, just another coder testing waters.
You can't write java in python.
You can extend Python with C/C++ which is quite common: Extending Python with C or C++
And about the part that they told that they added features with java:
It's common to create different parts of a project using different languages and tools. Microservice architecture is a common architecture for these kinds of use cases. You basically code different parts of the project in a language you want and then you connect all the parts using different methods like REST APIs, gRPC and etc.
Imagine you are creating a website like youtube that lets others upload videos. There is a form that users upload their files and you store them in your storage and then you have to encode the video file for different qualities. You can code the form handler using Python and Django to store the files in your storage. Then you can code another service using java that handles the encoding part which is a heavy process. When an upload is completed, you send the file or file path to your java service using an internal REST API and tell the service to start encoding the video and notify the Django service and then the Django service will publish the video on the feed that can itself be written in another language.
I would say go for 1 framework and stick with it. For example Django if you want to code in python, and spring if you want to code in java. Learning both frameworks however brings a lot of value, because you can compare their benefits (eg. spring forces you to write clean code, django has build-in and simpler database management)
I like Django's build-in tooling a lot, you only need to know python for it to work. Spring requires a bit more knowledge of eg. hibernate for database management. However I predict Django will outgrow spring at some point, because of cloud valuing fast iteration over code and quick startup time (auto-scaling apps) over large overhead apps and long boot times. Hoever, if you like java, I can recommend JHipster for java/spring webapp development to get up to speed very fast and learning the ways of REST CRUD api fast.
To combine 2 programs: write your main logic in one app, and write a small service in the second language, making sure its independent of the first app (no back and forth communication and complicated logic, but simple independent request/response, as if the main app was never there). Add a REST api to the second app and use eg. http requests to communicate.
What's possible in terms of combining languages:
connect different applications with each other: by letting them communicate through their APIs. For example a python api developed with flask or django can send requests to a java api developed with spring, as long as they have a way to communicate (eg over http, or via some queue like rabbitmq)
connect a webapp to 2 different backends: by using a shared authentication system: For example a keycloak authentication server to handle tokens, that your backend applications know about.
What's not possible (and also not preferable):
combining java with python code in the same program: there are some hacky ways to get it to work, but its asking for trouble and not readable.

REST API with Akka in Java

I am trying to create my own REST-based API using Java and Akka. I have created my main algorithmic implementation using Akka already. My confusion is coming in the form of how to implement the REST part of this. Most examples and libraries I have seen are specifically for Scala, which I am at the moment trying to stay away from.
I see Spray is a good way to go, but I see it's supposed to be for Scala. However, I know Scala compiles down to Java Byte Code and Java should be able to call Scala and visa versa. Is it possible to do this with Spray? If so, are there any working examples or tutorials online? I am not having any luck anywhere.
Thanks for your help and time.
I would recommend you to use playframework 2.0. It is already integrated with akka and you can choose to write your code in Java or Scala. Its will be very easy to implement a REST-based API.
Actually, I went down the same exact path: wanted to use Akka for REST-based services implementation and did not want to use Scala.
Akka can be used with Play-mini, which gives you the Sinatra-like REST mapping without any of the ui stuff (you don't need).
You may also want to look at the Spray Framework http://spray.io/.
It might be the lightweight alternative to Play Framework.
Here is a github repo with Jersey 2 Rest Service using Akka actors for processing in a Java project based on Maven.
https://github.com/pofallon/jersey2-akka-java
I think you want to look at this:
https://www.typesafe.com/activator/template/akka-http-microservice
Simple (micro)service which demonstrates how to accomplish tasks typical for REST service using Akka HTTP. Project includes: starting standalone HTTP server, handling simple file-based configuration, logging, routing, deconstructing requests, unmarshalling JSON entities to Scala's case classes, marshaling Scala's case classes to JSON responses, error handling, issuing requests to external services, testing with mocking of external services.
There is an old entry (2010) on akka github for a akka-sample-rest-java example that would be really interesting. However it's removed in following versions, don't know why.
https://github.com/akka/akka-modules/tree/v1.0/akka-samples/akka-sample-rest-java/src/main/java/sample/rest/java
Since it has been unmaintained, most of the classes rely on old versions of akka and does not works with the most recent ones.
at the moment two modern microservices & REST technologies: Vert.x and dropwizard
Akka-HTTP is the defacto Spray 2.0 as this stackoverflow thread shows:
Spray, Akka-http and Play, Which is the best bet for a new HTTP/REST project
So, I would opt for choosing Akka-HTTP if REST based API for Akka was what you were looking for.

How integrate RapidMiner in a PHP web application?

I've got an implementation in RapidMiner that classifies questions according to Bloom's taxonomy. I need to consume the data produced by a web application developed in PHP and show the results in the interface of the web application.
So I'm wondering if it is possible that the application in PHP communicates with RapidMiner to process the data and show the results provided by RapidMiner in the interface.
I know RapidMiner is implemented in Java, and there is the option of using Java bridge to comunicate PHP and JAVA, but I'm not sure if that is a solution to this.
Why not try to communicate with xml, for example, PHP app sends a list of questions via xml to rm, it then processes it and returns an xml feed. I think this'll likely be the easiest solution.. As far as performance, I can't say one way or the other if it's the best solution

Can I avoid Java EE to create a light-weight web page?

Everything I download seems hellbent on using all of Java EE. I need to build a single page to handle requests to it and do a tiny bit of processing based on parameters. This is to hook into another framework that will routinely call this URL.
I want a quick and easy way to create a page with some processing. Is there an easy way to do this using Java? I am using Java because I am comfortable with Java. I used SE for years and did some work in EE but I don't want all the stuff that comes with EE.
Should I maybe just avoid Java altogether and use something else. This needs to be deployed in a linux environment.
I used SE for years and did some work in EE but I don't want all the stuff that comes with EE.
Then just use a Servlet and that's all. Nothing, I repeat NOTHING, forces you to use "all that stuff" and your question is either a free rant or shows some deep misunderstanding.
You need Tomcat (or jetty, or any servlet container - jetty has an embeddable version btw)
You need a .jsp file and optionally an HttpServlet
Generally, it's not a good practice to put any processing code in a JSP, but if it is really simple and won't be extended, simply put the logic there - it is translated to a Servlet anyway.
yes, all the servlet based solutions are quite chubby.
jetty is all right, but the download is 20MB. that is ridiculous.
currently, the best choice is probably com.sun.net.httpserver which is bundled in JDK 6. you can easily implement your service.
It sounds like you could use PHP to do your processing. Call the page and POST the parameters to it, compute, and return the result.
If you are not very particular about using java and are willing to experiment, you should look at nodejs. It runs on V8 javascript engine and runs on linux.
There are a couple of fraemworks for nodejs for web apps:
Expressjs and spludo
as mentioned, you can do this very simply with jetty and a servlet, you don't even need a JSP if you just need a URL that does some processing based on request parameters and returns a response.
For development, it's really easy to create a dynamic web project in eclipse, just follow the steps in this article.
That said, I don't think java is a great choice for really lightweight stuff. PHP is probably the easiest thing to use if you just want to get it working yesterday.
You can use Java with FastCGI. This is very flexible, but also a bit low-level for most Java programmers.
If you aren't afraid of servlets (they are only a very small part of Java EE!), I can recommend JAX-RS, it is quite easy to get started with. If you client-side is JavaScript based, you can avoid using JSP (which I would recommend you to avoid).
For example, see backbone-jax-cellar. The Java source is here. For a Java app, this is light-weight. He is rolling his own DAO, but that's the price you pay for using Java and SQL and no dependencies (other than JDBC). The code is reminiscent of object-oriented PHP if you ask me. The point is, that if you have a JavaScript client, you don't need template rendering or all that cruft and a REST interface should be enough.
If you are afraid of the heavy build systems too, I made an example REST Todo app backend (which uses an existing frontend) that only requires a POSIX system, the JDK and sqlite3, and gets its own other dependencies (including webserver). I did not use a DAO. The repository front page has a README.
Another possibility is the Play Framework which does not use Java EE. It is rather heavy-weight, though. Full featured though. You would definitely need to use an IDE for this, you don't need that for developing JAX-RS/FastCGI apps.
I would reccomend Sinatra it is a very light-weight ruby web framework.

Creating a search application on Eclipse with GWT and Protege

I would like to create a search application connected to a RDF/OWL database on Eclipse. I would like to use the Google Widget Toolkit plugin for the front end and the Protege plugin for the database side. Do I need some other "essential" tool for creating this application?
In additional to GWT i can recommend you Vaadin, for actually searching Lucene can be useful. And of course look at Spring Framework and Groovy for rapid development.
Give us more information about what you supposed to create?
If you come from java GWT will feel instantly familiar. For the front end It abstracts away most of the quirks of java script development.
In your case I would concentrate on the RPC asynchronous way and how will you transport data to the front end / serialization deserialization. GWT offers many different approaches you need to find out which solves your problem best.

Categories