Exposing soap web service for a custom plugin
STEPS:
Step 1: Create one portlet plugin project, name: SoapExposer, after appending suffix of portlet plugin project full name of project will be SoapExposer-portlet.
Create one portlet name: Exposer, inside created project.
STEPS:
Step 1: Create one portlet plugin project, name: SoapExposer, after appending suffix of portlet plugin project full name of project will be SoapExposer-portlet.
Create one portlet name: Exposer, inside created project.
Step 2:Create service.xml,define entity as shown in below screen.
In service defintion don't forget to make remote-service="true",
Once we make remote-service="true" in service.xml and after building service we will get EmployeeManageServiceImpl.java
Now build service.
Step 3: Paste below code in view.jsp
<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %>
<%@page import="javax.portlet.PortletURL"%>
<portlet:defineObjects />
<p style="border:1px solid green;">ADD Employee Details</p>
<%
PortletURL addEmployeeDetailURL = renderResponse.createActionURL();
addEmployeeDetailURL.setParameter(actionRequest.ACTION_NAME,"addEmployeeDetail");
%>
<form action="<%=addEmployeeDetailURL.toString()%>" method="POST">
<b>Employee First Name</b><br/>
<input type="text" name="<portlet:namespace/>employeeFirstName" /><br/>
<b>Employee Last Name</b><br/>
<input type="text" name="<portlet:namespace/>employeeLastName" /><br/>
<b>Employee Age</b><br/>
<input type="text" name="<portlet:namespace/>employeeAge" /><br/>
<b>Employee Number</b><br/>
<input type="text" name="<portlet:namespace/>employeeNumber" /><br/>
<br/>
<input type="submit" value="AddEmployeeDetails"/>
</form>
Step 4: Paste below code in portlet controller: Exposer.java
package com.test;
import java.io.IOException;
import javax.portlet.ActionRequest;
import javax.portlet.ActionResponse;
import javax.portlet.PortletException;
import com.liferay.counter.service.CounterLocalServiceUtil;
import com.liferay.portal.kernel.exception.SystemException;
import com.liferay.portal.kernel.util.ParamUtil;
import com.liferay.util.bridges.mvc.MVCPortlet;
import com.slayer.model.EmployeeManage;
import com.slayer.model.impl.EmployeeManageImpl;
import com.slayer.service.EmployeeManageLocalServiceUtil;
/**
* Portlet implementation class Exposer
*/
public class Exposer extends MVCPortlet {
//Adding employee details
public void addEmployeeDetail(ActionRequest actionRequest,
ActionResponse actionResponse) throws IOException, PortletException {
System.out.println("inside addEmployeeDetail method...");
String employeeFirstName = ParamUtil.getString(actionRequest, "employeeFirstName");
String employeeLastName = ParamUtil.getString(actionRequest, "employeeLastName");
int employeeAge = ParamUtil.getInteger(actionRequest, "employeeAge");
String employeeNumber = ParamUtil.getString(actionRequest, "employeeNumber");
//Instanciate an empty object of type EmployeeManageImpl
EmployeeManage employeeManage = new EmployeeManageImpl();
//Generate a unique primary key to be set
long employeeId = 01;
try {
employeeId = CounterLocalServiceUtil.increment();
} catch (SystemException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
//set the field for this object
employeeManage.setEmployeeId(employeeId);
employeeManage.setEmpFirstName(employeeFirstName);
employeeManage.setEmpLastName(employeeLastName);
employeeManage.setEmpAge(employeeAge);
employeeManage.setEmpNumber(employeeNumber);
//called service layer API to save the object
try {
EmployeeManageLocalServiceUtil.addEmployeeManage(employeeManage);
System.out.println("New employee detail added successfully...");
actionResponse.setRenderParameter("jspPage", "/html/exposer/view.jsp");
} catch (SystemException e) {
System.out.println("something happened wrong while adding new employee detail");
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
Step 5: Paste below java code in EmployeeManageServiceImpl.java and then build service once again.
/**
* Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
*
* This library is free software; you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by the Free
* Software Foundation; either version 2.1 of the License, or (at your option)
* any later version.
*
* This library is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
* details.
*/
package com.slayer.service.impl;
import java.util.List;
import com.liferay.portal.kernel.exception.PortalException;
import com.liferay.portal.kernel.exception.SystemException;
import com.slayer.model.EmployeeManage;
import com.slayer.service.EmployeeManageLocalService;
import com.slayer.service.EmployeeManageLocalServiceUtil;
import com.slayer.service.base.EmployeeManageServiceBaseImpl;
/**
* The implementation of the employee manage remote service.
*
* <p>
* All custom service methods should be put in this class. Whenever methods are added, rerun ServiceBuilder to copy their definitions into the {@link com.slayer.service.EmployeeManageService} interface.
*
* <p>
* This is a remote service. Methods of this service are expected to have security checks based on the propagated JAAS credentials because this service can be accessed remotely.
* </p>
*
* @author samsun
* @see com.slayer.service.base.EmployeeManageServiceBaseImpl
* @see com.slayer.service.EmployeeManageServiceUtil
*/
public class EmployeeManageServiceImpl extends EmployeeManageServiceBaseImpl {
/*
* NOTE FOR DEVELOPERS:
*
* Never reference this interface directly. Always use {@link com.slayer.service.EmployeeManageServiceUtil} to access the employee manage remote service.
*/
public List<EmployeeManage> getlistOfEmployee()
{
List<EmployeeManage> employeeList = null;
try {
employeeList = employeeManageLocalService.getEmployeeManages(-1, -1);
} catch (SystemException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return employeeList;
}
public EmployeeManage getEmployeeDetailBasedOnEmpId(long employeeId){
EmployeeManage employeeDetails = null;
try {
employeeDetails = employeeManageLocalService.getEmployeeManage(employeeId);
} catch (PortalException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SystemException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return employeeDetails;
}
}
Step 6: Now by using build wsdd we will expose this service to outside world. By doing this a new file 'server-config.wsdd' will get generate inside WEB-INF. This is the web service deployment descriptor that contains information about the web services that we are exposing.
Follow below screen.
Step 7: Now deploy portlet and add on portal page for adding employee data.
As shown in below screen.
As shown in below screen.
Step 8: hit below url on browser, follow below screen http://localhost:8080/SoapExposer-portlet/api/axis
Below is the soap wsdl generated file.
0 comments:
Post a Comment