Sunday 19 June 2016

Expose liferay web services

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


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"
   

Sunday 12 June 2016

SQL Server management studio login

Here I am describing first how to install sql server and then connect with liferay.
I am using
Liferay 6.2 EE
Microsoft SQL Server Management Studio 2012
Windows 8
Here I am facing problem to first install and then login as a "sa" user.
So first install SQLEXPR_x64_ENU
then we install SQLManagementStudio_x64_ENU
I tried to search from windows + s
SQL SERVER but not getting any result.
It is installed but not visible in search.
You have to search it by pressing windows button like





then



Once you select it then visible to search in windows 8.
First open
SQL SERVER configuration manager.
then in
Sql Server Network Configuration -> protocols for SQLEXPRESS
Enable all protocols

Please restart sql service.
By closing sql server management studio window or Sql Server Configuration Manager windows doesn't stop service.
For start and stop service windows + r (run command) write services.msc
and then can restart SQL Server (SQLEXPRESS).

Now open sql server management studio
After connect SQL Server using Windows Authentication mode
Follow these steps




Then ok

Simply change the password and then login through sql server authentication.
For changing password you will get number of tutorial in net.
You will also get this from net but it was difficult for me to find out this.
After that to connect with liferay please follow this link.
Click here