Message Boards

Remote service builder in Liferay 7.3

Daniel G, modified 2 Years ago.

Remote service builder in Liferay 7.3

Regular Member Posts: 141 Join Date: 3/14/17 Recent Posts

Hi all,

I am trying to create a remote service builder. I was trying to create and deploy it, but once I try to access from /api/jsonws  I receive this error:

Current URL /api/jsonws?contextName=studentname&signature=%2Fstudent.student%2Fget-student-by-id-1-long generates exception: null
java.lang.IllegalArgumentException
        at jodd.asm5.ClassReader.<init>(ClassReader.java:170)
        at jodd.asm5.ClassReader.<init>(ClassReader.java:153)
        at jodd.asm5.ClassReader.<init>(ClassReader.java:424)
        at jodd.paramo.Paramo.resolveParameters(Paramo.java:59)
        at com.liferay.portal.util.MethodParametersResolverImpl.resolveMethodParameters(MethodParametersResolverImpl.java:49)
        at com.liferay.portal.kernel.util.MethodParametersResolverUtil.resolveMethodParameters(MethodParametersResolverUtil.java:29)
        at com.liferay.portal.jsonwebservice.JSONWebServiceActionConfig.getMethodParameters(JSONWebServiceActionConfig.java:185)
        at org.apache.jsp.html.portal.api.jsonws.action_jsp._jspService(action_jsp.java:871)
        at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:71)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:733)
        at com.liferay.portal.servlet.DirectRequestDispatcher.include(DirectRequestDispatcher.java:64)
        at com.liferay.portal.servlet.DirectRequestDispatcherFactoryImpl$IndirectRequestDispatcher.include(DirectRequestDispatcherFactoryImpl.java:190)
        at com.liferay.portal.servlet.ClassLoaderRequestDispatcherWrapper.doDispatch(ClassLoaderRequestDispatcherWrapper.java:79)
        at com.liferay.portal.servlet.ClassLoaderRequestDispatcherWrapper.include(ClassLoaderRequestDispatcherWrapper.java:53)
        at com.liferay.taglib.util.IncludeTag.includePage(IncludeTag.java:407)
        at com.liferay.taglib.util.IncludeTag.include(IncludeTag.java:383)
        at com.liferay.taglib.util.IncludeTag.doInclude(IncludeTag.java:217)
        at com.liferay.taglib.util.IncludeTag.doEndTag(IncludeTag.java:88)
        at org.apache.jsp.html.portal.api.jsonws.index_jsp._jspx_meth_liferay_002dutil_005finclude_005f1(index_jsp.java:1065)
        at org.apache.jsp.html.portal.api.jsonws.index_jsp._jspService(index_jsp.java:966)

This is my service.xml

<?xml version="1.0"?>
<!DOCTYPE service-builder PUBLIC "-//Liferay//DTD Service Builder 7.3.0//EN" "http://www.liferay.com/dtd/liferay-service-builder_7_3_0.dtd">

<service-builder dependency-injector="ds" package-path="remote.portlet">
	<namespace>student</namespace>
    <entity name="Student" local-service="true">
        <column name="studentId" type="long" primary="true"></column>
        <column name="name" type="String"></column>
    </entity>
</service-builder>

 

and this is the method:

@Component(
	property = {
		"json.web.service.context.name=student",
		"json.web.service.context.path=student"
	},
	service = AopService.class
)
public class StudentServiceImpl extends StudentServiceBaseImpl {

    @JSONWebService( method = "POST")
	@Override
	public Student getStudentById(long id) {
		try {
			return studentLocalService.getStudent(id);
		} catch (PortalException e) {
			// TODO Auto-generated catch block
			return null;
		}
	}
	
}

 

If I try to call it from javascript console, or from a method, I see this error:

ERROR [http-nio-8080-exec-10][JSONWebServiceServiceAction:126] java.lang.IllegalArgumentException

 

Does anyone has any idea what I'm doing wrong? I've tried to make the simplest service but I can't make it work

 

Thanks in advance! Any help would be very appreciated

 

Regards

Mirko Romstadt, modified 2 Years ago.

RE: Remote service builder in Liferay 7.3

New Member Posts: 17 Join Date: 7/23/14 Recent Posts

Why do you make this a POST request and not a GET request?

Daniel G, modified 2 Years ago.

RE: Remote service builder in Liferay 7.3

Regular Member Posts: 141 Join Date: 3/14/17 Recent Posts

Hi,

 

First of all, thanks for your answer.

I tried to make a get request, but when it didn't work, I tried with a post request but it didn't work neither

I've investigated more and the issue is with the parameter of the function. If I make a function with no parameters it works fine. If I add a parameter like the long one, it fails.
 

Reagrds

Mirko Romstadt, modified 2 Years ago.

RE: RE: Remote service builder in Liferay 7.3

New Member Posts: 17 Join Date: 7/23/14 Recent Posts

So you get the same error message for a GET request? What do you get if you try to do the call in e.g. Postman for /api/jsonws/student.student/get-student-by-id-1-long/1234 ?

Daniel G, modified 2 Years ago.

RE: RE: Remote service builder in Liferay 7.3

Regular Member Posts: 141 Join Date: 3/14/17 Recent Posts

Hi,

 

Yes, I've got a error 500. I was investigating and I think that is due to jdk11 compatiblity. I've tried to add this:

tasks.withType(JavaCompile) {

	// Generated classes using Jodd library are unable to be read when compiled against JDK 11

	sourceCompatibility = JavaVersion.VERSION_1_8
	targetCompatibility = JavaVersion.VERSION_1_8
}

but I can't compile due to this error

 

Could not determine the dependencies of task ':modules:ServiceTest:ServiceTest-service:jar'.
> Could not resolve all task dependencies for configuration ':modules:ServiceTest:ServiceTest-service:compileClasspath'.
   > Could not resolve project :modules:ServiceTest:ServiceTest-api.
     Required by:
         project :modules:ServiceTest:ServiceTest-service
      > No matching variant of project :modules:ServiceTest:ServiceTest-api was found. The consumer was configured to find an API of a library compatible with Java 8, preferably in the form of class files, and its dependencies declared externally but:
          - Variant 'apiElements' capability Eulen_7_3_workspace.modules.ServiceTest:ServiceTest-api:1.0.0 declares an API of a library, packaged as a jar, and its dependencies declared externally:
              - Incompatible because this component declares a component compatible with Java 11 and the consumer needed a component compatible with Java 8
          - Variant 'runtimeElements' capability Eulen_7_3_workspace.modules.ServiceTest:ServiceTest-api:1.0.0 declares a runtime of a library, packaged as a jar, and its dependencies declared externally:
              - Incompatible because this component declares a component compatible with Java 11 and the consumer needed a component compatible with Java 8

Thanks again!

Regards

Purvesh Kachhiya, modified 2 Years ago.

RE: Remote service builder in Liferay 7.3

New Member Posts: 3 Join Date: 3/28/20 Recent Posts

Hello,

Need to add remote-service attribute to true for an entity.

<entity name="Student" local-service="true" remote-service="true" >
        <column name="studentId" type="long" primary="true"></column>
        <column name="name" type="String"></column>
    </entity>