0 Replies Latest reply: Mar 14, 2013 6:35 AM by 996036 RSS

    Help with code error! Web Method

      hey everyone,

      i have a web service and i would like the client to send a file on server via a web method and then i would like to read the file that the client send. The web method is this :
      @WebMethod(operationName = "getfile") public void getfile(@WebParam(name = "getfile") DataHandler dh) throws IOException {

      InputStream in = dh.getInputStream();
      StringWriter writer = new StringWriter();
      org.apache.commons.io.IOUtils.copy(in, writer, "UTF-8");
      String theString = writer.toString();


      and the client calls the method from here :

      public static void main (String args[]) throws IOException, IOException_Exception{

      SOAPService service = new SOAPService();
      SOAPProxy = service.getGetXMLPort();
      File file = new File("C:\\Users\\manos\\Downloads\\manos.txt");
      FileDataSource fd = new FileDataSource(file);
      DataHandler datahandler = new DataHandler(fd);
      InputStream in = datahandler.getInputStream();
      byte [] array = org.apache.commons.io.IOUtils.toByteArray(in);


      but i get a NullPointerException in line SOAPProxy.getfile(array);

      this is the error:

      Exception in thread "main" javax.xml.ws.soap.SOAPFaultException: java.lang.NullPointerException at com.sun.xml.internal.ws.fault.SOAP11Fault.getProtocolException(SOAP11Fault.java:178) at com.sun.xml.internal.ws.fault.SOAPFaultBuilder.createException(SOAPFaultBuilder.java:111) at com.sun.xml.internal.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:108) at com.sun.xml.internal.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:78) at com.sun.xml.internal.ws.client.sei.SEIStub.invoke(SEIStub.java:129) at $Proxy32.getfile(Unknown Source) at com.mantsap.getxmlclient.SOAPClient.main(SOAPClient.java:25) Java Result: 1

      the length of the array is 8! i made a system.out to be sure.

      The file manos is just a text file.

      Thanks in Advance.:)