Can you may a small (compatible) change to the xsd file?

You probably have something like:

<element name="Rental">
   <complexType>
        <sequence>
               .....


If you change that to:

<element name="Rental" type="Rental"/>
<complexType name="Rental">
     <sequence>
        ....
           
It will probably "just work".   The Rental object would be generated with an 
@XmlType annotation with name="Rental" and thus we can directly access it as a 
a type.

Dan




On Thu January 21 2010 6:38:58 am John Dowson wrote:
> Hi Dan,
> 
> thanks a lot for the reply.  Some more information:
> 
> As I am relatively new to SOA, I am currently investigating various ways of
>  adding a web-service interface to a web application that takes input from
>  legacy systems through Excel spreadsheets via XML.
> 
> If I define my own model and then define the web-services using this model
>  (java-first approach) then everything works as expected (i.e. the services
>  return business objects and not a response object). The problem occurs
>  when I generate my model from an XML schema file using JAXB (xjc) and then
>  build the web services on top of this model (again, a round-about
>  java-first approach!). The Rental class is therefore generated by the JAXB
>  xjc compiler and has both @XmlRootElement and @XmlType annotations
>  (although the name attribute is empty):
> 
> @XmlAccessorType(XmlAccessType.FIELD)
> @XmlType(name = "", propOrder = {
>     "firstContact",
>     "supplier",
>     "managingRepair",
>  .....
>     "repair"
> })
> @XmlRootElement(name = "rental")
> public class Rental {
> 
>     @XmlElement(name = "first-contact", required = true)
>     @XmlSchemaType(name = "dateTime")
>     protected XMLGregorianCalendar firstContact;
> .....
> }
> 
> 
> I know this is a rather strange way of doing this as I should (probably) be
>  using the contract-first approach as I already have a reasonably
>  well-defined schema file. However, as I am currently investigating
>  different approaches, generating the model using JAXB seems (or seemed) to
>  be an easier approach than writing a WSDL by hand. Is there a problem with
>  this approach?
> 
> The WSDL is automatically generated given the model and the services
>  definitions - relevant sections:
> 
> <wsdl:message name="getClaimByReferenceNumberResponse">
>     <wsdl:part element="tns:getClaimByReferenceNumberResponse"
>  name="parameters"></wsdl:part> </wsdl:message>
> 
> <wsdl:message name="getClaimByReferenceNumber">
>     <wsdl:part element="tns:getClaimByReferenceNumber"
>  name="parameters"></wsdl:part> </wsdl:message>
> 
> <wsdl:portType name="MyServices">
>     <wsdl:operation name="getClaimByReferenceNumber">
>         <wsdl:input message="tns:getClaimByReferenceNumber"
>  name="getClaimByReferenceNumber"> </wsdl:input> <wsdl:output
>  message="tns:getClaimByReferenceNumberResponse"
>  name="getClaimByReferenceNumberResponse"> </wsdl:output> </wsdl:operation>
> </wsdl:portType>
> 
> <wsdl:binding name="MyServicesImplServiceSoapBinding"
>  type="tns:MyServices"> <soap:binding style="document"
>  transport="http://schemas.xmlsoap.org/soap/http"/>
> 
>     <wsdl:operation name="getClaimByReferenceNumber">
>         <soap:operation soapAction="" style="document"/>
> 
>         <wsdl:input name="getClaimByReferenceNumber">
>             <soap:body use="literal"/>
>         </wsdl:input>
> 
>         <wsdl:output name="getClaimByReferenceNumberResponse">
>             <soap:body use="literal"/>
>         </wsdl:output>
>     </wsdl:operation>
> 
> </wsdl:binding>
> 
> 
> Thanks in advance.
> 
> Regards,
> 
> John
> 
> On 20 Jan 2010, at 21:08, Daniel Kulp wrote:
> > I'd probably need to see a small example and the wsdl and such.  Probably
> > would need to see the Rental class as well, at least any class level
> > annotations that are on it.
> >
> > One common things that would cause this is if the Rental class has an
> > @XmlRootElement annotation, but not and @XmlType annotation.   Then
> > again, I'm not even sure if that worked at all in 2.2.5.   I fixed SOME
> > things when using this format in 2.2.6.  My fixes may have just been for
> > JAX-RS though.  Don't really remember.   (been one of those weeks :-)
> >
> >
> > Dan
> >
> > On Mon January 18 2010 10:05:55 am John Dowson wrote:
> >> Hi,
> >>
> >> I am developing a simple web service interface to an existing web
> >> application (java-first). I am using Apache CXF  2.2.5 and Spring 2.5.6.
> >>
> >> I have defined a simple web service interface:
> >>
> >> @WebService
> >> public interface MyServices {
> >>    public @WebResult(name="rental")Rental
> >> getClaimByReferenceNumber(@WebParam(name="referenceNumber") String
> >> referenceNumber); }
> >>
> >> and its corresponding implementation:
> >>
> >> @WebService(endpointInterface = "my.services.MyServices")
> >> public class MyServicesImpl implements MyServices {
> >>    @Autowired
> >>    private ClaimService claimService;
> >>
> >>    public void setClaimService(ClaimService claimService) {
> >>        this.claimService = claimService;
> >>    }
> >>
> >>    @Transactional
> >> //    @WebMethod
> >>    @Override
> >>    public Rental getClaimByReferenceNumber(String choReferenceNumber) {
> >>
> >>        Claim claim =
> >> claimService.getClaimByReferenceNumber(choReferenceNumber);
> >>
> >>        Rental rental = MapUtils.convert(claim);
> >>
> >>        return rental;
> >>    }
> >> ...
> >>
> >> I can install this web service (on Tomcat 6.0.20) and it seems to work
> >> ok.
> >>
> >> I then generate a test client to test the web service, using netbeans
> >> 6.8 'New Web service Client' wizard, pointing the wizard to the WSDL
> >> URL. The following test method correctly calls the web service and
> >> marshals the result to a file:
> >>
> >> public class TestGetClaimService {
> >>
> >>    private static final String[] LOCATIONS = {"context.xml"};
> >>
> >>    public static void main(String[] args) throws Exception {
> >>        ApplicationContext ctx = new
> >> ClassPathXmlApplicationContext(LOCATIONS);
> >>
> >>        AXServices client = (AXServices) ctx.getBean("myServices");
> >>
> >>        GetClaimByReferenceNumberResponse.Rental rental =
> >> client.getClaimByReferenceNumber("1923988"); JAXBContext context =
> >> JAXBContext.newInstance(GetClaimByReferenceNumberResponse.Rental.class);
> >>
> >>        Marshaller m = context.createMarshaller();
> >>        m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
> >>
> >>        System.out.println("Claim is: ");
> >>        m.marshal(rental, System.out);
> >> }
> >>
> >>
> >> The problem I have is that I now have a
> >> GetClaimByReferenceNumberResponse.Rental object, whereas what I actually
> >> want is a Rental object (both classes are automatically generated from
> >> the WSDL file). How can I achieve this, i.e. return a plain object from
> >> the web service call rather than having it wrapped-up in a response
> >> object,
> >>
> >>   Rental rental = client.getClaimByReferenceNumber("1923988");
> >>        JAXBContext context = JAXBContext.newInstance(Rental.class);
> >> ...
> >>
> >> I am guessing that this is a common problem but have not managed to find
> >> a solution. All the tutorials I have seen seem to be able to return the
> >> business object directly (i.e. not wrapped in a response), but I am
> >> unsure of how they are doing this. I am new to Apache CXF and web
> >> services in general, as well as this user list, so please forgive me if
> >> this question has already been posed (how do you search the user
> >> lists?).
> >>
> >> Let me know if you need anything else (WSDL file, for example)
> >>
> >> Thanks in advance,
> >>
> >>
> >>
> >> John L. Dowson MSc
> >> Senior Developer
> >>
> >> Tel: +44 (0)1923 883921
> >> Mobile: +44 (0)7929 630850
> >> Email:
> >> john.dow...@sherwoodcompliance.co.uk<mailto:john.dow...@sherwoodcomplian
> >>ce .co.uk>
> >>
> >>
> >>
> >>
> >>
> >>
> >>
> >>
> >>
> >> ________________________________
> >> Sherwood Compliance Services
> >> Batchworth Park, London Road, Rickmansworth, Hertfordshire. WD3 1JS
> >>
> >>
> >> This e-mail is only intended for the person(s) to whom it is addressed
> >> and may contain confidential information.
> >>
> >> Sherwood Compliance Services does not accept responsibility for any loss
> >> or damage caused by this e-mail or any attachments. Any opinions or
> >> comments may be personal to the writer and may not represent the view of
> >> Sherwood Compliance Services. If you have received this e-mail in error,
> >> please notify the sender immediately and then delete this message from
> >> your system.
> >>
> >> Company registered in England 4819089 at 55 Station Road, Beaconsfield,
> >> Buckinghamshire. HP9 1QS
> >
> > --
> > Daniel Kulp
> > dk...@apache.org
> > http://www.dankulp.com/blog
> 
> John L. Dowson MSc
> Senior Developer
> 
> Sherwood Compliance Services
> Tel: +44 (0)1923 883921
> Mobile: +44 (0)7929 630850
> Email: john.dow...@sherwoodcompliance.co.uk
> 
> 
> 
> 
> 
> 
> 
> 
> 
> Sherwood Compliance Services
> Batchworth Park, London Road, Rickmansworth, Hertfordshire. WD3 1JS
> 
> 
> This e-mail is only intended for the person(s) to whom it is addressed and
>  may contain confidential information.
> 
> Sherwood Compliance Services does not accept responsibility for any loss or
>  damage caused by this e-mail or any attachments. Any opinions or comments
>  may be personal to the writer and may not represent the view of Sherwood
>  Compliance Services. If you have received this e-mail in error, please
>  notify the sender immediately and then delete this message from your
>  system.
> 
> Company registered in England 4819089 at 55 Station Road, Beaconsfield,
>  Buckinghamshire. HP9 1QS
> 

-- 
Daniel Kulp
dk...@apache.org
http://www.dankulp.com/blog

Reply via email to