MarioProject
MarioProject

Reputation: 427

Liferay Json Web Service Parameters input

I user Liferay 6.2 I create an Entity (notizia) with Service Builder.

I generated Web Services. I have a method to print a string like this:

public class notiziaServiceImpl extends notiziaServiceBaseImpl {

    @Override
    @AccessControlled(guestAccessEnabled=true)
    public String printMyString()
    {
        return "i'm the string ";
    }
}

It works! I added another method with an input parameter

@AccessControlled(guestAccessEnabled=true)  
    public String getHelloWorld(String worldName) 
                    throws com.liferay.portal.kernel.exception.PortalException,
                    com.liferay.portal.kernel.exception.SystemException {
        return "Hello world: " + worldName;
    }

"getHelloWorld" method not work. I got this error in console:

[MethodParametersResolverImpl:59] java.lang.IllegalArgumentException
java.lang.IllegalArgumentException

I don't know what i miss. How can i solve it?

Upvotes: 2

Views: 738

Answers (3)

evaldeslacasa
evaldeslacasa

Reputation: 603

Thanks for that answer @Dhruv Pandey! you saved my day (or days).

By the way, I want to point out that even if in the Jodd's link you posted they say: "Jodd may be used on any platform where there is a suitable Java 8 runtime environment." that doesn't mean we can't use it in, for example, a server running on Java 11.

What's important here is that the artifact we deploy has the target runtime environment set as Java 8, otherwise we'll get the exception.

So I'm running a Liferay 7.2 instance in Java 11, and had this configuration in the build plugin of my service pom.xml:

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.8.1</version>
            <configuration>
                <source>1.8</source>
                <target>11</target>
            </configuration>
        </plugin>
        ...
    </plugins>
<build>

This was throwing the error. What I did, is changed the configuration to the following:

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.8.1</version>
            <configuration>
                <source>1.8</source>
                <target>1.8</target>
            </configuration>
        </plugin>
        ...
    </plugins>
<build>

After that, the error was gone.

Upvotes: 1

Dhruv Pandey
Dhruv Pandey

Reputation: 514

This is somehow related to Java version. Try using Java8 for building and deploying your services. It worked for me after 2 days of research.

What I think issue is Liferay is using  jodd.asm5 (Check first line of your exception trace) and I checked Jodd site https://jodd.org/download/ and they are not supporting it after Java 8. Not sure how Liferay is using that.

Upvotes: 1

dnebing
dnebing

Reputation: 355

When you add a new method to your XxxServiceImpl class, you always have to rebuild services.

ServiceBuilder injects the right stuff into the parent class, etc to ensure that the method is registered and available for remote API calls.

Upvotes: 1

Related Questions