While reading documentation of Google Data API and Atlassian REST API, I found interesting functionality - link (or title, element expansion) - http://bit.ly/i3rKMw. I would like to implement this functionality in my Java project of web service server for our IS, but I can't find any proper solution or advices for implementation. My project is quite big with many services so I need some robust and most automated solution. I was thinking about how to implement it like an extension for RESTEasy and JAXB, but it seems to be very complicated.
Do you know some opensource projects which implements this functionality or any advices which could help me?
Resteasy already provides an annotation based solution for this:
http://docs.jboss.org/resteasy/2.0.0.GA/userguide/html_single/#LinkHeader
This was added to version 2.0
I don't think that any JAX-RS framework can provide such logic.
It actually a business logic: when you receive expand query parameter, expand the relevant element/section.
You'll need to implement it yourself.
Related
I've been searching for an answer to this problem and found a lot of resources on how to build a REST API that supports pagination, sorting, and filtering, using what are considered best practices by each author. The problem lies in the fact that these best practices seem to be subjective and there isn't a standardized way to implement these features.
The best examples of what I'm looking for are this implementation that makes use of Spring Data and a Gist published by someone who found himself on the same situation. The first solution relies on Spring Data JPA, whereas I'm using vanilla JPA, which would make me change my entire logic. The second example seems a bit crude since the author himself states that it doesn't contemplate HATEOAS and links, which are, from what I've gathered, an important part of a modern pagination for REST APIs.
What I can't seem to find is a "plug-and-play" implementation of these concepts, that can be easily integrated with Jersey, even if it means adapting my JPA logic to use its methods.
Surely there are advantages to custom implementations as they can be adapted to each project's specific needs, but they can lead to some pitfalls and end up hurting the API in the long run. It would be really useful to have some kind of annotation that can be injected and parse all the required fields, such as sort, order, page, etc.
Is there a dependency that I can add to my project that doesn't force me to reinvent the wheel?
I'm currently using this configuration that I adapted from the example provided in the question. It's not optimal but it works until I can find a better solution. Hope this helps someone who's in the same situation!
I am working on an application which is built in .NET and Java. The Java component contains the complete Rule base using Redhat BRMS suite. The .NET client (UI and desktop based applications) will be consulting the Java Rule engine and sending/receiving the JSON data. The decision which has been taken is to expose the Rules engine (Redhat BRMS 6.0.0 using Drools) as a REST based API. I have come-up with the following design approaches:
Write a REST controller in Spring framework and service classes for calling BRMS.
Write a simple REST controller using JBOSS proprietary RESTSY or JAXRS.
Write a Camel adapter and wrap the REST calls behind the Camel and let the Camel talk to Drools.
Wrap REST behind SOAP based webservices.
I want to ask which one would be the better approach for designing such as System.
Any other thoughts are welcome.
As might be obvious from https://github.com/gratiartis/sctrcd-payment-validation-web and https://github.com/gratiartis/qzr my general preference is for exposing my Drools business rules using REST APIs in a Spring application.
The only alternative I consider in the above list is 4, where the API is exposed through a SOAP web service. Albeit definitely not wrapping a JSON REST service! A well-designed Spring application can expose functionality through both REST and SOAP APIs with very little effort.
I have usually exposed via SOAP when working with .NET clients. Firstly, the .NET tooling has excellent support for generating proxies based on WSDL that you have defined. Secondly, the WSDL forms a well-defined contract which both you and the client developers must obey. Having a strict contract can be very useful in preventing arguments. Although if your interface is simple, it may not be so much of a benefit.
The other key reason is that the WSDL does not change unless you change it deliberately. A REST JSON API may seem quick to develop, thanks to Jackson generating everything for you. However, it can expose your internal object model (and dependencies!), meaning that unless you are careful, what seems like a trivial change to an internal model can make private data visible and can break clients.
All that said, if you can keep the API reasonably simple and have a good relationship with the .NET devs (perhaps you're one of them), then going with the Spring REST API would be my recommendation. Feel free to steal code from the github repos if it can help you get started!
btw - If you were to consider Camel, it's worth noting that there is a Drools-Camel component which does quite a bit of the work for you.
In my view,
I would go with the option 1. This is the simplest and easiest approach.
Option 2 may be second choice.
Option 3 - Looks like if there are some routing rules you could choose. Again its could make it complex.
And definitely not option 4 to make it complicated with SOAP.
I need to write integrations to multiple external web services. Some of them are SOAP (have WSDL), some of them pretty much ad hoc - HTTP(s), authentication either by basic auth or parameters in URL (!), natural-language like XML which does not really map nicely to domain classes..
For now, I've done the spike integrations using Spring Web 3.0 RestTemplate and binding using JAXB2 (Jaxb2Marshaller). Some kind of binding is needed because domain classes need to be cleaner than the XML.
It works, but it kind of feels bad. Obviously this partially just because how the services are built. And one minor issue I have is naming of RestTemplate as services have nothing to do with REST. This I can live with. JAXB2 feels a bit heavy though.
So, I'm looking for some other alternatives. Ideas? I'd like to have a simple solution (so RestTemplate is fine), not too enterprisey..
While some of your services may be schemaless XML, they will still probably have a well-documented API. One of the techniques that the Spring folks seem to be pushing, at least from the web-service server side, is to use XPath/XQuery for retrieving only the information you really need from a request. I know that this may only end up being part of your solution, but I'm not sure that this is a situation where one particular binding framework is going to meet all your needs.
If I understand correctly you have 1 application that has to make calls to various external (web) services by use of different technologies. The first thing that comes to mind is to have some intermediate level. While this could be something as elaborate as en ESB-solution, my guess is that is not what you're looking for.
You could for example achieve this intermediate level by having a class hierarchy with at its top an interface 'Consumer'. Method to be implemented: doConsume() and so on.
If you look into it you'll probably have the opportunity to make use of several design patterns like Strategy or Template. Remember to be pro-active and try to ask a few times 'What if ..' (As in: what if they need me to consume yet another service? etc.)
If JAXB feels too heavy there are other API's to be found:
Axis
JAX-WS
CXF
other
It'll depend on the situation which one would be better. If you run into troubles with any of them I'm sure you'll be able to find help here on SO (and from people who have more hands-on experience with them than me ;-)
I wrote a piece of java code using threads, JDBC, Java Mail API etc. without using any of the frameworks (read Spring). I am frankly not too comfortable learning them first (lots of terminologies to remember!) and use them. So, please suggest me some ways to refine my existing code incorporating few of these framework concepts applicable to the aforementioned things without having to learn a lot about them. Is there any quick way to learn some vital framework concepts and use it.. sounds certainly foolish, but still looking for somebody's experiences :)
If you aren't interested in frameworks, your code should at least use interfaces and layering that's appropriate. Your app will be well-layered if you have interfaces for services and repositories whether you use a framework or not.
You should have a front controller servlet that accepts all requests.
You should bind and validate all requests prior to processing in the service tier.
The services should be completely separate from your web tier. If you can't unbolt the web UI and have the rest of the stuff work, you're doing it wrong.
for your simple stuff i dont really see a value add of using framework. u could replace the thread handling with the Java 5 Executors though. And if you want IoC/dependency injection then look into Google Guice
I am not one of those people that can read a book and understand (although, I certainly wish I was that type). I have to learn by doing so I suggest installing an IDE that supports the framework you want to learn and do the tutorials or build something that you can use personally. Couple that with some books/internet for reference and guidance. Good luck!
I am looking for a library or code snippet to allow me to serialize and de serialize an object into a SOAP representation. Similar to what the .NET SoapFormatter does but an implementation in Java.
I have looked on Google and web but so far I have been unable to find something which does it. I know there is a namepsace in javax for SOAP, but again, if this holds what I need ton achieve it, I am looking for a little guidance code to show me an example or something.
TIA
Andrew
Please take a look at the JAXB(Java Architecture for XML Binding) and SAAJ(SOAP with Attachments API for Java).
There are more web service implementations in Java than you could shake a stick at. There is no one way of doing this stuff.
Are you actually looking for a web service implementation, or just that one very specific task? There's no such thing as "SOAP representation", so I'm not sure what you're asking for.