2

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..

merryprankster
  • 3,369
  • 2
  • 24
  • 26
  • What part of JAXB feels heavy in your use case? – bdoughan Aug 19 '11 at 14:14
  • I meant performance wise - I've understood JAXB is not fastest binding framework around. Do correct me if I'm wrong. – merryprankster Aug 19 '11 at 17:13
  • 2
    The only way to judge performance is to profile your app. JAXB (JSR-222) is the default binding layer for Java EE technologies (JAX-WS and JAX-RS), and has some serious users. There are several implementations (Metro, EclipseLink MOXy, Apache JaxMe) available. I'd be wary switching solely based on opinion. Note: I lead the MOXy implementation. – bdoughan Aug 19 '11 at 17:32
  • You're definitely right about measuring vs rumors. It really might be that JAXB is enough in this project. Now that I did quick reading regarding JAXB performance issues, it seems complaints are mostly about the cost of creating JAXB context which should be relatively easy to handle. – merryprankster Aug 19 '11 at 17:43
  • JAXBContext is a thread-safe object that is only meant to be created once. The advantage of this object is that the metadata is precomputed, and the marshalling/unmarshalling can be faster. Some other XML binding offerings initialize on the fly, which can slow down the marshalling/unmarshalling. – bdoughan Aug 19 '11 at 17:45
  • Hmm, interesting - from some of the postings I got the impression that it would not be thread safe, and therefore pooling was suggested. *EDIT* well..I guess I'll have to take that back - I think I just mixed marshallers and context. – merryprankster Aug 19 '11 at 17:47
  • JAXBContext is thread safe. I've seen some people create pools for Marshallers and Unmarshallers which are not thread safe, but they are light-weight objects that can be created on demand. – bdoughan Aug 19 '11 at 17:50

2 Answers2

1

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:

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 ;-)

Community
  • 1
  • 1
Wivani
  • 2,036
  • 22
  • 28
  • Well yes, I guess I've been a bit unclear in many levels ;) Yes, ESB is overkill for my purposes. I'm looking for a lightweight solution. Nor did I mean to ask for patterns or such. Thanks anyways! Regarding the APIs you mentioned, I've looked into those as well. However, I already have Axis2 in the project but didn't even consider it to be possible to user for schemaless integrations so I will give it another look. – merryprankster Aug 19 '11 at 17:37
1

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.

Ryan Ransford
  • 3,224
  • 28
  • 35