0

im stuck in this terrible problem, I have a SOAP based webservice implemented in Java.The client besides other data is supposed to have "male" and "female" checkboxes so the user can either select one of them or both and the client is supposed to send it to the server to be stored in the database, where it is a multivalued entity, but it gives me Error 500, the failure on Server side, is the way i pass the array and then use it on server side correct? if not how could i pass and process it? here is the code for Client, Thanks in advance for your time:

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);
    }
}

Here is the Server Code:

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.length == 2){
        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.lenght == 2){
                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;
}

I get the following error:

Errore causata da: (SOAP-ENV:Protocol) :Unsupported response content type "text/html; charset=utf-8", must be: "text/xml". Response was:
<html><head><title>Apache Tomcat/7.0.14 - Error report</title><style><!--H1 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:22px;} H2 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:16px;} H3 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:14px;} BODY {font-family:Tahoma,Arial,sans-serif;color:black;background-color:white;} B {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;} P {font-family:Tahoma,Arial,sans-serif;background:white;color:black;font-size:12px;}A {color : black;}A.name {color : black;}HR {color : #525D76;}--></style> </head><body><h1>HTTP Status 500 - </h1><HR size="1" noshade="noshade"><p><b>type</b> Exception report</p><p><b>message</b> <u></u></p><p><b>description</b> <u>The server encountered an internal error () that prevented it from fulfilling this request.</u></p><p><b>exception</b> <pre>javax.servlet.ServletException: Error building response envelope: java.lang.NullPointerException
        org.apache.soap.server.http.RPCRouterServlet.doPost(RPCRouterServlet.java:418)
        javax.servlet.http.HttpServlet.service(HttpServlet.java:641)
        javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
</pre></p><p><b>note</b> <u>The full stack trace of the root cause is available in the Apache Tomcat/7.0.14 logs.</u></p><HR size="1"
2
Contributors
1
Reply
3
Views
6 Years
Discussion Span
Last Post by hag++
0

I'm not sure if it is just an issue with my browser but you're code is almost un-readable. One question I do have is why would someone be able to select both male and female? Another question is how did you generate your WSDL? I'm assuming you wrote the service for the server and then generated a WSDL off of that service. What is the value specified in the WSDL?

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.