Liferay provides JAX web services implementation using Apache CXF. There are two types of web services Liferay supports. 1) JAX-WS 2) JAX-RS.
Here I am going to explain JAX-WS in Liferay 7/DXP.
There are basically two things you need to understand to create JAX web services in Liferay.
1.CXF Endpoints
- CXF Endpoints are context paths where JAX web services are deployed. E.g you can define CXF endpoints /soap and then you can create extender which deploy web services to this context path.
2.Extenders
- Extender is used to deploy web services to specified CXF endpoints. For example, If you define /soap endpoint while creating extender then all the web services registered with this extender will be available at /soap endpoint.
There are two types of extender : SOAP Extenders and REST Extenders. SOAP Extenders are used to publish JAX-WS web services and REST Extenders are used to publish JAX-RS web services.
You can define CXF endpoints and extenders from control panel or programmatically. Here I am going to show you programmatically.
First create module project of service type in your IDE.
Add Configuration Path :
Add following configuration attributes in bnd.bnd file.
configurationPath: /configuration
Include-Resource: configuration=src/main/resources/configuration
src/main/resources/configuration
is path where you will define configuration for endpoints and extenders.
Configure CXF Endpoints :
Create a file com.liferay.portal.remote.cxf.common.configuration.CXFEndpointPublisherConfiguration-cxf
in configuration folder.
Here I am going to define /soap context path as following.
contextPath=/soap
authVerifierProperties=auth.verifier.PortalSessionAuthVerifier.urls.includes=*
AuthVerifier properties: Any properties defined here are passed as-is to the AuthVerifier filter. See the AuthVerifier documentation for more details.
Configure SOAP Extender :
Create a file com.liferay.portal.remote.soap.extender.configuration.SoapExtenderConfiguration-soap
in configuration folder.
Define extender which will deploy web services to /soap context path.
contextPaths=/soap
jaxWsServiceFilterStrings=(component.name={{jax-ws service class}})
Create JAX-WS service class:
package com.st.liferay7.jaxws.calculatorservice;
import javax.jws.WebMethod;
import javax.jws.WebService;
import org.osgi.service.component.annotations.Component;
@Component(
immediate = true,
property = "jaxws=true",
service = Calculator.class
)
@WebService
public class Calculator {
@WebMethod
public int divide(int a, int b) {
return a / b;
}
@WebMethod
public int multiply(int a, int b) {
return a * b;
}
@WebMethod
public int subtract(int a, int b) {
return a - b;
}
@WebMethod
public int sum(int a, int b) {
return a + b;
}
}
To publish JAX-WS web services via SOAP in a Liferay Portal CE 7.0 module, annotate the class and its methods with standard JAX-WS annotations. For example, the above class uses the @WebService
annotation for the class and @WebMethod
annotations for its methods. You must also set the jaxws property to true in the OSGi @Component annotation.
Deploy module on your Liferay server. If module is configured and deployed properly you can see cxf endpoint and soap extender created from Control Panel > Configuration > System Settings
You can see all the web services from /o/{{cxfendpoints}}
path. Here try /o/soap
, it will show list of web services registered for /soap context path.
That’s
Download :
soap calculator service(jar)