1 Reply Latest reply on Jun 15, 2010 6:52 AM by himanshu27k

    POST Method Rest Web Service call

      Hi,

      I am getting null pointer exception while trying to create user through rest web service.

       

               HttpClient client = new HttpClient();       
              Credentials defaultcreds = new UsernamePasswordCredentials("admin","admin");       
              client.getState().setCredentials(AuthScope.ANY, defaultcreds);
                     
              PostMethod method = new PostMethod("http://100.10.14.153/rpc/rest/userService/users");               
              method.setRequestHeader( "Content-type", "text/xml; charset=UTF-8" );
             
              String message= "<createUser> <username>test1</username><password>test1</password><email>test1@sae.org</email></createUser>";
             
              try{
              RequestEntity entity = new StringRequestEntity(message, "application/atom+xml", "UTF-8");
              method.setRequestEntity(entity);           
                     
              client.executeMethod(method);       
              InputStream in = method.getResponseBodyAsStream();
             
              // Use dom4j to parse the response and print nicely to the output stream
              SAXReader reader = new SAXReader();       
              Document document = reader.read(in);       
              XMLWriter writer = new XMLWriter(System.out, OutputFormat.createPrettyPrint());      
              writer.write(document);    
              }
              catch(Exception ex){
                  ex.printStackTrace();
              }
              finally{
                  method.releaseConnection();

       

              }