Mule 3.6 Custom Java Class

529 views Asked by At

I'm building a flow wich has a java class to open a SCP conection with my server and send a file through it.

Following the java code:

    import java.io.IOException;

    import net.schmizz.sshj.SSHClient;
    import net.schmizz.sshj.transport.verification.PromiscuousVerifier;
    import net.schmizz.sshj.xfer.FileSystemFile;

    import org.mule.api.MuleEventContext;
    import org.mule.api.lifecycle.Callable;

public class SCPUpload  implements Callable  {

@Override
public Object onCall(MuleEventContext eventContext)         throws IOException {

    String hostPath = eventContext.getMessage().getInvocationProperty("hostProcessorPath");
    String hostIp = eventContext.getMessage().getInvocationProperty("host_ip");
    String hostPort = eventContext.getMessage().getInvocationProperty("host_port");
    String fileFullPaTh  = eventContext.getMessage().getInvocationProperty("filePath");
    String filename  = eventContext.getMessage().getInvocationProperty("filename");


    System.out.println(hostPath);
    System.out.println(hostIp);
    System.out.println(hostPort);
    System.out.println(filename);



    try(SSHClient ssh = new SSHClient();) {

         ssh.addHostKeyVerifier(new PromiscuousVerifier());
         ssh.connect(hostIp , Integer.parseInt(hostPort));
         ssh.authPassword("ubuntu", "reverse".toCharArray());
        // Present here to demo algorithm renegotiation - could have just put this before connect()
        // Make sure JZlib is in classpath for this to work
        //not necessary for while
        //ssh.useCompression();

        final String src = fileFullPaTh + "\\" + filename;
        System.out.println(src);
        ssh.newSCPFileTransfer().upload(new FileSystemFile(src), hostPath + "/" + src.replace("\\", "_"));

    } 

    return true;
}

}

Before it worked, but not any more and I can't realize why. Following the stack trace:

 Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)#4f624884': Error setting property values; nested exception is org.springframework.beans.PropertyBatchUpdateException; nested PropertyAccessExceptions (1) are:
PropertyAccessException 1: org.springframework.beans.MethodInvocationException: Property 'objectClassName' threw exception; nested exception is java.lang.IllegalArgumentException: java.lang.ClassNotFoundException: SCPUpload

My flow is like this:

 <flow name="hotFolder_sender" initialState="started" processingStrategy="synchronous">
            <set-variable variableName="hostProcessorPath" value="/tmp/go_images" doc:name="Host Processor Path"/>
            <set-variable variableName="host_ip" value="192.168.0.107" doc:name="Host IP"/>
            <set-variable variableName="host_port" value="22" doc:name="host port"/>
            <set-payload value="java" doc:name="Set Payload"/>
            <component class="SCPUpload" doc:name="SCPUpload"/>



        </flow>

Please, can some one help see where I'm wronging? Or a diferent way to do so?

1

There are 1 answers

1
valter Gomes On

I got success in build my project now.

For some reason the path src/main/java existed in mule project but not as a physical path, then, my classes was never been created in the right path and as consequence a ClassNotFoundException was threw.

To fix it, I removed all references to this path in my project and created it again.

Following the steps I took:

1) right click in project > build path > configure build path 2) remove all refernces to src/main/java 3) check if the folder was rightly removed if not remove it manually 4) back to right click in project > build path > configure build path 5) add folder button 6) create a folder named java in src/main 7) start the project :)

Thanks a lot @Sudarshan, I just moved forward for your help and thanks @David Dossot for always support us here.