Importing/using Java classes in Grails - java

I have an existing RESTful service created with Jersey, for which I created 2 clients (also Java), one using the Jersey client API, and one using Apache HTTP client.
I don't have much frontend experience- I've used Spring/Java a little bit and understand the basic concepts, but I thought I would try learning Grails. I wanted to just use Grails for the front-end (So, no reliance on GORM), and use my existing service for business logic/interaction with storage). Would it be possible for me to just include the jar w/ my existing client and use it in my Grails controller, or will I need to write a new Groovy client for it using a Groovy (or an already included java library)?
I'd also be happy to get opinions on if this seems like a good idea, or if it seems pointless to use Grails if I'm not taking advantage of GORM/Grails data persistence functionality? I figured I could still get the advantage of 'convention over configuration', and maybe some other advantages of the framework, but again I'm pretty new to web development so I'd appreciate any advice.

You can use your existing java client in grails. If your existing client jar is in a maven repo then you can specify dependency for the jar in BuildConfig.groory. or else you can just drop the jar inside your grails projects lib directory.
Also, if your client code depends on any third party jars, you will have to specify dependency for that third party jars in BuildConfig.groovy - See grails docs for how to specify dependencies.
If you want, you can use grails rest-client-builder plugin to write your client too.

Related

Django-cms with non-django-based project

I have a project with a Java backend and Angular-based frontend and I'd like to utilize Django-cms. Is this possible to do with a non-Django project? I've been looking over the documentation, but I can't find an explicit 'yes' or 'no'. I can't wrap my head around how I'd integrate, what seem to me, two very different projects.
No, it's not possible.
django CMS is a standard Django application, that requires a standard kind of Django environment. It can't do anything except as part of a Django project.
There's nothing to stop you configuring your web server so that some requests (by URL) go to the Django project while the others are handled by the Java backend, but this isn't integration, it's simply some form of wholly independent co-existence.

Java Rest framework + server to expose service to Ruby on Rails

I have a very small Java codebase that I would like to expose as a REST service that responds in JSON format (to be used by a Ruby on Rails project).
I have only notions about Java web servers / web frameworks. What would be:
a. a suitable Java MVC and
b. a java server
to ease my deployment? I am interested in:
easy to build(wrap) the solution
easy to maintain / configure the server
stable (not experimental)
We use CXF extensively. It is very simple standard JAX-RS annotation based. There is a good tutorial to set it up quickly. It works with or without Spring, but easier with spring, this is my preference. The other option would be Spring REST it is very similar to Spring MVC which is very easy if you know spring already, but on the other hand it is not JAX-RS based.
you might want to give Grails a try - it:
shares some similarities with RoR
comes bundled with an application server so it's very easy to get up and running
allows very simple deployment to a Java application server (e.g. Tomcat, Jetty)
has built-in support for JSON
has recent stable releases
is under active development
http://www.restlet.org/
http://static.springsource.org/spring/docs/current/spring-framework-reference/html/mvc.html
https://github.com/dhanji/sitebricks (my favorit)
For the server part of the problem, build your code so that it is a servlet and then deploy in a container like Tomcat or Jetty. (There are many others too, but Tomcat and Jetty work very well and are pretty easy to use.)
For the framework, I'd recommend CXF (I've had good success with it in my project) as it keeps the amount of configuration you need to write small (typically just add annotations to mark which methods are to be exposed; the annotations are standardized as JAX-RS), but many others are valid choices too.

Jbilling + Ruby

Are there ready solutions (gems, plugins, libraries, etc) for integration ruby (rails) applications and jbilling?
I didn't find even api client for ruby.
I need someone to share his experience with integration. Jbilling has web-service (SOAP ,Java RMI, Burlap) but there is no specific gem for easy accessing and editing data via API.
JRuby 1.6.0 was Released yesterday.
Lines from jbilling manual "All of the API classes are located in the jbilling_api.jar file located in your jBilling
distribution.
The API also makes use of several third-party libraries, such as the Log4j library and
Commons Logging, which provides a powerful logging infrastructure; Spring, which
handles configuration and remoting; CXF, a SOAP library; and Hessian, for
Hessian/Burlap support. You'll therefore need to provide the log4j.jar, commons-
logging.jar and spring.jar files in your class path, if your project does not already
include them.
"
Is that good practice to include so many jars in jruby rails application ?
You can try making your app run on JRuby and using the Java libraries directly. We did an experimental branch of our own app for a similar reason and found some useful projects in the process:
https://github.com/nicksieger/warbler/
https://github.com/calavera/trinidad
In the end we didn't go for JRuby, for various reasons that weren't necessarily of a technical nature.
What version of jB are you using? You could use this project as an example to do your integration.
You can also build such a project from scratch using wsdl2 java utility. Typically, you can access jBilling wsdl at localhost:8080/jbilling/services/jbilling?wsdl assuming jb is running on your local at port 8080.

Web Services in Java, beginner question

Im new to the subject of web services in java, though im familiar with the concept of web services. As im new to this topic,i have the following questions which i would like someone to help me with.
1) How are web services created in Java ?.Ive come across methods like using Eclipe WTP (Web Tools Platform), Sun WSDP (Web Services Developer Pack). What is the difference between them and which one to use ?
2) Is there any particular book or article on the web which i can refer to for learning how to create a basic web service using Java ?
3) If i have a WSDL file, is there any way i can test it ?
Thank You
1) Actually you have a lot of choices. See this question for a discussion about Java Web Services Frameworks. The two methods actually use a different framework, Eclipse uses Axis2.
2) Most, if not all, frameworks support 'contract first' development (from an existing WSDL), both for services and clients. For testing, SoapUI may also suit your needs.
Before choosing any tool and technology, first understand what webservice technology is about and what benefits it offers.
Its always better to understand the proper semantics of xml, xsd and other concepts(including namespaces).
Then pickup a book/article that explains how to implements one in java.
Choose a framework (Apache Axis, Spring ws etc) and implement one.
There are lot of resources available online that help you in your learning path.
Happy webservices.
For #3, you can test it using the web services explorer in Eclipse. Its really nice actually. Copy the source for the WSDL and copy it into some file in your project (xxxx.wsdl). Then, right click on that file in the navigator and choose "Web Services" -> "Test with Web Services Explorer"
If you dont have this option, then you need to install the necessary plugins into Eclipse to do this (or I think if you install the EE version of Eclipse it already has this). I dont recall which plugin I installed that added this functionality, but it was something relating to web work.
Once you've opened this, you can input values as the wsdl specifies and view the source xml as needed.
I'm also new to web development and I've found this incredibly helpful.
Best of luck!

Java Web Service framework/library, which is a better one and why?

Currently I am evaluating number of web service frameworks in Java. I need web service framework that will help me to expose some functionality of existent application running on JBoss, The application is mostly developed using Spring and POJOs (no EJBs).
What I need is a framework having following properties:
It should provide tools for automatic generation of boilerplate code and save time by eliminating repetitive tasks, for example tools generating WSDL from Java (java2wsdl), tools generating endpoints etc.
Applications should be easily deployed on existent J2EE platform (JBoss), this means that it should contain as less as possible configuration files (like axis2.xml in axis2 framework).
Also it is preferred to be able to deploy web service within .war archive of existent application. (it seems that Axis2 need a separate archive for web service app.)
It will be very cool to use a combination of POJOs and Spring.
Generally, the framework should have clean structure and design (for example Spring-WS lacks it), good documentation and whatever else characterizes a good piece of software.
It is preferred that framework incorporates some standard features like JAX-WS etc. instead of vendor specific methods.
I have briefly examined
Axis2
Apache CXF
and Sun's Metro
Spring WS
But still it is difficult to decide what to use in my case:
Axis2 seems to be so low level, it requires separate application archive and lots of configurations
Spring WS seems to be too opaque and "sophisticated for impression purposes (?)"
Apache CXF and Metro probably are two frameworks that I prefer to chose from but still
I need your opinion and experience about usage of some of them in a real-world applications.
I've used CXF's forerunner, XFire, for a while now and it's not been too bad. At the time, we migrated from Axis for two major reasons: performance and ease of development. At the time (don't know if this is true now), the performance of XFire was much better than anything out there, and with annotation-driven development, instead of having to run stub generation, it was really really easy to add new web services.
CXF seems to be more of the same but better - we haven't migrated yet due to constraints on development time as well as not having a pressing reason to do so (plus the relative lack of documentation 6-12 months ago wasn't too encouraging). Additionally I haven't really evaluated the market of late, so I can't tell you how CXF stands up to its contemporary competitors.
Regarding your points:
There is no boilerplate code to be generated, the WSDL is automatically created from the service class' annotations and published by the server.
Deployment in Tomcat was relatively simple. Just define another servlet in web.xml and map a URL pattern to this servlet.
Our web services were deployed in WAR files, I'm not sure what the alternatives are in fact but this seemed to be the default and obvious way to do it.
POJOs work fine initially; we've now moved most of the web service object creation to Spring in order to wire more complex conditional dependencies in and have had no problems with this.
Documentation was a weak point with CXF originally, though having just had a look it seems to be better now. The general design and architecture seems relatively sane; slotting in one's own filters to modify the transmission details was not very painful, and extending existing classes has generally been considered (so sensible methods are marked protected instead of private, for example).
JAX-WS is full supported in CXF.
So I'm probably a little impartial as I haven't tried the other ones, but I'll give a thumbs up to having a look at CXF. It's pretty fast, relatively simple to get going with and fairly powerful if you need to tweak it.
We have tried Metro and CXF and kept CXF because Metro includes too many dependencies like Sun's APIs in its jar files which makes it difficult to integrate in another application server than Glassfish. CXF has a cleaner packaging with explicit external dependencies.
We also failed to enable Gzip compression with Metro while it worked like a charm with CXF.
I'd go with Spring WS first and XFire second. I'm a Spring user, so I'm used to the opacity.
XFire now Apache CXF was far away easier to use than Axis. I had something done very quickly using it where Axis seemed overly complicated. I didn't look at Spring WS.
I will use CXF. It is easy to use than Axis2
I have only used the Spring WS because that is what I was told to use, but it was a pretty easy use framework. If you have to go with soemthing else I would go with XFire due to the JAX-WS support.

Categories

Resources