robotframework / jrobotremoteserver

Serves remote test libraries for Robot Framework that are implemented in Java.
Apache License 2.0
43 stars 33 forks source link

Unknow 'Remote' library under 'http://localhost:8271' location. Unable to connect. #48

Closed nlamblin closed 2 years ago

nlamblin commented 4 years ago

I'm trying to implement JavaLibCore and RemoteServer to use Java method in robotframework as keywords.

Could you please help me to find a way to fix below error? Thank you a lot.

Java code

Keyword class

package keywords;
import org.robotframework.javalib.annotation.ArgumentNames;
import org.robotframework.javalib.annotation.RobotKeyword;
import org.robotframework.javalib.annotation.RobotKeywords;

@RobotKeywords
public class MyKeyword {

    @RobotKeyword("Print Message")
    @ArgumentNames({"message"})
    public void printMessage(String message) {
        System.out.println("My message is : " + message);
    }

}

Main class

import org.robotframework.javalib.library.AnnotationLibrary;
import org.robotframework.remoteserver.RemoteServer;

public class KeywordRemoteLibrary extends AnnotationLibrary {

    public static void main(String[] args) {
        RemoteServer.configureLogging();
        RemoteServer server = new RemoteServer("localhost", 8271);
        server.putLibrary("/keywords", KeywordRemoteLibrary.class);
        try {
            server.start();
        }
        catch(Exception e) {
            e.printStackTrace();
        }
    }

}

Eclipse console

17:11:26.290 [main] INFO  org.eclipse.jetty.util.log - Logging initialized @1006ms to org.robotframework.remoteserver.logging.Jetty2Log4J
17:11:26.361 [main] INFO  org.robotframework.remoteserver.RemoteServer - Mapped path /keywords to library java.lang.Class.
17:11:26.362 [main] INFO  org.robotframework.remoteserver.RemoteServer - Robot Framework remote server starting
17:11:26.364 [main] INFO  org.eclipse.jetty.server.Server - jetty-9.4.25.v20191220; built: 2019-12-20T17:00:00.294Z; git: a9729c7e7f33a459d2616a8f9e9ba8a90f432e95; jvm 11.0.2+9
17:11:26.435 [main] INFO  org.eclipse.jetty.server.handler.ContextHandler - Started o.e.j.s.ServletContextHandler@421bba99{/,null,AVAILABLE}
17:11:26.460 [main] INFO  org.eclipse.jetty.server.AbstractConnector - Started ServerConnector@379614be{HTTP/1.1,[http/1.1]}{127.0.0.1:8271}
17:11:26.461 [main] INFO  org.eclipse.jetty.server.Server - Started @1178ms
17:11:26.461 [main] INFO  org.robotframework.remoteserver.RemoteServer - Robot Framework remote server started on port 0.

Robotframework code

*** Settings ***
Library    Remote    http://localhost:8271

*** Test Cases ***
First Test Case
    Print Message    test

Error However I'm facing an error on robotframework script:

Unknow 'Remote' library under 'http://localhost:8271' location. Unable to connect.

Hi-Fi commented 4 years ago

Your server starts on port 0 (so probably doesn't start at all or there's some issue with port printing. I think it's somehow issue with giving the host, too, as this example works fine: https://github.com/eficode/JavaFXLibrary/blob/master/src/main/java/JavaFXLibraryRemoteServer.java

Hi-Fi commented 4 years ago

In my demo at Robocon I started that with Maven: https://github.com/Hi-Fi/rf-remote-library-demos/tree/master/basic_data_handling/src/java/pom.xml

nlamblin commented 4 years ago

I updated the Java code with the first example you gave :

import org.robotframework.javalib.library.AnnotationLibrary;

public class KeywordRemoteLibrary extends AnnotationLibrary {

    public static void main(String[] args) throws Exception {
         String host = "127.0.0.1";
                 int port = 64494;
         KeywordRemoteLibraryServer.configureLogging();
         KeywordRemoteLibraryServer server = new KeywordRemoteLibraryServer(host, port);
         server.putLibrary("/RPC2", new KeywordRemoteLibrary());
         server.start();
    }

}
--------------------------------------------------------------------------------------------------------------
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.core.config.Configurator;
import org.apache.logging.log4j.core.config.DefaultConfiguration;
import org.robotframework.remoteserver.RemoteServer;
import org.robotframework.remoteserver.logging.Jetty2Log4J;

public class KeywordRemoteLibraryServer extends RemoteServer {

    public KeywordRemoteLibraryServer(String host, int port) {
        super(host, port);
    }

    private static Log log = LogFactory.getLog(RemoteServer.class);

    public static void configureLogging() {
        Configurator.initialize(new DefaultConfiguration());
        Configurator.setRootLevel(Level.FATAL);
        org.eclipse.jetty.util.log.Log.setLog(new Jetty2Log4J());
        LogFactory.releaseAll();
        LogFactory.getFactory().setAttribute("org.apache.commons.logging.Log",
                "org.apache.commons.logging.impl.Log4JLogger");
        log = LogFactory.getLog(RemoteServer.class);
    }

}

However, I'm still facing the same issue. Could you please help me ? Thank you.

When I access to 127.0.0.1/64494, I have this:

Capture

And netstat -ano command :

 Proto  Local Address          Foreign Address        State           PID
 TCP    127.0.0.1:64494        0.0.0.0:0              LISTENING       92432

So, I supposed that the server is up?

Robotframework error during robot execution : Getting keyword names from library 'Remote' failed: Calling dynamic method 'get_keyword_names' failed: Connecting remote server at http://127.0.0.1:64494 failed: <Fault 0: 'Failed to invoke method get_keyword_names in class org.robotframework.remoteserver.servlet.ServerMethods: java.lang.RuntimeException'>

Stacktrace on the server:

java.lang.RuntimeException: null
    at org.robotframework.remoteserver.library.DynamicApiRemoteLibrary.getKeywordNames(DynamicApiRemoteLibrary.java:54) ~[jrobotremoteserver-4.0.0.jar:?]
    at org.robotframework.remoteserver.servlet.ServerMethods.get_keyword_names(ServerMethods.java:53) ~[jrobotremoteserver-4.0.0.jar:?]
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:?]
        ...

So, I supposed that connection is done correct?

Thank you very much for your help.

Update : I added this and problem seems to be fixed.

static List<String> includePatterns = new ArrayList<String>() {{
        add("keywords/*.class");
}};

public KeywordRemoteLibrary() {
    super(includePatterns);
}

However, I still have error on RED IDE. Indeed it is still mentioned that Remote is not connected. But I think that it is a RED issue correct ? image

Hi-Fi commented 4 years ago

With jrobotremoteserver you have to have trailing / at the end, as otherwise it defaults to /RPC2. But with browser you can see, that remote should end with /RPC2 as library is published to that path.

Haven't used RED so don't know if it reads remote documentation like that.

Hi-Fi commented 2 years ago

No comments for long time -> closing.