Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/311.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/ssh/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mule 3 java调用以连接到unix_Java_Ssh_Mule Esb - Fatal编程技术网

Mule 3 java调用以连接到unix

Mule 3 java调用以连接到unix,java,ssh,mule-esb,Java,Ssh,Mule Esb,我正在mule 3中开发一个新流程,在这里我使用java组件连接到unix服务器并从服务器发出一些查询 Java代码按预期工作,但如果我将相同的代码放在mule的Java组件中,则会出现以下错误: org.mule.model.resolvers.EntryPointNotFoundException: Failed to find entry point for component, the following resolvers tried but failed: [ MethodHeade

我正在mule 3中开发一个新流程,在这里我使用java组件连接到unix服务器并从服务器发出一些查询

Java代码按预期工作,但如果我将相同的代码放在mule的Java组件中,则会出现以下错误:

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}.
附上mule代码以供参考

<?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>
感谢有人调查此事并帮助解决问题

谢谢,
Nikhil

问题是Mule不知道要调用哪个方法。在Mule中解决此问题的标准方法是创建一个类,并从onCall()方法调用自定义代码。这样,您就更可能不需要修改现有的Java代码

这篇博客文章有一个如何做的例子:。提示:不要像示例那样使用System.out

更新: 我看到Java代码有一个main()方法,可以从命令行使用。这不是重用代码的好设计。您应该将其重构为一个方法,其中包含硬编码的数据参数(主机、用户等)。然后您就可以实现可调用接口,该接口只有一个onCall()方法,它应该调用您的新方法

为了让您了解这是一个伪代码示例:

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, ...)
    }

}

请至少分享您打算执行的Java方法的签名。HI Aled,我需要使用Java将mule 3连接到unix服务器并执行脚本。我已更新了答案。如果是正确的,请接受。我在问题中添加了您的代码。您应该删除此答案,因为它不是真正的答案。这是问题信息的一部分。
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, ...)
    }

}
Hi Attaching the piece of  java  code for reference.

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);
        }
    }
}