Using Swagger In module servlets does not work as expected but works through openmrs core servelets

11 views
Skip to first unread message

Harsha Kumara

unread,
Apr 6, 2015, 3:45:05 PM4/6/15
to d...@openmrs.org, Darius Jazayeri, Wyclif Luyima, Saptarshi Purkayastha, Suranga Kasthurirathne
Hi all,

I was following[1] to integrate swagger into the FHIR module. In[1], we have to add mappings as follow in web.xml

For finding the annotated APIs which uses by swagger internal 
<!-- swagger servlet reader -->
<servlet>
  <servlet-name>DefaultServletReaderConfig</servlet-name>
  <servlet-class>com.wordnik.swagger.servlet.config.DefaultServletReaderConfig</servlet-class>
  <load-on-startup>2</load-on-startup>
  <init-param>
    <param-name>swagger.resource.package</param-name>
    <param-value>com.wordnik.swagger.sample.servlet</param-value>
  </init-param>
  <init-param>
    <param-name>swagger.api.basepath</param-name>
    <param-value>http://localhost:8002</param-value>
  </init-param>
  <init-param>
    <param-name>api.version</param-name>
    <param-value>1.0.0</param-value>
  </init-param
</servlet>

And  swagger API servelet
<!-- swagger api declaration -->
<servlet>
  <servlet-name>ApiDeclarationServlet</servlet-name>
  <servlet-class>com.wordnik.swagger.servlet.listing.ApiDeclarationServlet</servlet-class>
</servlet>
<servlet-mapping>
  <servlet-name>ApiDeclarationServlet</servlet-name>
  <url-pattern>/api-docs/*</url-pattern
</servlet-mapping>

When I specified that in openmrs web.xml. It will generate the api doc from selected servelets in http:// localhost/openmrs/api-docs. 

But when I declare the servelets in module config.xml I get no response. 

I even extend above servelet and created one by own. GET requests are coming to the servelet which I confirmed through debugging. But there is no response from the servelet declared in the module config.xml even doGet function is called in the servelet.

Any thoughts about what can be going wrong here?

Thanks,
Harsha
 

--
Harsha Kumara
Software Engineer
WSO2 Inc.
Sri Lanka.

Wyclif Luyima

unread,
Apr 7, 2015, 3:04:30 PM4/7/15
to Harsha Kumara, d...@openmrs.org, Darius Jazayeri, Saptarshi Purkayastha, Suranga Kasthurirathne
Hi Harsha,

What URL are you entering to hit the servlet? Did you read this?

Wyclif
--
Wyclif Luyima
Regenstrief Institute Inc.

Confidentiality Notice: The contents of this message and any files transmitted with it may contain confidential and/or privileged information and are intended solely for the use of the named addressee(s). Additionally, the information contained herein may have been disclosed to you from medical records with confidentiality protected by federal and state laws. Federal regulations and State laws prohibit you from making further disclosure of such information without the specific written consent of the person to whom the information pertains or as otherwise permitted by such regulations. A general authorization for the release of medical or other information is not sufficient for this purpose.

If you have received this message in error, please notify the sender by return e-mail and delete the original message. Any retention, disclosure, copying, distribution or use of this information by anyone other than the intended recipient is strictly prohibited.

Harsha Kumara

unread,
Apr 7, 2015, 10:52:06 PM4/7/15
to Wyclif Luyima, d...@openmrs.org, Darius Jazayeri, Saptarshi Purkayastha, Suranga Kasthurirathne
Hey Wyclif,

Yeas, the servelet is hitting. As I mentioned earlier, I have confirm it with extending provided servelet with my own servelet and debuging it. 

Thanks,
Harsha

Wyclif Luyima

unread,
Apr 8, 2015, 11:27:26 AM4/8/15
to Harsha Kumara, d...@openmrs.org, Darius Jazayeri, Saptarshi Purkayastha, Suranga Kasthurirathne
Can you share your code?

Wyclif

Harsha Kumara

unread,
Apr 8, 2015, 12:04:29 PM4/8/15
to Wyclif Luyima, d...@openmrs.org, Darius Jazayeri, Saptarshi Purkayastha, Suranga Kasthurirathne
Hi Wyclif,

Please find code in branch[1]. I have follow the approach suggested in [2].


Thanks,
Harsha

Wyclif Luyima

unread,
Apr 8, 2015, 1:10:02 PM4/8/15
to Harsha Kumara, d...@openmrs.org, Darius Jazayeri, Saptarshi Purkayastha, Suranga Kasthurirathne
Hi Harsha,

I just talked with Suranga and this is what i imagine might be going wrong. Those swagger servlets you are configuring are written in a standard way and you expect them to be called in a standard way by the container but their is a variation in how openmrs module servlets instances are constructed and get called, therefore there are certain things that don't work e.g calls to  getInitParameter() and getInitParameterNames() are not supported as of now in our custom implementation of  ServletConfig class for modules which means all those init params you are defining in the module are not getting picked, this is why it works when you register things in web.xml and fail when you define them in the config.xml file.

One possible solution would be to subclass those swagger servlet classes, override getInitParameter(String) and getInitParameterNames() methods, and read in those values as constants, see if that solves the problem.

I have created TRUNK-4673 to add support for module servlet init paramaters.

Wyclif

Harsha Kumara

unread,
Apr 9, 2015, 11:32:46 PM4/9/15
to Wyclif Luyima, d...@openmrs.org, Darius Jazayeri, Saptarshi Purkayastha, Suranga Kasthurirathne
Hi Wyclif,

I tried to override the init parameters from many ways and couldn't do that. Actually parameters are read in the init method of DefaultServletReaderConfig. There WebXMLReader webConfig = new WebXMLReader(servletConfig). But the problem is it's not public.I could have take the source of the servelet and done the same. But the problem is that code was written in Scala. 

So I might not have any option here :(

Thanks,
Harsha


Suranga Kasthurirathne

unread,
Apr 10, 2015, 10:27:55 AM4/10/15
to Harsha Kumara, Wyclif Luyima, d...@openmrs.org, Darius Jazayeri, Saptarshi Purkayastha

Yikes.

It seems that our efforts to get this running using the (pretty) swagger version is failing. Given that we're failing at getting this up, I think we should fall back on a sketchier (but working) front end using plan old JSP.
A better swagger based UI can happen later, perhaps as part of GSoC 2016 ?
--
Best Regards,
Suranga

Wyclif Luyima

unread,
Apr 10, 2015, 11:26:53 AM4/10/15
to Suranga Kasthurirathne, Harsha Kumara, d...@openmrs.org, Darius Jazayeri, Saptarshi Purkayastha
Hi Harsha,

I doubt if we are on the same page, i meant  init params are not read in for module servlets in OpenMRS, so they can't be working and that is for sure one primary reason your code fails when you put then in the config.xml file, can you try to run the module of master when you have implemented the getInitParameter..() methods in ModuleServlet class and see what happens? Can't you decompile the java class that was generated from the scala code? So you can look a the code


Wyclif

Lluis Martinez

unread,
Apr 10, 2015, 11:30:03 AM4/10/15
to d...@openmrs.org
Does this mean that if we try to use Swagger in REST WS it will fail too ? 

--
OpenMRS Developers: http://om.rs/dev
Post: d...@openmrs.org | Unsubscribe: dev+uns...@openmrs.org
Manage your OpenMRS subscriptions: http://om.rs/id
 
*** FINAL WARNING: This group will be moved to OpenMRS Talk effective 10 April 2015 at 19:00 UTC. Please visit https://talk.openmrs.org/t/openmrs-developers-group-changes-2015-04-10/1508 for details and to make necessary changes.

To unsubscribe from this group and stop receiving emails from it, send an email to dev+uns...@openmrs.org.

Suranga Kasthurirathne

unread,
Apr 10, 2015, 11:30:13 AM4/10/15
to Wyclif Luyima, Harsha Kumara, d...@openmrs.org, Darius Jazayeri, Saptarshi Purkayastha

Hmm.... @wyclif, we do want our module to support 1.9.8, at least. At what stage was getInitParameter..() implemented?
For production purposes, we do need to support versions earlier than 1.12
--
Best Regards,
Suranga

Darius Jazayeri

unread,
Apr 10, 2015, 11:36:19 AM4/10/15
to Suranga Kasthurirathne, Wyclif Luyima, Harsha Kumara, d...@openmrs.org, Saptarshi Purkayastha
Is it possible to define a real servlet from a module via spring or web.xml, and not just a module servlet?

-Darius

Harsha Kumara

unread,
Apr 10, 2015, 2:13:32 PM4/10/15
to Wyclif Luyima, Suranga Kasthurirathne, d...@openmrs.org, Darius Jazayeri, Saptarshi Purkayastha
Hi Wyclif,

I did decompile and saw the code. Please refer [1]. There you can following line in init method. That is the place where it read the params, Content of the class is in [2]. 
        WebXMLReader webConfig = new WebXMLReader(servletConfig);

Got your point and If so I need to implement the getInitParameter in the ModuleServlet and check. I just checked it with 1.9.8 with modified getInitParameter method. But it still gives a blank page. :(. I confirmed that method is getInitParameter in ModuleServelet is calling at server start. But when I request for the servelet, it's still giving blank page.

@Darius, Previously I checked defining the servelet in web.xml and it worked. :). But I'm not sure whether swagger annotations which uses to describe the API will work. Because we need to give the package of servelets which reside the api through servelet init parameter. Even if it worked, defining module packages in web.xml can't be done as it add dependency from openmrs core to a module. For WebService rest module, I think we no need of using swagger servelet based approach instead we can focus on [3] which specify how swagger can integrate with Spring MVC.

AFAIR to use swagger with Spring annotated APIs which use request mapping annotation, the spring version must be 3.2.5 or above. :).  
 

Thanks,
Harsha

Reply all
Reply to author
Forward
0 new messages