0

I have to upload a file using soap ui.Below is my service code.It executes fine if call using jersey.But when i try to call using soapui null pointer exception occurs.

I call the fileupload service in soap ui like below

Create Rest Project: Add the Url:

http://localhost:8080/FileService/Services/HomeService/testupload
file file:c:\\1.wav





 @POST
            @Path("testupload")
            @Consumes(MediaType.MULTIPART_FORM_DATA)
            @Produces(MediaType.TEXT_PLAIN)
            public String uploadFile(@FormDataParam("file") InputStream fis,
                            @FormDataParam("file") FormDataContentDisposition fdcd) {

                OutputStream outpuStream = null;
                String fileName = fdcd.getFileName();

                String filePath = FOLDER_PATH + fileName;

                try {
                    int read = 0;
                    byte[] bytes = new byte[1024];
                    outpuStream = new FileOutputStream(new File(filePath));
                    while ((read = fis.read(bytes)) != -1) {
                        outpuStream.write(bytes, 0, read);
                    }
                    outpuStream.flush();
                    outpuStream.close();
                } catch(IOException iox){
                    iox.printStackTrace();
                } finally {
                    if(outpuStream != null){
                        try{outpuStream.close();} catch(Exception ex){}
                    }
                }
                return "File Upload Successfully !!";
            }

How to fix this issue? Any help will be greatly appreciated!!!

Selva
  • 1,620
  • 3
  • 33
  • 63
  • 1
    possible duplicate of [What is a Null Pointer Exception, and how do I fix it?](http://stackoverflow.com/questions/218384/what-is-a-null-pointer-exception-and-how-do-i-fix-it) – dotvav Sep 30 '15 at 09:17
  • My doubt is how to pass file as stream using soapui – Selva Sep 30 '15 at 09:18
  • provide stacktrace or which line the exception occurs – Selva Sep 30 '15 at 09:19
  • ep 30, 2015 2:39:20 PM org.apache.catalina.core.StandardWrapperValve invoke SEVERE: Servlet.service() for servlet [File Service] in context with path [/FileService] threw exception java.lang.NullPointerException at com.uploadFile(HomeService.java:112) PM com.sun.jersey.spi.container.ContainerResponse mapMappableContainerException SEVERE: The RuntimeException could not be mapped to a response, re-throwing to the HTTP container java.lang.NullPointerException – Selva Sep 30 '15 at 09:23
  • I think fdcd or fis in null.. please check that. Please catch NullPointerException also – Selva Sep 30 '15 at 09:24
  • yes absolutely,but i pass a file as attachement in soapui.but the same service is working fine if i call via jersey – Selva Sep 30 '15 at 09:43

0 Answers0