1 Reply Latest reply on Jul 13, 2006 2:36 PM by heiko.braun

    Marshalling and Unmarshalling objects within SOAP server

    peterhanlon

      I have a document/literal soap service built using jbossws-1.0.1.GA. The server accepts objects of many different types, processes them then persists them to a database this all works as expected.

      In order to simplify the persistance of the objects I would like to convert the objects into XML before they are persisted and convert them from XML back to objects when they are requested back from the soap service. Given that the JAXB layer used by the web service already knows about my objects and how to Marshal and Unmarshal the objects it seems sensible to reuse this functionality if possible.

      I have tried variations on the code below but I always get an exception saying that it can't load the jaxb.properties file when I try to create a new instance of JAXBContext. I haven't used JAXB before but I can't see why this wouldn't work. If anyone has any ideas I would be really grateful.

      @WebService
      @SOAPBinding(style=SOAPBinding.Style.DOCUMENT,
      use=SOAPBinding.Use.LITERAL,
      parameterStyle=SOAPBinding.ParameterStyle.WRAPPED)

      public class test
      {

      @WebMethod
      public Document store(Document msg){
      try {
      StringWriter XML= new StringWriter();
      JAXBContext jc = JAXBContext.newInstance("uk.co.test.document");
      Marshaller marshaller = jc.createMarshaller();
      marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, new Boolean(true));
      marshaller.marshal(msg, XML);

      System.out.println(XML);
      } catch (Exception e) {
      e.printStackTrace();
      }

      return msg;
      }
      }


      Regards

      Pete