Hi
In this tutorial I will discuss how to expose liferay web services
Here I am using sql server
portal-ext.properties file
jdbc.default.driverClassName=net.sourceforge.jtds.jdbc.Driver
jdbc.default.url=jdbc:jtds:sqlserver://localhost/spadnew
jdbc.default.username=sa
jdbc.default.password=root
In this tutorial I will discuss how to expose liferay web services
Here I am using sql server
portal-ext.properties file
jdbc.default.driverClassName=net.sourceforge.jtds.jdbc.Driver
jdbc.default.url=jdbc:jtds:sqlserver://localhost/spadnew
jdbc.default.username=sa
jdbc.default.password=root
To access JSON web services Using IP address add the below configuration in portal-ext.properties
---------------------------------------
auth.token.check.enabled=false
json.service.auth.token.enabled=false
axis.servlet.hosts.allowed=192.168.3.12, 127.0.0.1, SERVER_IP
Add the below jar file in TOMCAT_SERVER}/lib/ext)
cors-filter-1.3.2.jar
java-property-utils-1.7.1
After that, you have to restart your Tomcat Server instance.
These are the configuration for access web service
we have to also add some content to our web.xml
Here we have two web.xml
one is visible inside our project in eclipse
and the path of this is
WorkSpace\liferay-portal-6.2-ee-sp14\tomcat-7.0.62\webapps\gallery-portlet\WEB-INF\web.xml
We have another web.xml which is created by exlipse (may be)
F:\LiferayWorkSpaces\WorkSpace\liferay-portal-6.2-ce-ga2\tomcat-7.0.42\webapps\ROOT\WEB-INF\web.xml
content that we have to paste inside web.xml is
If you want to use Liferay RestFull API through AJAX calls (or jQuery JSon calls).
You have to set Cors Filter in web.xml of Liferay ROOT on the server.
This is the code for web.xml
<!-- CorsFilter per call Rest API in AJAX/jQuery-->
<filter>
<filter-name>CORS</filter-name>
<filter-class>com.thetransactioncompany.cors.CORSFilter</filter-class>
<init-param>
<param-name>cors.allowOrigin</param-name>
<param-value>*</param-value>
</init-param>
<init-param>
<param-name>cors.supportedMethods</param-name>
<param-value>GET, POST, HEAD, PUT, DELETE</param-value>
</init-param>
<init-param>
<param-name>cors.supportedHeaders</param-name>
<param-value>Accept, Origin, X-Requested-With, Content-Type,
Last-Modified, Access-Control-Request-Method, Access-Control-Request-Headers</param-value>
</init-param>
<init-param>
<param-name>cors.exposedHeaders</param-name>
<param-value>Set-Cookie</param-value>
</init-param>
<init-param>
<param-name>cors.supportsCredentials</param-name>
<param-value>true</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>CORS</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
Than, you have to import in ${TOMCAT_SERVER}/lib/ (or better ${TOMCAT_SERVER}/lib/ext) this two jars:
cors-filter-1.3.2.jar
java-property-utils-1.6.jar
After that, you have to restart your Tomcat Server instance.
If we want to access through url without sign in then it throws error
to avoid this error we have to give some annotation to our method
Suppose we have an entity Complaints
so we have to write our method that is exposed by liferay is
ComplaintsSeviceImpl.java
@AccessControlled(guestAccessEnabled=true)
@JSONWebService(value = "getOpenAndClosedComp", method = "GET")
public JSONObject getOpenAndClosedComp()
throws SystemException {
}
hit url : http://10.35.115.177:8080/api/jsonws
from context path drop down we have to select our portlet
then it will display list of methods that we created in our impl class.
In this case our method name is "getOpenAndClosedComp"
No comments:
Post a Comment