Topic
6 replies Latest Post - ‏2012-02-08T17:05:38Z by SystemAdmin
SystemAdmin
SystemAdmin
14225 Posts
ACCEPTED ANSWER

Pinned topic UML to Java generating wrong servlet intialisation parameter

‏2012-01-31T15:07:46Z |
I am using the JAX-RS & REST modelling feature in Rational Software Architect 8.0.3. When I run the UML to Java transform the web.xml file is updated with the initialisation parameter for the servlet being set to javax.ws.rs.Application, which RSA then flags as a problem. I can manually correct this to javax.ws.rs.core.Application, however is there any way I can fix the transformation to create the right entry.

Regards,
Adrian
Updated on 2012-02-08T17:05:38Z at 2012-02-08T17:05:38Z by SystemAdmin
  • SystemAdmin
    SystemAdmin
    14225 Posts
    ACCEPTED ANSWER

    Re: UML to Java generating wrong servlet intialisation parameter

    ‏2012-02-06T06:39:24Z  in response to SystemAdmin
    You need to have an Application class created from the REST palette in your model.

    Please see this article for more details on modeling - http://www.ibm.com/developerworks/rational/library/design-implement-restful-web-services/index.html

    regards
    Sandeep
    • SystemAdmin
      SystemAdmin
      14225 Posts
      ACCEPTED ANSWER

      Re: UML to Java generating wrong servlet intialisation parameter

      ‏2012-02-08T13:31:28Z  in response to SystemAdmin
      Thanks for your reply.

      I have an Application class created from the REST palette in my model, the problem is that the transform is not tranforming the Application class to javax.ws.rs.core.Application, instead it is using javax.ws.rs.Application.

      Regards,
      Adrian
      • SystemAdmin
        SystemAdmin
        14225 Posts
        ACCEPTED ANSWER

        Re: UML to Java generating wrong servlet intialisation parameter

        ‏2012-02-08T13:50:17Z  in response to SystemAdmin
        I am not sure you are getting -

        Normally this is what you should get in web.xml:

        
        <servlet> <description> JAX-RS Tools Generated - Do not modify</description> <servlet-name>JAX-RS Servlet</servlet-name> <servlet-class>com.ibm.websphere.jaxrs.server.IBMRestServlet</servlet-class> <init-param> <param-name>javax.ws.rs.Application</param-name> <param-value>ApplicationClass</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>JAX-RS Servlet</servlet-name> <url-pattern/> </servlet-mapping>
        

        and this in java:

        
        
        
        import java.util.Set; 
        
        import java.util.HashSet; 
        
        import javax.ws.rs.core.Application;   
        /** * <!-- begin-UML-doc --> * <!-- end-UML-doc --> * @author SKATOCH * @generated "UML to Java (com.ibm.xtools.transform.uml2.java5.internal.UML2JavaTransform)" */ 
        
        public 
        
        class ApplicationClass 
        
        extends Application 
        { 
        /** * @return * @generated "UML to Java (com.ibm.xtools.transform.uml2.java5.internal.UML2JavaTransform)" */ 
        
        public Set<Class<?>> getClasses() 
        { Set<Class<?>> classes = 
        
        new HashSet<Class<?>>(); 
        
        return classes; 
        } 
        }
        


        What exactly are you getting?
        • SystemAdmin
          SystemAdmin
          14225 Posts
          ACCEPTED ANSWER

          Re: UML to Java generating wrong servlet intialisation parameter

          ‏2012-02-08T14:33:41Z  in response to SystemAdmin
          Ah, sorry, I've found my mistake.

          The error I saw was "The param-value should be a class that extends javax.ws.rs.core.Application" - using your example, changing

          <init-param>
          <param-name>javax.ws.rs.Application</param-name>
          <param-value>ApplicationClass</param-value>
          </init-param>

          to

          <init-param>
          <param-name>javax.ws.rs.core.Application</param-name>
          <param-value>ApplicationClass</param-value>
          </init-param>

          fixed this error (and the servlet still worked OK).

          But the real problem was that the class name needs to be fully qualified, eg a.b.c.ApplicationClass. When I fixed this everything is OK.

          Thanks for your help on this, you gave me some useful pointers to help find the problem.

          Regards,
          Adrian
          • SystemAdmin
            SystemAdmin
            14225 Posts
            ACCEPTED ANSWER

            Re: UML to Java generating wrong servlet intialisation parameter

            ‏2012-02-08T14:46:40Z  in response to SystemAdmin
            Hmm, I don't think what you have is right. The param-name has to be:

            <param-name>javax.ws.rs.Application</param-name>

            as per the JAX-RS spec. The value has to be javax.ws.rs.core.Application derived class.

            What JAX-RS implementation are you using? Websphere?
            • SystemAdmin
              SystemAdmin
              14225 Posts
              ACCEPTED ANSWER

              Re: UML to Java generating wrong servlet intialisation parameter

              ‏2012-02-08T17:05:38Z  in response to SystemAdmin
              Sorry, I wasn't very clear on what I did.

              I have both <param-name>javax.ws.rs.Application</param-name> and a fully qualified class name (a.b.c.d), and now both the servlet works and Rational Software Architect finds no errors. a.b.c.d extends javax.ws.rs.core.Application. So I now have this correctly setup and working.

              Before this I think I had combined two incorrect workarounds that cancelled each other out before, but this was the wrong thing to do.

              Regards,
              Adrian