2011-07-20 43 views
0

我陷入了這個可怕的問題,我有一個基於SOAP的web服務在Java中實現。除了其他數據的客戶端應該有「男性」和「女性」複選框,因此用戶可以選擇其中一個或兩個,客戶端應該發送到服務器存儲在數據庫,它是一個多值的實體,但它給了我錯誤500,在服務器端的故障這裏是客戶端的代碼,謝謝提前爲你的時間:將數組傳遞給SOAP會導致錯誤500

private void salvaActionPerformed(java.awt.event.ActionEvent evt) {          
    // TODO add your handling code here: 
    disease=malattia.getText(); 


    sexarra=new String[sexint]; 
    if(sexint==1) 
     sexarra[0]=sexone; 
    else if(sexint==0) 
     JOptionPane.showMessageDialog(null, "Bisogna specificare almeno un valore del campo sesso", "Errore", JOptionPane.ERROR_MESSAGE); 
    else{ 
     sexarra[0]=sexone; 
     sexarra[1]=sextwo;} 
     // System.out.print(sexarra[0]); 
     //  System.out.println(sexarra[1]); 



     description=descrizione.getText(); 


     agestr=eta.getText(); 
     if(agestr.equalsIgnoreCase("")) 
      JOptionPane.showMessageDialog(null, "Il campo età non può essere vuoto", "Errore", JOptionPane.ERROR_MESSAGE); 

     age=Integer.parseInt(agestr); 
     if(age<=0 || age>=110){ 

      JOptionPane.showMessageDialog(null, "Il valore inserito nel campo età non è giusto", "Errore", JOptionPane.ERROR_MESSAGE); 
     } 
     else{ 

      try { 
       URL url = new URL("http://localhost:8080/soap/servlet/rpcrouter"); 
       //costruzione della chiamata 
       Call chiamata = new Call(); 
       chiamata.setTargetObjectURI("urn:ServerNeuro"); 
       chiamata.setMethodName("aggiungi_malattia"); 
       chiamata.setEncodingStyleURI(Constants.NS_URI_SOAP_ENC); 

       SOAPMappingRegistry smr = new SOAPMappingRegistry(); 
       StringDeserializer sd = new StringDeserializer(); 
       smr.mapTypes (Constants.NS_URI_SOAP_ENC, new QName ("", "return"), null, null, sd); 
       chiamata.setSOAPMappingRegistry(smr); 


       //creazione dei parametri 

       Vector parametri = new Vector(); 
       parametri.addElement(new Parameter("malattia", String.class, disease, null)); 
       parametri.addElement(new Parameter("eta", Integer.class, age, null)); 
       parametri.addElement(new Parameter("descrizione", String.class, description, null)); 
       parametri.addElement(new Parameter("sexarra",String[].class, sexarra, null)); 

       chiamata.setParams(parametri); 
       try { 
        Response risp = chiamata.invoke(url, ""); 
        if (risp.generatedFault()) { 
         Fault fault = risp.getFault(); 
         System.err.println("Chimata Fallita"); 
         System.err.println("Code: " + fault.getFaultCode()); 
         System.err.println("descrizione: " + fault.getFaultString()); 
        } else { 
         Parameter par = risp.getReturnValue(); 
         msg = (String) par.getValue(); 
         System.out.print(msg); 
        } 
       } catch (SOAPException e) { 
        System.out.println("Errore causata da: (" + e.getFaultCode() + ") :" + e.getMessage()); 
        msg = "errore"; 
       } 

      } catch (MalformedURLException ex) { 
       System.out.println("Exception: " + ex.getMessage()); 
      } 
      System.out.println(msg); 
      if (msg.equals("si")) { 
       JOptionPane.showMessageDialog(null, "La registrazione è avvenuta con successo", "REGISTRAZIONE", JOptionPane.INFORMATION_MESSAGE); 

      } 
      else{ 


       JOptionPane.showMessageDialog(null, "Attenzione il utente inserito è gia esistente nel database", "ATTENZIONE", JOptionPane.ERROR_MESSAGE); 
      } 
     } 
}          

private void femminaActionPerformed(java.awt.event.ActionEvent evt) {           
    // TODO add your handling code here: 

    if(femmina.isSelected()){ 
     if(sexint==0){ 
      sexint++; 
      sexone=femmina.getText(); 

     } 

     else if(sexint==1){ 
      sexint++; 

      sextwo=femmina.getText(); 
     } 
     else 
      sexint--; 

     System.out.println(sexint); 
    } 
}          

private void maschioActionPerformed(java.awt.event.ActionEvent evt) {           
    if(maschio.isSelected()){ 
     if(sexint==0){ 
      sexint++; 
      sexone=maschio.getText(); 

     } 

     else if(sexint==1){ 
      sexint++; 

      sextwo=maschio.getText(); 
     } 
     else 
      sexint--; 

     System.out.println(sexint); 
    } 
} 

這裏是服務器代碼:

public String aggiungi_malattia(String malattia, Integer eta,String descrizione,String[] sexarra) { 
    String ris = "no"; 
    String q = null, w = null; 
    String errore = connetti(); 
    //inserimeto dei dati del utente dentro la tabella login 
    if(sexarra[1]== null){ 
     q = "INSERT INTO malattia (nome, eta, descrizione, sesso) " 
      + "VALUES ('" + malattia + "','" + eta + "','" + descrizione + "','" + sexarra[0] + "')";} 
    else{ 
     q = "INSERT INTO malattia (nome, eta, descrizione, sesso) " 
      + "VALUES ('" + malattia + "','" + eta + "','" + descrizione + "','" + sexarra[0] + "')"; 
     w="INSERT INTO malattia (nome, eta, descrizione, sesso) " 
      + "VALUES ('" + malattia + "','" + eta + "','" + descrizione + "','" + sexarra[1] + "')"; 
    } 

    if (errore.equals("")) { 
     try { 
      Statement st = conn.createStatement(); 
      if(sexarra[1]==null){ 
       st.executeUpdate(q); 
       st.executeUpdate(w); 
      } 
      else 
       st.executeUpdate(q); 
      st.close(); 
      conn.close(); 
      ris = "si"; 
     } catch (SQLException e) { 
      System.out.println("Errore: " + e.getMessage()); 
      return ris; 
     } 
    } 
    return ris; 
} 

這是Catalina.out的最後一行,它對我沒有任何意義。我懷疑該數組可能會導致它自從它在運行時確定後,我找不到任何其他方式來執行它,提示這裏將不勝感激

Jul 20, 2011 11:35:22 PM org.apache.catalina.realm.CombinedRealm startInternal 
    SEVERE: Failed to start "org.apache.catalina.realm.UserDatabaseRealm/1.0" realm 
    org.apache.catalina.LifecycleException: No UserDatabase component found under key UserDatabase 
     at org.apache.catalina.realm.UserDatabaseRealm.startInternal(UserDatabaseRealm.java:264) 
     at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:145) 
     at org.apache.catalina.realm.CombinedRealm.startInternal(CombinedRealm.java:201) 
     at org.apache.catalina.realm.LockOutRealm.startInternal(LockOutRealm.java:120) 
     at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:145) 
       at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:1026) 
       at org.apache.catalina.core.StandardEngine.startInternal(StandardEngine.java:291) 
     at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:145) 
     at org.apache.catalina.core.StandardService.startInternal(StandardService.java:443) 
     at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:145) 
     at org.apache.catalina.core.StandardServer.startInternal(StandardServer.java:727) 
     at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:145) 
     at org.apache.catalina.startup.Catalina.start(Catalina.java:620) 
     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) 
     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) 
     at java.lang.reflect.Method.invoke(Method.java:597) 
     at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:303) 
     at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:431) 
    Jul 20, 2011 11:35:22 PM org.apache.catalina.startup.HostConfig deployWAR 
    INFO: Deploying web application archive soap.war 
    Jul 20, 2011 11:35:23 PM org.apache.catalina.startup.HostConfig deployDirectory 
    INFO: Deploying web application directory manager 
    Jul 20, 2011 11:35:23 PM org.apache.catalina.startup.HostConfig deployDirectory 
    INFO: Deploying web application directory examples 
    Jul 20, 2011 11:35:24 PM org.apache.catalina.startup.HostConfig deployDirectory 
    INFO: Deploying web application directory ROOT 
    Jul 20, 2011 11:35:24 PM org.apache.catalina.startup.HostConfig deployDirectory 
    INFO: Deploying web application directory host-manager 
    Jul 20, 2011 11:35:25 PM org.apache.catalina.startup.HostConfig deployDirectory 
    INFO: Deploying web application directory docs 
    Jul 20, 2011 11:35:25 PM org.apache.catalina.startup.HostConfig deployDirectory 
    INFO: Deploying web application directory axis 
    - Unable to find config file. Creating new servlet engine config file: /WEB-INF/server-config.wsdd 
    Jul 20, 2011 11:35:26 PM org.apache.coyote.AbstractProtocolHandler start 
    INFO: Starting ProtocolHandler ["http-bio-8080"] 
    Jul 20, 2011 11:35:26 PM org.apache.coyote.AbstractProtocolHandler start 
    INFO: Starting ProtocolHandler ["ajp-bio-8009"] 
    Jul 20, 2011 11:35:26 PM org.apache.catalina.startup.Catalina start 
    INFO: Server startup in 3780 
+0

請檢查您的日誌,並告訴我們在哪一行中拋出異常。 Andiamo公司! – SJuan76

+0

似乎像Tomcat問題給我。你有沒有改變你的tomcat配置文件中的任何東西。我建議至少使用一個新的tomcat容器進行web服務測試。 – Shahzeb

回答

0

在UserDatabaseRealm異常意味着設置認證策略失敗。

您是否試過通過網頁(使用瀏覽器)訪問您的服務器?