0

I'm creating a system that uses two web services and a client to provide an interface for a travel agent. There is a flight booking web service, which stores the available flights within an xml document (based on a schema) and provides methods to retrieve the offers or book a given flight. There is also a travel agent service which consumes the flight booking service and a currency conversion service in order to provide the user prices in a specific currency. Then the client will consume the travel agency service in order to view and book available flights.

My issue is getting the flight information from the flight booking service to the travel agency service, and onwards to the client. The schema used for the offer list is used within both web services and the client. The xml document containing the offers is unmarshalled within the flight booking service to become an object of OffersType. I want to return this object to the travel agency so that operations can be performed on it, and then it returned to the client. However when accessing the method in the travel agency program it only returns flightbooking.OffersType, which can't be cast into the local OffersType. Is there a way to do this? Or do I need to create a new OffersType which uses the information from the remote OffersType?

So for example, on the flight booking web service:

@WebMethod(operationName = "getOffers")
public OffersType getOffers() {
     try {
        javax.xml.bind.JAXBContext jaxbCtx = javax.xml.bind.JAXBContext.newInstance(this.getClass().getPackage().getName());
        javax.xml.bind.Unmarshaller unmarshaller = jaxbCtx.createUnmarshaller();
        offers = (OffersType) unmarshaller.unmarshal(new java.io.File("\\resources\\CurrentOffers.xml")); //NOI18N
    } catch (javax.xml.bind.JAXBException ex) {
        // XXXTODO Handle exception
        java.util.logging.Logger.getLogger("global").log(java.util.logging.Level.SEVERE, null, ex); //NOI18N
    }
    return offers;
}

with offers being an instance of OffersType.

Then on the travel agency side:

private OffersType getOffers() {
    OffersType ret = new OffersType();
    flightbooking.FlightBookingWS port = service.getFlightBookingWSPort();
    return port.getOffers();
}

but obviously that doesn't work, as the returned object is an instance of flightbooking.OffersType.

skaffman
  • 398,947
  • 96
  • 818
  • 769
Bonnotbh
  • 515
  • 7
  • 24

1 Answers1

1

If you are using Java on both the server and client, I would use Jersey + Jackson on both ends. You can as long as you have the model on both sides, and they're annotated up properly, you can just pass it from one side to another.

There are many examples online, but I'd start with this SO question: How to reuse Jersey's JSON/JAXB for serialization?

Community
  • 1
  • 1
Dan Hardiker
  • 3,013
  • 16
  • 19