1

I have simple java method to upload file from local disk to remote web service, and it's working great in controller class.

Now I moved this method into separated class. I try to call this method from thread :

    public void run(){

        while (true){
            System.out.println("Geting next Task for processing ...");


            try {

                CommonUtils.uploadVideo(32);


                Thread.sleep(20000);

            } catch (InterruptedException | IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (ExecutionException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
        }
}

@Inject
static
WSClient ws;

synchronized static void uploadVideo(int taskId) throws  InterruptedException, ExecutionException, IOException {
     ....
     ....
     ...

        com.ning.http.client.AsyncHttpClient underlyingClient =  (com.ning.http.client.AsyncHttpClient) ws.getUnderlying();

        final String response;

        response = underlyingClient.preparePost("http://192.16.10.125:9001/publish").
                                setHeader("watermark", "0").
                                addBodyPart(new FilePart("file", file)).execute().get().getResponseBody().toString();


  }

And I got an error :

Exception in thread "Thread-8" java.lang.NullPointerException
        at utils.CommonUtils.uploadVideo(CommonUtils.java:308)
        at utils.TaskRunner.run(TaskRunner.java:88)
        at java.lang.Thread.run(Unknown Source)

What is wrong? Is the problem Asynchronous call web service?

0 Answers0