Results 1 to 17 of 17
  1. #1
    rubikk is offline Member
    Join Date
    Jul 2011
    Posts
    8
    Rep Power
    0

    Default Deserialization problems

    Hi everybody, hoping that this is the correct section I've a problem that need to resolve and don't know how to do.
    I'm writing a web service that read an xml file and print some of the information. To do so after the parsing the objects of xml are saved into two beans.

    This is an XML fragment:
    Java Code:
        <?xml version="1.0" encoding="UTF-8"?>
    <prodotti>
    	<prodotto id="01"> 
    		<nome>Navel</nome> 
    		<categoria>Arance</categoria> 
    		<pezzatura> 
    			<confezione tipo = "cassa" peso = "15" prezzo= "15"/> 
    			<confezione tipo = "sacchetto" peso = "3" prezzo="6"/> 
    			<confezione tipo = "plateau" peso = "10" prezzo="12"/> 
    		</pezzatura> 
    	</prodotto> 
    	<prodotto id="02"> 
    		<nome>Tarocco</nome> 
    		<categoria>Arance</categoria> 
    		<pezzatura> 
    			<confezione tipo = "cassa" peso = "15" prezzo= "17"/> 
    			<confezione tipo = "sacchetto" peso = "3" prezzo="7"/> 
    			<confezione tipo = "plateau" peso = "10" prezzo="14"/> 
    		</pezzatura> 
    	</prodotto> 
    	<prodotto id="03"> 
    		<nome>Limoni_di_Sorrento</nome> 
    		<categoria>Limoni</categoria> 
    		<pezzatura> 
    			<confezione tipo = "sacchetto" peso = "3" prezzo="7.50"/> 
    			<confezione tipo = "plateau" peso = "7" prezzo="14"/> 
    		</pezzatura> 
    	</prodotto> 	
    	<prodotto id="04"> 
    		<nome>Clementine</nome> 
    		<categoria>Mandarini</categoria> 
    		<pezzatura> 
    			<confezione tipo = "cassa" peso = "10" prezzo= "13"/> 
    			<confezione tipo = "plateau" peso = "5" prezzo="7.50"/> 
    		</pezzatura> 
    	</prodotto> 	
    	<prodotto id="05"> 
    		<nome>Limoni_sfusi</nome> 
    		<categoria>Limoni</categoria> 
    		<pezzatura> 
    			<confezione tipo = "sacchetto" peso = "3" prezzo="5"/> 
    			<confezione tipo = "plateau" peso = "7" prezzo="7.50"/> 
    		</pezzatura> 
    	</prodotto> 	
    	<prodotto id="06"> 
    		<nome>Mandarini</nome> 
    		<categoria>Mandarini</categoria> 
    		<pezzatura> 
    			<confezione tipo = "cassa" peso = "10" prezzo= "13"/> 
    			<confezione tipo = "plateau" peso = "5" prezzo="7.50"/> 
    		</pezzatura> 
    	</prodotto> 	
    	<prodotto id="07">
    		<nome>Arance_da_giardino T</nome> 
    		<categoria>Arance</categoria> 
    		<pezzatura> 
    			<confezione tipo = "cassa" peso = "15" prezzo= "15"/> 
    			<confezione tipo = "sacchetto" peso = "3" prezzo="5"/> 
    		</pezzatura> 
    	</prodotto> 	
    </prodotti>
    And those are the two beans:
    Java Code:
    public class Prodotto {
    	
    	private int id;
    	private String nome;
    	private String categoria;
    	private Confezione[] confezioni;
    	
    	public int getID() {
    		return id;
    	}
    	public void setID(int i) {
    		id = i;
    	}
    	
    	public String getNome() {
    		return nome;
    	}
    	public void setNome(String n) {
    		nome = n;
    	}
    	
    	public String getCategoria() {
    		return categoria;
    	}
    	public void setCategoria(String c) {
    		categoria = c;
    	}
    	
    	public Confezione[] getConfezione() {
    		return confezioni;
    	}
    	public void setConfezioni(Confezione[] conf) {
    		confezioni = conf;
    	}
    }
    and:
    Java Code:
        public class [B]Confezione [/B]{  
          
            String tipo;  
            int peso;  
            float prezzo;  
              
            public String getTipo() {  
                return tipo;  
            }  
            public void setTipo(String t) {  
                tipo = t;  
            }  
              
            public int getPeso() {  
                return peso;  
            }  
            public void setPeso(int p) {  
                peso = p;  
            }  
              
            public float getPrezzo() {  
                return prezzo;  
            }  
            public void setPrezzo(float pr) {  
                prezzo = pr;  
            }  
              
        }
    Here is the code where the parsing is executed:
    Java Code:
        public class [B]ProdottoDB[/B] {  
          
            Prodotto[] prodotti;  
            Confezione[] confezioni;  
          
            public ProdottoDB(Document doc) throws Exception {  
                NodeList list = doc.getElementsByTagName("prodotto");  
                int length = list.getLength();  
                prodotti = new Prodotto[length];  
                Prodotto p = null;  
          
                for (int i = 0; i < length; i++) {  
                    Element elem = (Element)list.item(i);  
          
                    p = new Prodotto();  
                    p.setID(Integer.parseInt(elem.getAttribute("id")));  
                    p.setNome(getValue(elem, "nome"));  
                    p.setCategoria(getValue(elem, "categoria"));  
          
                      
                    NodeList listConf = elem.getElementsByTagName("confezione");  
                    confezioni = new Confezione[listConf.getLength()];  
                      
                    for (int j = 0; j < listConf.getLength(); j++) {  
                        Element elemConf = (Element)listConf.item(j);  
          
                        Confezione c = new Confezione();  
                        c.setTipo(elemConf.getAttribute("tipo"));  
                        c.setPrezzo(Float.parseFloat(elemConf.getAttribute("prezzo")));  
                        c.setPeso(Integer.parseInt(elemConf.getAttribute("peso")));  
          
                        confezioni[j] = c;  
                        System.out.println("confezioni");  
                    }  
          
                    p.setConfezioni(confezioni);  
                    prodotti[i] = p;  
                }  
            }  
          
            public Prodotto[] getProdotti() {  
                return prodotti;  
            }  
          
            public float getPrezzo(int id, String categoria) {  
                for (int i = 0; i < prodotti.length; i++) {  
                    if (id == prodotti[i].getID()) {  
                        Confezione[] c = prodotti[i].getConfezione();  
                        for (int j=0; j<c.length; j++) {  
                            if (categoria.equals(c[j].getTipo()))  
                                return c[j].getPrezzo();  
                        }  
                    }  
                }  
                return -1;  
            }  
          
            /* 
             * Legge il valore di un nodo Element  
             */  
            private String getValue(Element elem, String name) {  
                NodeList l = elem.getElementsByTagName(name);  
                if (l == null || l.getLength() == 0)  
                    return null;  
                elem = (Element)l.item(0);  
                return elem.getFirstChild().getNodeValue();  
            }  
        }
    The client is:
    Java Code:
        public class [B]TerramicaClient[/B] {  
          
            public static void main(String[] args) throws Exception {  
          
                BufferedReader console = new BufferedReader(new InputStreamReader(System.in));  
          
                System.out.println("Scegliere l'operazione da eseguire: ");  
          
                System.out.println("1 - Elenco prodotti: ");   
                System.out.println("2 - Ricerca prezzo: ");  
                int sel = Integer.parseInt(console.readLine());  
                //  
                //System.out.println("I prodotti non sono disponibili");  
          
                if (sel==1) {  
                    ArrayList<Prodotto> prods = elenca();  
                    for (Prodotto p : prods) {  
                        System.out.println("ID: " + p.getID());  
                        System.out.println("Categoria: " + p.getCategoria());  
                        System.out.println("Nome: " + p.getNome());  
          
                        Confezione[] confs = p.getConfezione();  
                        for (int i=0; i<confs.length; i++) {  
                            System.out.println("Tipo confezione: " + confs[i].getTipo());  
                            System.out.println("Peso confezione: " + confs[i].getPeso());  
                            System.out.println("Prezzo confezione: " + confs[i].getPrezzo());  
                        }  
                    }  
                }  
                  
                if (sel==2) {  
                    System.out.println("ID?: ");  
                    int id = Integer.parseInt(console.readLine());  
                    System.out.println("Tipo?: ");  
                    String tipo = console.readLine();  
                      
                    float res = prezzo(id, tipo);  
                      
                    System.out.println("Prezzo: " + res);  
                }  
            }  
          
            private static ArrayList<Prodotto> elenca() throws Exception {  
          
                ArrayList<Prodotto> prs = new ArrayList<Prodotto>();  
          
                ServiceClient serviceClient = new ServiceClient();  
          
                OMFactory fac = OMAbstractFactory.getSOAP12Factory();  
                OMNamespace omNs = fac.createOMNamespace("http://www.terramica.it", "tns");  
                OMElement method = fac.createOMElement("elenco", omNs);  
          
                Options options = serviceClient.getOptions();  
                EndpointReference targetEPR = new EndpointReference("http://localhost:8081/axis2/services/TerramicaService");  
                options.setSoapVersionURI(Constants.URI_SOAP12_ENV);  
                options.setTo(targetEPR);   
          
                // invocazione del servizio utilizzando la MEP in-out  
                OMElement result = serviceClient.sendReceive(method);  
          
                // recupera il risultato  
                Iterator values = result.getChildrenWithName(new QName("http://service.terramica.it", "return"));  
                while (values.hasNext()) {  
                    OMElement omElement = (OMElement) values.next();  
                    Prodotto prod = (Prodotto) BeanUtil.deserialize(Prodotto.class, omElement, new DefaultObjectSupplier(), "prodotto");  
                    prs.add(prod);  
                }  
                return prs;  
            }  
          
            private static float prezzo(int id, String categoria) throws Exception {  
          
                ServiceClient serviceClient = new ServiceClient();  
          
                OMFactory fac = OMAbstractFactory.getSOAP12Factory();  
                OMNamespace omNs = fac.createOMNamespace("http://service.terramica.it", "tns");  
          
                OMElement method = fac.createOMElement("prezzo", omNs);  
                OMElement arg0 = fac.createOMElement("id", omNs);  
                arg0.addChild(fac.createOMText(arg0, String.valueOf(id)));  
                method.addChild(arg0);  
                OMElement arg1 = fac.createOMElement("tipo", omNs);  
                arg1.addChild(fac.createOMText(arg1, categoria));  
                method.addChild(arg1);  
          
                Options options = serviceClient.getOptions();  
                EndpointReference targetEPR = new EndpointReference("http://localhost:8081/axis2/services/TerramicaService");  
                options.setSoapVersionURI(Constants.URI_SOAP12_ENV);  
                options.setTo(targetEPR);   
          
                // invocazione del servizio utilizzando la MEP in-out  
                OMElement result = serviceClient.sendReceive(method);  
          
                // recupera il risultato  
                float response = Float.parseFloat(result.getFirstElement().getText());  
          
                return response;  
            }  
        }
    And the server side code:
    Java Code:
    public class [B]TerramicaService[/B] {
    
    	private static String file = "Terramica/ProdottiTerramica.xml";
    
    	public static Prodotto[] elenco() throws Exception {
    
    		System.out.println("entro in elenco");
    		MessageContext msgCtx =  MessageContext.getCurrentMessageContext(); 
    		ServletContext ctx = (ServletContext) msgCtx.getProperty(HTTPConstants.MC_HTTP_SERVLETCONTEXT);
    		String rpath = ctx.getRealPath(file);
    
    		BufferedInputStream in = new BufferedInputStream(new FileInputStream(rpath));
    		DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    		factory.setNamespaceAware(true);
    		DocumentBuilder builder = factory.newDocumentBuilder();
    		Document doc = builder.parse(in);
    
    		System.out.println("creo il database di prodotti");
    		ProdottoDB db = new ProdottoDB(doc);
    		Prodotto[] prod = db.getProdotti();
    		return prod;
    	}
    
    	public float prezzo(int id, String tipo) throws Exception {
    		MessageContext msgCtx =  MessageContext.getCurrentMessageContext(); 
    		ServletContext ctx = (ServletContext) msgCtx.getProperty(HTTPConstants.MC_HTTP_SERVLETCONTEXT);
    		String rpath = ctx.getRealPath(file);
    
    		BufferedInputStream in = new BufferedInputStream(new FileInputStream(rpath));
    		DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    		factory.setNamespaceAware(true);
    		DocumentBuilder builder = factory.newDocumentBuilder();
    		Document doc = builder.parse(in);
    
    		ProdottoDB db = new ProdottoDB(doc);
    		float prezzo = db.getPrezzo(id, tipo);
    		return prezzo;
    	}
    }
    Unfortunately the client execution of the "elenca" operation is
    ID: 1
    Categoria: Arance
    Nome: Navel
    Exception in thread "main"
    java.lang.NullPointerException
    at it.terramica.client.TerramicaClient.main(Terramica Client.java:46)

    I think that can be a problem related with the deserialize method used in the client. Some like "I know how to deserialize prodotto type but I don't know how to handle confezione type"...
    Can anyone help me understanding if this is the problem and, in case, how can I fix it in the simplest way? :)

    Thank you!!!
    Last edited by rubikk; 07-01-2011 at 06:29 PM.

  2. #2
    d3n1s is offline Member
    Join Date
    Apr 2011
    Posts
    69
    Rep Power
    0

    Default

    I had this issue when one of my classes did not implement serializable. Make them implement Serializable and see if it works.

  3. #3
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,403
    Rep Power
    25

    Default

    Terramica Client.java:46)
    First find what object reference/variable on line 46 of Client.java is null?
    Then why is it null?

  4. #4
    rubikk is offline Member
    Join Date
    Jul 2011
    Posts
    8
    Rep Power
    0

    Default

    I think that the problem is in the creation of the array named confs, but the problem is that I don't find the reason why the results are null.
    If it can help I can also post the SOAP message exchange...

    And, d3n1s, the serialization method I use is part of org.apache.axis2.databinding.utils.BeanUtil, so I don't think there's need of making the classes implement Serializable (am I wrong?)
    Last edited by rubikk; 07-01-2011 at 04:08 PM.

  5. #5
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,403
    Rep Power
    25

    Default

    I think that the problem is ...
    What variable is null? Why is it null?
    Trace back through your code to see why.

  6. #6
    rubikk is offline Member
    Join Date
    Jul 2011
    Posts
    8
    Rep Power
    0

    Default

    The problem is that server side the code works (the code for getting and printing the price of one element give the correct result) so I think that the error is in the client class.
    Now, every "Prodotto" object also has an array of "Confezione" objects. And the problem is in this array, I think. For this I've said that maybe can be a problem of the serialization method.

    Just for completeness, that are the SOAP messages: the request
    POST /axis2/services/TerramicaService HTTP/1.1
    Content-Type: application/soap+xml; charset=UTF-8; action="urn:anonOutInOp"
    User-Agent: Axis2
    Host: 127.0.0.1:8081
    Transfer-Encoding: chunked

    d2
    <?xml version='1.0' encoding='UTF-8'?>
    <soapenv:Envelope xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope">
    <soapenv:Body>
    <tns:elenco xmlns:tns="http://www.terramica.it" />
    </soapenv:Body>
    </soapenv:Envelope>0

    and the response
    HTTP/1.1 200 OK
    Server: Apache-Coyote/1.1
    Content-Type: application/soap+xml; action="urn:elencoResponse";charset=UTF-8
    Transfer-Encoding: chunked
    Date: Fri, 01 Jul 2011 14:34:38 GMT

    1094
    <?xml version='1.0' encoding='UTF-8'?>
    <soapenv:Envelope xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope">
    <soapenv:Body>
    <ns:elencoResponse xmlns:ns="http://service.terramica.it" xmlns:ax27="http://data.terramica.it/xsd">
    <ns:return xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ax27:Prodotto">
    <ax27:ID>1</ax27:ID>
    <ax27:categoria>Arance</ax27:categoria>
    <ax27:confezione xsi:type="ax27:Confezione">
    <ax27:peso>15</ax27:peso>
    <ax27:prezzo>15.0</ax27:prezzo>
    <ax27:tipo>cassa</ax27:tipo>
    </ax27:confezione>
    <ax27:confezione xsi:type="ax27:Confezione">
    <ax27:peso>3</ax27:peso>
    <ax27:prezzo>6.0</ax27:prezzo>
    <ax27:tipo>sacchetto</ax27:tipo>
    </ax27:confezione>
    <ax27:confezione xsi:type="ax27:Confezione">
    <ax27:peso>10</ax27:peso>
    <ax27:prezzo>12.0</ax27:prezzo>
    <ax27:tipo>plateau</ax27:tipo>
    </ax27:confezione>
    <ax27:confezioni xsi:nil="true" />
    <ax27:nome>Navel</ax27:nome>
    </ns:return>
    <ns:return xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ax27:Prodotto">
    <ax27:ID>2</ax27:ID>
    <ax27:categoria>Arance</ax27:categoria>
    <ax27:confezione xsi:type="ax27:Confezione">
    <ax27:peso>15</ax27:peso>
    <ax27:prezzo>17.0</ax27:prezzo>
    <ax27:tipo>cassa</ax27:tipo>
    </ax27:confezione>
    <ax27:confezione xsi:type="ax27:Confezione">
    <ax27:peso>3</ax27:peso>
    <ax27:prezzo>7.0</ax27:prezzo>
    <ax27:tipo>sacchetto</ax27:tipo>
    </ax27:confezione>
    <ax27:confezione xsi:type="ax27:Confezione">
    <ax27:peso>10</ax27:peso>
    <ax27:prezzo>14.0</ax27:prezzo>
    <ax27:tipo>plateau</ax27:tipo>
    </ax27:confezione>
    <ax27:confezioni xsi:nil="true" />
    <ax27:nome>Tarocco</ax27:nome>
    </ns:return>
    <ns:return xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ax27:Prodotto">
    <ax27:ID>3</ax27:ID>
    <ax27:categoria>Limoni</ax27:categoria>
    <ax27:confezione xsi:type="ax27:Confezione">
    <ax27:peso>3</ax27:peso>
    <ax27:prezzo>7.5</ax27:prezzo>
    <ax27:tipo>sacchetto</ax27:tipo>
    </ax27:confezione>
    <ax27:confezione xsi:type="ax27:Confezione">
    <ax27:peso>7</ax27:peso>
    <ax27:prezzo>14.0</ax27:prezzo>
    <ax27:tipo>plateau</ax27:tipo>
    </ax27:confezione>
    <ax27:confezioni xsi:nil="true" />
    <ax27:nome>Limoni_di_Sorrento</ax27:nome>
    </ns:return>
    <ns:return xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ax27:Prodotto">
    <ax27:ID>4</ax27:ID>
    <ax27:categoria>Mandarini</ax27:categoria>
    <ax27:confezione xsi:type="ax27:Confezione">
    <ax27:peso>10</ax27:peso>
    <ax27:prezzo>13.0</ax27:prezzo>
    <ax27:tipo>cassa</ax27:tipo>
    </ax27:confezione>
    <ax27:confezione xsi:type="ax27:Confezione">
    <ax27:peso>5</ax27:peso>
    <ax27:prezzo>7.5</ax27:prezzo>
    <ax27:tipo>plateau</ax27:tipo>
    </ax27:confezione>
    <ax27:confezioni xsi:nil="true" />
    <ax27:nome>Clementine</ax27:nome>
    </ns:return>
    <ns:return xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ax27:Prodotto">
    <ax27:ID>5</ax27:ID>
    <ax27:categoria>Limoni</ax27:categoria>
    <ax27:confezione xsi:type="ax27:Confezione">
    <ax27:peso>3</ax27:peso>
    <ax27:prezzo>5.0</ax27:prezzo>
    <ax27:tipo>sacchetto</ax27:tipo>
    </ax27:confezione>
    <ax27:confezione xsi:type="ax27:Confezione">
    <ax27:peso>7</ax27:peso>
    <ax27:prezzo>7.5</ax27:prezzo>
    <ax27:tipo>plateau</ax27:tipo>
    </ax27:confezione>
    <ax27:confezioni xsi:nil="true" />
    <ax27:nome>Limoni_sfusi</ax27:nome>
    </ns:return>
    <ns:return xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ax27:Prodotto">
    <ax27:ID>6</ax27:ID>
    <ax27:categoria>Mandarini</ax27:categoria>
    <ax27:confezione xsi:type="ax27:Confezione">
    <ax27:peso>10</ax27:peso>
    <ax27:prezzo>13.0</ax27:prezzo>
    <ax27:tipo>cassa</ax27:tipo>
    </ax27:confezione>
    <ax27:confezione xsi:type="ax27:Confezione">
    <ax27:peso>5</ax27:peso>
    <ax27:prezzo>7.5</ax27:prezzo>
    <ax27:tipo>plateau</ax27:tipo>
    </ax27:confezione>
    <ax27:confezioni xsi:nil="true" />
    <ax27:nome>Mandarini</ax27:nome>
    </ns:return>
    <ns:return xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ax27:Prodotto">
    <ax27:ID>7</ax27:ID>
    <ax27:categoria>Arance</ax27:categoria>
    <ax27:confezione xsi:type="ax27:Confezione">
    <ax27:peso>15</ax27:peso>
    <ax27:prezzo>15.0</ax27:prezzo>
    <ax27:tipo>cassa</ax27:tipo>
    </ax27:confezione>
    <ax27:confezione xsi:type="ax27:Confezione">
    <ax27:peso>3</ax27:peso>
    <ax27:prezzo>5.0</ax27:prezzo>
    <ax27:tipo>sacchetto</ax27:tipo>
    </ax27:confezione>
    <ax27:confezioni xsi:nil="true" />
    <ax27:nome>Arance_da_giardino T</ax27:nome>
    </ns:return>
    </ns:elencoResponse>
    </soapenv:Body>
    </soapenv:Envelope>0

  7. #7
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,403
    Rep Power
    25

    Default

    I think that the error is in the client class.
    Are you talking about the cause of the NullPointerException?
    Have you tracked the NPE exception back to where the code is failing to produce a non-null value?

  8. #8
    rubikk is offline Member
    Join Date
    Jul 2011
    Posts
    8
    Rep Power
    0

    Default

    Maybe we don't understand each other (I have to apologize for my english), but let's try again.
    Yes, the NPE is generated by the class TerramicaClient. In the main of this class the results of method elenca() are saved into an ArrayList.

    elenca() save the results into an OMElement, and the method getChildrenWithName extract from the OMElement the object named return (as in the SOAP response message).
    Then the deserialize method convert this results into objects of type Prodotto. And here is the problem, I think. The object Prodotto has 4 variables:
    private int id;
    private String nome;
    private String categoria;
    private Confezione[] confezioni;

    The first three are correctly saved, the array not. So I think that there's some problem in deserialization of Confezione object but I don't know how to fix that.

  9. #9
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,403
    Rep Power
    25

    Default

    the array not
    Why is the array confezioni not correctly saved? Where is the array created and where are values stored into it?
    Is this line being executed?
    Java Code:
    confezioni = new Confezione[listConf.getLength()]; //<<<< Creates the array
    Is this line being executed:
    Java Code:
    p.setConfezioni(confezioni);

  10. #10
    rubikk is offline Member
    Join Date
    Jul 2011
    Posts
    8
    Rep Power
    0

    Default

    Ok. I've made several tries. The first code line is executed correctly. The array is created when the constructor of ProdottoDB class is called into the elenco() method of TerramicaService class. The array is an Array of Confezione type objects, and the type Confezione is a bean with three variables (tipo, peso, prezzo) that contains the values of attributes of the tag confezione (see XML file).

    I think that the problem is in this section of code (is a part of TerramicaClient class):

    Java Code:
    Confezione[] confs = p.getConfezione();
    System.out.println("dim " + confs.length);
    for (int i=0; i<confs.length; i++) {
    	System.out.println("Tipo confezione: " + confs[i].getTipo());
    	System.out.println("Peso confezione: " + confs[i].getPeso());
    	System.out.println("Prezzo confezione: " + confs[i].getPrezzo());
    }
    If I comment those lines the service is executed correctly, but I really don't understand why this portion of code doesn't works (I can also send the zip file of the eclipse project if looking at it can make you more clear what the situation is).

    (By the way, thank you so much for your patience :) )

  11. #11
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,403
    Rep Power
    25

    Default

    What does this print out?
    System.out.println("dim " + confs.length);

    Does this line work ok?
    Prodotto prod = (Prodotto) BeanUtil.deserialize(Prodotto.class, omElement, new DefaultObjectSupplier(), "prodotto");

    Have you tried printing out the contents of prod?
    Last edited by Norm; 07-01-2011 at 06:33 PM.

  12. #12
    rubikk is offline Member
    Join Date
    Jul 2011
    Posts
    8
    Rep Power
    0

    Default

    The first line doesn't print anything, is the line that generates the null pointer exception.

    prod print well the data of Prodotto types but not the data of Confezione type. And with that we return to the starting point. I think that deserialize for some reason don't work as I wish, but I don't know how to change it or what to use to access the results of web service invocation.

  13. #13
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,403
    Rep Power
    25

    Default

    Then this is the line that is giving you the trouble:

    Prodotto prod = (Prodotto) BeanUtil.deserialize(Prodotto.class, omElement, new DefaultObjectSupplier(), "prodotto");

    Have you tried what was suggested in post#2?

  14. #14
    rubikk is offline Member
    Join Date
    Jul 2011
    Posts
    8
    Rep Power
    0

    Default

    Yes, I think...

    As I said answering d3n1s, my service doesn't use java.io.Serializable interface, instead my serialize method is part of the class org.apache.axis2.databinding.utils.BeanUtil, so unfortunately I don't think that this is a solution. :(

  15. #15
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,403
    Rep Power
    25

    Default

    Perhaps you should try to isolate the problem by writing a small program with only the Prodotto class and the call to BeanUtil.deserialize.
    If you could have your xml file as a local file and have the BeanUtil.deserialize method get its contents from there.
    That would make it easier to change different parts to see where the problem is.

  16. #16
    rubikk is offline Member
    Join Date
    Jul 2011
    Posts
    8
    Rep Power
    0

    Default

    I'm pretty sure that the problem is in the deserialization operation. Also because if I delete the part of code that access to "confezioni" array all the service works well. I don't know if the deserialize method can work also with complex return types or I've to search another method of working with the results. I will continue searching information :)

    Norm, thanks for your help and, above all, for your patience.

  17. #17
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,403
    Rep Power
    25

    Default

    Good luck. I don't have the BeanUtil and other classes to be able to test any of it.

Similar Threads

  1. Exception in object deserialization
    By hanx in forum Advanced Java
    Replies: 3
    Last Post: 03-01-2011, 07:13 PM
  2. Singleton serialization / deserialization
    By DerekRaimann in forum New To Java
    Replies: 4
    Last Post: 02-28-2011, 01:38 AM
  3. [SOLVED] Deserialization question
    By xcallmejudasx in forum New To Java
    Replies: 3
    Last Post: 04-14-2009, 12:15 AM
  4. Serialization/Deserialization Error
    By andrepezzo in forum Advanced Java
    Replies: 2
    Last Post: 12-16-2008, 05:36 PM
  5. Serialization/Deserialization Error
    By andrepezzo in forum Networking
    Replies: 0
    Last Post: 12-16-2008, 04:21 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •