Re: problem in a web service

"Francesco Dipalo" <[email protected]> Mon, 17 Jan 2005 20:11:37 +0100
Newsgroups gmane.text.xml.soap.user
Message-ID <002e01c4fcc8$6b131d10$c6b91c97@BOBO>
I use only a deployment descriptor file
TIA
  ----- Original Message ----- 
  From: Martin Gainty 
  To: [email protected] 
  Sent: Monday, January 17, 2005 3:15 PM
  Subject: Re: problem in a web service


  Francesco:

  Can we see the source code for xml_pars
  Also please provide the wsdl you are using

  Molte Grazie,

  Martin-
  001-617-852-7822
    ----- Original Message ----- 
    From: Francesco Dipalo 
    To: [email protected] 
    Sent: Monday, January 17, 2005 6:18 AM
    Subject: problem in a web service


     I have written this .dd file: 
    <isd:service 
       xmlns:isd="http://xml.apache.org/xml-soap/deployment"
       id="urn:Composizione">
       
       <isd:provider type="java"
             scope="Application"
             methods="compone">
         <isd:java class="service_controller"
             static="false"/>
       </isd:provider>
       <isd:faultListener>org.apache.soap.server.DOMFaultListener</isd:faultListener>
       <isd:mappings>
       </isd:mappings>    
    </isd:service>

    this client  ( in %SOAP-HOME%\WEB-INF\classes)

    import java.net.*;
    import java.util.*;
    import java.io.*;
    import org.apache.soap.*;
    import org.apache.soap.rpc.*;

    public class Client {
       static boolean corretto1=false;
       static boolean corretto2=false;
       
       static boolean Copy(String path, String filename) throws Exception {
          boolean flag=false;
          File pathTo = new File(path + filename); 
          File pathFrom = new File(filename);
          try { 
             FileInputStream inputFile = new FileInputStream(pathFrom); 
             int bytes = inputFile.available(); 
             pathTo.createNewFile(); 
             FileOutputStream outputFile = new FileOutputStream(pathTo); 
             int readBytes = 0; 
             while (readBytes < bytes) {   
                outputFile.write(inputFile.read()); 
                readBytes++; 
             } 
          inputFile.close(); 
          outputFile.close();
          flag=true; 
          } catch (FileNotFoundException e) { 
            flag=false;
            System.out.println("Il file: " + pathFrom.toString() + ", non esiste!"); 
            e.printStackTrace(); 
          } 
          return flag;
       }

       public static void main(String[] args) throws Exception {
          String c_Nomefile="";
          String c_Nomefile1="";
          String c_Nomefile2="";
          String CATALINA_HOME=System.getProperty("catalina.home"); 
          String [] lista = new File(".").list();
          URL url = new URL("http://localhost:8080/soap/servlet/rpcrouter"); 
          System.out.println("ELENCO SERVIZI:");
          for(int cx=0; cx<lista.length; cx++)
             if ( new File(lista[cx]).isFile() )                           //verifica se รจ file
                if ( lista[cx].toLowerCase().lastIndexOf(".owl") >= 0)     //e con estensione owl
                   System.out.println((" * " + lista[cx]+"             ").substring(0,20));
          try {
             do {
                System.out.print("Servizio principale (digitare anche l'estensione): ");
                BufferedReader in1= new BufferedReader(new InputStreamReader(System.in));
                c_Nomefile1 = in1.readLine();
             } while (!(c_Nomefile1.endsWith(".owl")));
             do {
                System.out.print("Servizio da comporre (digitare anche l'estensione): ");
                BufferedReader in2= new BufferedReader(new InputStreamReader(System.in));
                c_Nomefile2 = in2.readLine();
             } while (!(c_Nomefile1.endsWith(".owl")));
             c_Nomefile = c_Nomefile1 + c_Nomefile2; // crea nome file composto
          } catch (Exception e) { e.printStackTrace(); }
          c_Nomefile = c_Nomefile1.substring(0,c_Nomefile1.indexOf('.')) + c_Nomefile2; 
          corretto1=Copy(CATALINA_HOME+"\\bin\\",c_Nomefile1);
          corretto2=Copy(CATALINA_HOME+"\\bin\\",c_Nomefile2);
          if ((corretto1==true) && (corretto2==true)) {
             Call call = new Call();
             call.setTargetObjectURI("urn:Composizione");   
             call.setEncodingStyleURI(Constants.NS_URI_SOAP_ENC);
             Vector params = new Vector();
             params.addElement(new Parameter("file_1", String.class, c_Nomefile1, null));
             params.addElement(new Parameter("file_2", String.class, c_Nomefile2, null));
             params.addElement(new Parameter("file_composto", String.class, c_Nomefile, null));
             params.addElement(new Parameter("path_output", String.class, CATALINA_HOME+"\\webapps\\soap\\WEB-INF\\classes\\", null));
             
             call.setParams(params);
             try {
         call.setMethodName("compone");   
                Response resp = call.invoke(url, "");
                if (resp.generatedFault()) {
                   Fault fault = resp.getFault();
                   System.err.println("Generated fault: " + fault);
                } else {
                   Parameter ret = resp.getReturnValue();
                   Object value = ret.getValue();
                   switch (value.hashCode()) {
                      case 0: System.out.println("I due file non sono componibili"); break;
                      case 1: System.out.println("I due file sono stati composti nel file " +c_Nomefile); break;
                      case -1: System.out.println("Utility interrotta per errori"); break;
                   }
                }
             } catch (SOAPException e) {
                System.err.println("Caught SOAPException (" +e.getFaultCode() + "): " +e.getMessage());
             }
          } 
          try { 
             System.out.print("\nPremere INVIO per terminare...\n");
             System.in.read();
          } catch(Exception e) {}
       }
    }

    this service ( in %SOAP-HOME%\WEB-INF\classes)

    import java.io.*;
    //import xml_pars;

    public class service_controller {
     public static int c_Comp;                     //esito della composizione (1=ok, 0=non composto, -1=errore tag)
     public static String tempor;                  //final static String fileTMP = "tmp.owl";

     private static String c_Tabella;
     private static xml_pars owl = new xml_pars();  //classe parsing .XML
     private static String linea;
     private static boolean corretto;
     
     //---------------------//
     //     COMPOSIZIONE    //      MAIN
     //---------------------//
     //Costruttori della classe:  //si possono togliere
             public service_controller () { }
             public service_controller (String file_1, String file_2, String file_composto, String path_output) {
                    compone(file_1, file_2, file_composto, path_output);
             }
     public static String get_output() { if (c_Comp <= 0) tempor = ""; return tempor; } //metodo di controllo
     public static int compone0(String file_1, String file_2, String file_composto, String path_output) {
           metodi_xml(file_2); return (c_Comp = c_ProceduraTag(file_1));
     }
     public static int compone(String file_1, String file_2, String file_composto, String path_output) {
           if (compone0(file_1, file_2, file_composto, path_output) <= 0) {

                  System.out.println("\nI due servizi non sono tra loro componibili.");
                  waitkey();

           } else {

                  System.out.println("\nFILE COMPOSTO:\n");
                  int cx = 0; owl.put_parsing(get_output());
                  do {    if ( ((cx++)%16) == 0) waitkey();
                          System.out.print(owl.ctags());
                  } while (owl.nido >= 0 || cx<3);

                  if (path_output.length() > 0) owl.newdir(path_output);       //se non c'S crea la cartella
                  owl.put_parsing(get_output());
                  owl.save_parsing(path_output + "/" + file_composto); //c_EliminaFile(); fare in modo che in path_output compaia il percorso fino a soap
                  //if (file_1.length() > 0) { owl.load_parsing(file_1); owl.save_parsing(path_output + "/" + file_1); }
                  //if (file_2.length() > 0) { owl.load_parsing(file_2); owl.save_parsing(path_output + "/" + file_2); }

           }
          return c_Comp;
     }


     //---------------------//
     //     METODI XML      //      PROCEDURE UTILITY
     //---------------------//
    // Carica un file.owl e lo compila in una tabella di: tipo, nome del tag + \n
     public static void metodi_xml (String file) {
           System.out.print("Apro il file "+file+" ... ");
           if (! (corretto = owl.load_parsing(file)) )
                  System.out.println("Errore!");
           else  {  // crea tabella
                  System.out.println("Ok!\nCompilo la tabella...");
                  owl.tag(2);          //salta header (tag <?> e tag Ontology)
                  c_Tabella = tempor = "";
                  while(true) {
                         c_AnalisiTag(owl.tags()); if (owl.nido < 0) break;
                         if (linea.length() > 1) c_Tabella += linea + "\n";
                         tempor += owl.tag_root(owl.xml_id);
                  }
           }
     }
    // Compila il singolo tag (tipo, nome del tag + \n)
     public static int c_AnalisiTag(String tag) {           // ritorna tipo tag e linea       
           linea = ".";       
           if (owl.si_tag(tag,"<owls:") > 0) {
                  linea = owl.search_true(tag, "owls:Class ", "C") +
                          owl.search_true(tag, "owls:ObjectProperty ", "P") +
                          //owl.search_true(tag, "owls:Ontology ", "O") +
                          linea;
                  if (linea.length() == 1) {
                         System.out.println("Tag sconosciuto: " + tag);
                         corretto = false; };
                  linea += owl.search_tag(tag, "name=");    //"owls:name"
           };
           return linea.charAt(0);
     }
    // Esegue la composizione del file con il file passato in metodi_xml
     public static int c_ProceduraTag(String file) {        // esegue utility
           String temp, tag; int comp = 0; temp = tag = "";
           System.out.print("Apro il file "+file+" ... ");
           if (! owl.load_parsing(file) ) {
                  System.out.println("Errore!"); corretto = false; };
           if (corretto) {
                  System.out.println("Ok!\nAvvio utility...");
                  owl.tag(2);   //salta header (tag <?> e tag Ontology)
                  do {   tag = owl.tags();    //o tag = owl.tag(0);
                         int tipo = c_AnalisiTag(tag);
                         if (linea.length() > 1) {
                            tag = owl.tag_root(owl.xml_id);
                            if (c_Tabella.indexOf(linea) < 0) { temp += tag; }
                              else {  if (tipo=='C') comp = 1;  //...
                            }
                        }
                  } while (owl.nido >= 0);
           }
           if (!corretto) { System.out.println("Utility interrotta per errori."); comp = -1; };
           owl.reset(); //aggiunge intestazione padre
           tempor = owl.tags() + owl.tags() + tempor + temp + tag;
           return comp;
     }


    //---------------------//
    //      OUTPUT         //       PROCEDURE OUTPUT
    //---------------------//
     public static void waitkey() {         // Attende il tasto invio
      try { System.out.print("\nPremere INVIO per proseguire...\n");
            System.in.read(); } catch(Exception e) {}
     }



     //--------------
     // MAIN DI PROVA
     //--------------
     //public static void main(String []argv) {
     //       compone("PROVA1.OWL", "PROVA2.OWL", "prova1prova2.owl", ".");
     //}       

    }

    but I received this exception (the xml_pars.class is in %SOAP-HOME%\WEB-INF\classes)

    Generated fault: [Attributes={}] [faultCode=SOAP-ENV:Server] [faultString=Except
    ion from service object: null] [faultActorURI=/soap/servlet/rpcrouter] [DetailEn
    tries=
    [(0)=<stackTrace>java.lang.NullPointerException
            at xml_pars.tag(Unknown Source)
            at xml_pars.reset(Unknown Source)
            at service_controller.c_ProceduraTag(service_controller.java:104)
            at service_controller.compone0(service_controller.java:23)
            at service_controller.compone(service_controller.java:26)
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
            at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
    java:39)
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
    sorImpl.java:25)
            at java.lang.reflect.Method.invoke(Method.java:324)
            at org.apache.soap.server.RPCRouter.invoke(RPCRouter.java:146)
            at org.apache.soap.providers.RPCJavaProvider.invoke(RPCJavaProvider.java
    :129)
            at org.apache.soap.server.http.RPCRouterServlet.doPost(RPCRouterServlet.
    java:354)
            at javax.servlet.http.HttpServlet.service(HttpServlet.java:760)
            at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
            at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Appl
    icationFilterChain.java:247)
            at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationF
    ilterChain.java:193)
            at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperV
    alve.java:256)
            at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContex
    t.invokeNext(StandardPipeline.java:643)
            at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.jav
    a:480)
            at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)

            at org.apache.catalina.core.StandardContextValve.invoke(StandardContextV
    alve.java:191)
            at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContex
    t.invokeNext(StandardPipeline.java:643)
            at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.jav
    a:480)
            at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)

            at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:
    2422)
            at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.j
    ava:180)
            at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContex
    t.invokeNext(StandardPipeline.java:643)
            at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatche
    rValve.java:171)
            at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContex
    t.invokeNext(StandardPipeline.java:641)
            at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.j
    ava:163)
            at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContex
    t.invokeNext(StandardPipeline.java:641)
            at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.jav
    a:480)
            at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)

            at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineVal
    ve.java:174)
            at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContex
    t.invokeNext(StandardPipeline.java:643)
            at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.jav
    a:480)
            at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)

            at org.apache.coyote.tomcat4.CoyoteAdapter.service(CoyoteAdapter.java:19
    9)
            at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java
    :828)
            at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.proce
    ssConnection(Http11Protocol.java:700)
            at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java
    :584)
            at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadP
    ool.java:683)
            at java.lang.Thread.run(Thread.java:534)
    </stackTrace>]
    ] [FaultEntries=]

    Why? Can anyone help me?
    TIA
    TIA




    ----
    Email.it, the professional e-mail, gratis per te:clicca qui

    Sponsor:
    Scopri il benessere che solo l'aloe vera regala al tuo corpo: cura la tua pelle
    Con la vasta gamma di prodotti che ti offre Erboristeria.com
    Clicca qui



 
 
 --
 Email.it, the professional e-mail, gratis per te: http://www.email.it/f
 
 Sponsor:
 Ascolta le migliori suonerie per il tuo cellulare 
 Clicca qui: http://adv.email.it/cgi-bin/foclick.cgi?mid113&d-1