I followed the guide found here:
https://github.com/wordnik/swagger-core/wiki/Java-JAXRS-Quickstart
Here is my POM:
<!-- SWAGGER -->
<dependency>
<groupId>com.wordnik</groupId>
<artifactId>swagger-jersey-jaxrs_2.10</artifactId>
<version>1.3.0</version>
</dependency>
The Annotations are found fine, so i am assuming the POM is working OK
For WEB.xml, I tried doing multiple things, following the guide:
<servlet>
<servlet-name>jersey-serlvet</servlet-name>
<servlet-class>
com.sun.jersey.spi.spring.container.servlet.SpringServlet
</servlet-class>
<init-param>
<param-name>com.sun.jersey.config.property.packages</param-name>
<param-value>com.thomsonreuters.ips.service;com.wordnik.swagger.jersey.listing</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>jersey-serlvet</servlet-name>
<url-pattern>/service/*</url-pattern>
</servlet-mapping>
<!-- SWAGGER serverlet? -->
<servlet>
<servlet-name>JerseyJaxrsConfig</servlet-name>
<servlet-class>com.wordnik.swagger.jersey.config.JerseyJaxrsConfig</servlet-class>
<init-param>
<param-name>api.version</param-name>
<param-value>1.0.0</param-value>
</init-param>
<init-param>
<param-name>swagger.api.basepath</param-name>
<param-value>http://localhost:8080/{PROJECTNAME}</param-value>
</init-param>
<load-on-startup>2</load-on-startup>
</servlet>
but this throws a wild error when i try to reach:
localhost:8080/{PROJECTNAME}/service/api-docs
HTTP Status 500 - java.lang.NoSuchMethodError: com.wordnik.swagger.annotations.ApiOperation.authorizations()Ljava/lang/String;
next I saw around the googleverse to modify the web.xml to the following:
<servlet>
<servlet-name>jersey-serlvet</servlet-name>
<servlet-class>
com.sun.jersey.spi.spring.container.servlet.SpringServlet
</servlet-class>
<init-param>
<param-name>api.version</param-name>
<param-value>2.0</param-value>
</init-param>
<init-param>
<param-name>com.sun.jersey.config.property.packages</param-name>
<param-value>com.thomsonreuters.ips.service;com.wordnik.swagger.jaxrs;</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>jersey-serlvet</servlet-name>
<url-pattern>/service/*</url-pattern>
</servlet-mapping>
note the api.version and the new jaxrs init param.
when that happens, and i go to
http://localhost:8080/ScholarlyItemService/service/api-docs
i get no errors, but i do get useless webpage:
{"apiVersion":"0.0","swaggerVersion":"1.2"}
I think you almost have it. What you see is not a useless webpage, it's rather the documentation of your service built by swagger as a json document. You have to annotate your code as shown in the Quickstart guide. This should show up in this document.
What you may actually want is the Swagger UI: http://swagger.wordnik.com/ to see this document in a readable way.
It took me a moment, but I got it running. You have to download from here: https://github.com/wordnik/swagger-ui, and copy the contents from the dist folder to your /webapp folder. You can then open the contained index.html in a browser. In my case, I could not access this document directly, so I had to put the dist' contents in a subfolder (e.g. /docs) and exclude this from my servlet mapping in web.xml as described here: http://blog.ericdaugherty.com/2010/02/excluding-content-from-url-pattern-in.html.
In the index.html change the url: "http://petstore.swagger.wordnik.com/api/api-docs",
part to your api endpoint http://localhost:8080/ScholarlyItemService/service/api-docs and you will get your api documentation when calling http://localhost:8080/ScholarlyItemService/docs/index.html
Related
I have a webservlet with Jersey rest API configured. Now I have to convert the servlet to a liferay portlet. How to convert? Like what portlet-class should I specify in my portlet.xml? The below is the web.xml of my servlet.
<servlet>
<servlet-name>charts</servlet-name>
<!--<servlet-class>javax.servlet.http.HttpServlet</servlet-class>-->
<servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>com.sun.jersey.config.property.packages</param-name>
<param-value>com.charts.api.service</param-value>
</init-param>
<init-param>
<param-name>com.sun.jersey.api.json.POJOMappingFeature</param-name>
<param-value>true</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>charts</servlet-name>
<url-pattern>/charts</url-pattern>
<url-pattern>/charts/*</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
How to configure my portlet.xml and use rest service with my portal? I have to deploy the portlet in liferay jboss server as well.
Why don't you use a delegate servlet in liferay?
You can create a liferay portlet and in web.xml define your delegate servlet.
Here you've got a definition example:
<servlet>
<servlet-name>buscador</servlet-name>
<servlet-class>com.liferay.portal.kernel.servlet.PortalDelegateServlet</servlet-class>
<init-param>
<param-name>servlet-class</param-name>
<param-value>com.dummy.servlet.BuscadorServlet</param-value>
</init-param>
<init-param>
<param-name>sub-context</param-name>
<param-value>buscador</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
It will listens on http://yourliferay/delegate/buscador
Hope it helps
I'm using Jersey for restful service deserialization and in the web.xml file it is declared that i must declare the package name where my resources will be. so it ends up looking like this in web.xml:
<servlet>
<servlet-name>Jersey REST Service</servlet-name>
<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
<!-- Register resources and providers under com.vogella.jersey.first package. -->
<init-param>
<param-name>jersey.config.server.provider.packages</param-name>
<!-- this is my package name where my jersey resources are kept -->
<param-value>com.vogella.web.resources</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Jersey REST Service</servlet-name>
<url-pattern>/rest/*</url-pattern>
</servlet-mapping>
now onto my question, what if i wanted to have jersey resources in other packages, could i create another web.xml file or how is it done ?
The packages can be comma separated list.
<init-param>
<param-name>jersey.config.server.provider.packages</param-name>
<!-- this is my package name where my jersey resources are kept -->
<param-value>com.vogella.web.resources, com.vogella.web.resources1</param-value>
</init-param>
I have setup my application like this using jetty
Web.xml
<servlet>
<servlet-name>GoogleProxy</servlet-name>
<servlet-class>org.mortbay.proxy.AsyncProxyServlet$Transparent</servlet-class>
<load-on-startup>1</load-on-startup>
<init-param>
<param-name>ProxyTo</param-name><param-value>http://www.google.com</param-value>
</init-param>
<init-param>
<param-name>Prefix</param-name><param-value>/google</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>GoogleProxy</servlet-name>
<url-pattern>/google/*</url-pattern>
</servlet-mapping>
However when I access my app (The url is like this localhost:8080/myapp/google/images) it returns an error 403. I am using jetty 6.1.13
I am learning Servlets.
In web.xml of an application, I found the following Servlet code.
Can somebody please explain me the significance of the code
<servlet id="Servlet_1060120206078">
<servlet-name>action</servlet-name>
<servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
<init-param id="InitParam_1060120206077">
<param-name>config</param-name>
<param-value>/WEB-INF/struts-config.xml</param-value>
</init-param>
<init-param id="InitParam_1060120206076">
<param-name>debug</param-name>
<param-value>2</param-value>
</init-param>
<init-param id="InitParam_1069371544495">
<param-name>detail</param-name>
<param-value>2</param-value>
</init-param>
<init-param id="InitParam_1069371544496">
<param-name>validate</param-name>
<param-value>true</param-value>
</init-param>
<load-on-startup>2</load-on-startup>
</servlet>
Thanks
Nirmalya
This is just defining a servlet (in this case a FrontController for Struts) that is used to handle requests. Later on in the file I'm sure you'll also find a servlet mapping that maps this servlet to http requests.
The <init-param> elements are key/value pairs that the servlet can read on startup. Struts uses these for configuration.
All the InitParam_XXX stuff is un-necessary, my guess is that it was machine generated by some editor.
Check this out for more details:
http://netbeans.org/kb/docs/web/quickstart-webapps-struts.html
Any of you guys have enabled SSI (ServerSide Includes) in JBoss? I guess it should be not difficult as it is built on top of a Tomcat instance.
Tomcat already includes in catalina.jar the org.apache.catalina.ssi.SSIServlet so just declare the servlet and attach it to a mapping URL, by setting this in the applications web.xml
<servlet>
<servlet-name>ssi</servlet-name>
<servlet-class>
org.apache.catalina.ssi.SSIServlet
</servlet-class>
<init-param>
<param-name>buffered</param-name>
<param-value>1</param-value>
</init-param>
<init-param>
<param-name>debug</param-name>
<param-value>0</param-value>
</init-param>
<init-param>
<param-name>expires</param-name>
<param-value>60</param-value>
</init-param>
<init-param>
<param-name>isVirtualWebappRelative</param-name>
<param-value>1</param-value>
</init-param>
<load-on-startup>4</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>ssi</servlet-name>
<url-pattern>*.shtml</url-pattern>
</servlet-mapping>
I put all the parameters, you can see their definition in this Tomcat SSI reference.
As the doc says, SSI can bypass security policies so it must be privileged, do this changing the context.xml located in jboss-web.deploy inside the deploy folder. Just add privileged="true" to the root element.
<Context ... privileged="true">
The servlet will just act as a proxy for the files matching the URL of its mapping.