7 September 2018

RD EE6 webservices module 9: alternate lab instructions

  1. Create a new web project Publisher
  2.  Create a new java bean class domain.Address with properties street, number, postalCode, City
  3.  Create a new java bean class domain.Publisher with properties id, name, address
    1. Make sure JAXB can convert this bean from/to XML 
  4. Create a new Soap WebService service.PublisherService. Do not wrap the service in a SessionBean (it will work as a servlet)
    1. We will not save the data to a database. To store the publishers in memory, add this attribute to PublisherService
    2. private static Map<Integer,Publisher> publisherDao = new
      HashMap<Integer,Publisher>(); 
      
    3. Add a webservice method create(String name,Address address) to the PublisherService
      1. In the method create a new Publisher. For the id, take the size of the publisherDao + 1.
      2. Add the Publisher to the publisherDao map. Use its id as the key in the map.
    4. Add a webservice method querySingle(int id). It should return the publisher with this id.
    5. Add a webservice method QueryAll. It should return all publishers
    6. Test and correct any errors
  5. Make sure a SOAP Fault is returned when creating a publisher with invalid parameters
  6. Advanced (Optional)
    1. Customize the Fault to add a detail child element with one or more reasons explaining why the creation failed.
      <detail>
         <canNotCreatePublisher >
           <reason>No address</reason>
           <reason>No name</reason>
         <canNotCreatePublisher> 
      </detail>
      
      Note: the canNotCreatePublisher element may contain some extra namespace information.
    2. Make an ErrorInfo bean class that contains a list of reasons. Make sure objects of the class can be transferred from/to XML using JAXB
    3. Make a CreateException class that inherits from Exception. The class should have an attribute
      private ErrorInfo faultInfo;
      1. Add accessor methods for the attribute and a constructor with the attribute as an argument
      2. Add an @WebFault annotation to the CreateException class
    4. In the create webservice check for the validity of the parameters. If there are invalid parameters throw a CreateException with an error message for each invalid parameter.

No comments:

Post a Comment