0

I was creating a Java web service server, using eclipse IDE. that server is the following.

Note: I am working in UBUNTU

package com.tesis.service;

import java.util.concurrent.ExecutionException;
import java.util.concurrent.RejectedExecutionException;

import com.mathworks.engine.*;

/**
 * @author root
 *
 */
public class CNNPredict 
{
    public String cNNPredict(int[] Image, int Height, int Width) throws Exception
    {
        String FilePath =   "/home/user/Documents/MATLAB/Project";
        char[] CharFilePath = FilePath.toCharArray();
        MatlabEngine eng = MatlabEngine.startMatlab();
        eng.feval("cd", CharFilePath);
        String result = eng.feval("CNNPredict",Image,Height,Width);
        return result;
    }
}

As you can see I am using MATLAB engine. Matlab engine documentation. I checked that cNNPredict method is working properly by copying it into a new Java project and It worked perfectly. I added the .jar files required to run java engine to the Dynamic web project where the web service is located.

Apparently this web service runs without problems Web Service working in local host If I click on "CnnPredict" link I get the wsdl direction of the class , this direction is what I use to link the client with the server.

this is the client code:

public static void main(String[] args) throws IOException, CNNPredictExceptionException
{
    CNNPredictStub stub = new CNNPredictStub();
    CNNPredict cnn = new CNNPredict();
    BufferedImage img = null;
    System.out.println("Reading image ...");
    img = ImageIO.read(new File("/home/riosgamarra/Documents/MATLAB/TesisGamarrarios/101_ObjectCategories/laptop/image_0009.jpg"));
    int[] UnrolledImage = convertToGray(img);
    cnn.setImage(UnrolledImage);
    cnn.setWidth(img.getWidth());
    cnn.setHeight(img.getHeight());
    System.out.println(stub.cNNPredict(cnn).get_return());

}

It has no errors, but when I run it this error message shows up:

Exception in thread "main" org.apache.axis2.AxisFault: <faultstring>com/mathworks/engine/MatlabEngine</faultstring>
    at org.apache.axis2.util.Utils.getInboundFaultFromMessageContext(Utils.java:513)
    at org.apache.axis2.description.OutInAxisOperationClient.handleResponse(OutInAxisOperation.java:368)
    at org.apache.axis2.description.OutInAxisOperationClient.send(OutInAxisOperation.java:414)
    at org.apache.axis2.description.OutInAxisOperationClient.executeImpl(OutInAxisOperation.java:225)
    at org.apache.axis2.client.OperationClient.execute(OperationClient.java:150)
    at com.tesis.service.CNNPredictStub.cNNPredict(CNNPredictStub.java:197)
    at com.tesis.client.CallWS.main(CallWS.java:40)

what I am missing ? do I need to add any special permissions to the server project ? What Am I missing ?

Note: I run the client clicking on the class and selecting Run as > Java application.

5
  • as a side note. Are you coding as root? Not good :-}
    – bichito
    Commented Mar 7, 2017 at 21:14
  • Could you be more specific please, Don´t know what do you mean with "coding as root". Thanks Commented Mar 8, 2017 at 3:19
  • /** * @author root * */ It is in the source you posted
    – bichito
    Commented Mar 8, 2017 at 3:30
  • Thanks, now I see it, But could you tell me why this situation is generating the error in the code or if I need to add some complements in the project?? Commented Mar 8, 2017 at 23:26
  • I will post my comments for convenience of space
    – bichito
    Commented Mar 8, 2017 at 23:38

1 Answer 1

0
 at com.tesis.service.CNNPredictStub.cNNPredict(CNNPredictStub.java:197)

is where the exception is but

public class CNNPredict 
{
    public String cNNPredict(int[] Image, int Height, int Width) throws Exception
    {
        String FilePath =   "/home/user/Documents/MATLAB/Project";
        char[] CharFilePath = FilePath.toCharArray();
        MatlabEngine eng = MatlabEngine.startMatlab();
        eng.feval("cd", CharFilePath);
        String result = eng.feval("CNNPredict",Image,Height,Width);
        return result;
    }
}

is not the stub. First we need to the right code to look at. The matlab api is straight forward. My guess is that the stub is making the wrong call

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.