-1

i am working on a new flow in mule 3 where i am using java component to connect to a unix server and fire some queries from server.

The Java code is working as expected But if i place the same code inside java component in mule i am getting the below mentioned error:

org.mule.model.resolvers.EntryPointNotFoundException: Failed to find entry point for component, the following resolvers tried but failed: [
MethodHeaderPropertyEntryPointResolver: The required property "method" is not set on the event
CallableEntryPointResolver: Object "connectionpkg.Connection@1deb78e1" does not implement required interface "interface org.mule.api.lifecycle.Callable"
AnnotatedEntryPointResolver: Component: connectionpkg.Connection@1deb78e1 doesn't have any annotated methods, skipping.
ReflectionEntryPointResolver: Could not find entry point on: "connectionpkg.Connection" with arguments: "{}"
]. Component that caused exception is: DefaultJavaComponent{newconFlow.component.1397643446}.

Attaching the mule code for reference.

<?xml version="1.0" encoding="UTF-8"?>

<mule xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
    xmlns:spring="http://www.springframework.org/schema/beans" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd">
    <http:listener-config name="HTTP_Listener_Configuration" host="localhost" port="7007" doc:name="HTTP Listener Configuration"/>
    <flow name="newconFlow">
        <http:listener config-ref="HTTP_Listener_Configuration" path="/conn" allowedMethods="get" doc:name="HTTP"/>
        <component doc:name="Java" class="connectionpkg.Connection"/>
        <logger message="#[payload]" level="INFO" doc:name="Logger"/>
    </flow>
</mule>

The Java source code is:

package connectionpkg;
import com.jcraft.jsch.Channel;
import com.jcraft.jsch.ChannelSftp;
import com.jcraft.jsch.JSch;
import com.jcraft.jsch.Session;

public class Connection {
    public static void main(String[] arg) {
        try {
            JSch jsch = new JSch();

            String user = "xxxx";
            String host = "xxxxx";
            int port = 22;
            String privateKey = "xxxxxxxx";

            jsch.addIdentity(privateKey);
            System.out.println("identity added ");

            Session session = jsch.getSession(user, host, port);
            System.out.println("session created.");

            // disabling StrictHostKeyChecking may help to make connection but makes it insecure
            // see http://stackoverflow.com/questions/30178936/jsch-sftp-security-with-session-setconfigstricthostkeychecking-no
            // 
            // java.util.Properties config = new java.util.Properties();
            // config.put("StrictHostKeyChecking", "no");
            // session.setConfig(config);

            session.connect();
            System.out.println("session connected.....");

            Channel channel = session.openChannel("sftp");
            channel.setInputStream(System.in);
            channel.setOutputStream(System.out);
            channel.connect();
            System.out.println("shell channel connected....");

            ChannelSftp c = (ChannelSftp) channel;

            String fileName = "test.txt";
            c.put(fileName, "./in/");
            c.exit();
            System.out.println("done");

        } catch (Exception e) {
            System.err.println(e);
        }
    }
}

Appreciate someone will Look into it and help to resolve the issue.

Thanks, Nikhil

aled
  • 21,330
  • 3
  • 27
  • 34

1 Answers1

0

The problem is that Mule doesn't know which method you want to call. The standard way to resolve this problem in Mule is that you create a class that implements the Callable interface, and call your custom code from the onCall() method. In that way it is more likely that you don't need to modify the existing Java code.

This blog article has an example of how to do it: https://www.ricston.com/blog/using-java-code-mule/. Tip: don't use System.out like the example does.

Updated: I see that the Java code has a main() method, to be used from the command line. That is not a good design for reusing the code. You should refactor it to a method, with parameters for the data has is hard-coded (host, user, etc). Then you can just can implement the Callable interface, which just has an onCall() method, which should call your new method.

Just to give you an idea this is a pseudo code example:

public class Connection implements Callable {
    public static void main(String[] arg) {
        execute(args[1], args[2],...);
    }

    public void execute(String host, String user, ...) {
      // Most of the code that was previously in the main method.

    }

    public Object onCall(MuleEventContext event) {
         // get parameters somehow 
         execute(host, user, ...)
    }

}
aled
  • 21,330
  • 3
  • 27
  • 34