You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-user@axis.apache.org by Pierre Lasante <pi...@sympatico.ca> on 2004/11/28 16:44:09 UTC

Problem Deserializing a vector

Hi, this is the message I get each time I run the client:

AxisFault
 faultCode: {http://schemas.xmlsoap.org/soap/envelope/}Server.userException
 faultSubcode:
 faultString: java.lang.NullPointerException
 faultActor:
 faultNode:
 faultDetail:
        {http://xml.apache.org/axis/}hostname:pierre

java.lang.NullPointerException
        at org.apache.axis.message.SOAPFaultBuilder.createFault(SOAPFaultBuilder.java:221)
        at org.apache.axis.message.SOAPFaultBuilder.endElement(SOAPFaultBuilder.java:128)
        at org.apache.axis.encoding.DeserializationContext.endElement(DeserializationContext.java:1077)
        at org.apache.crimson.parser.Parser2.maybeElement(Unknown Source)
        at org.apache.crimson.parser.Parser2.content(Unknown Source)
        at org.apache.crimson.parser.Parser2.maybeElement(Unknown Source)
        at org.apache.crimson.parser.Parser2.content(Unknown Source)
        at org.apache.crimson.parser.Parser2.maybeElement(Unknown Source)
        at org.apache.crimson.parser.Parser2.parseInternal(Unknown Source)
        at org.apache.crimson.parser.Parser2.parse(Unknown Source)
        at org.apache.crimson.parser.XMLReaderImpl.parse(Unknown Source)
        at javax.xml.parsers.SAXParser.parse(Unknown Source)
        at org.apache.axis.encoding.DeserializationContext.parse(DeserializationContext.java:225)
        at org.apache.axis.SOAPPart.getAsSOAPEnvelope(SOAPPart.java:645)
        at org.apache.axis.Message.getSOAPEnvelope(Message.java:424)
        at org.apache.axis.handlers.soap.MustUnderstandChecker.invoke(MustUnderstandChecker.java:62)
        at org.apache.axis.client.AxisClient.invoke(AxisClient.java:173)
        at org.apache.axis.client.Call.invokeEngine(Call.java:2737)
        at org.apache.axis.client.Call.invoke(Call.java:2720)
        at org.apache.axis.client.Call.invoke(Call.java:2396)
        at org.apache.axis.client.Call.invoke(Call.java:2319)
        at org.apache.axis.client.Call.invoke(Call.java:1776)
        at localhost.axis.TxResultSet_jws.TxResultSetSoapBindingStub.getCoffee(TxResultSetSoapBindingStub.java:100)
        at TxResultSetClient.main(TxResultSetClient.java:20)

Here is the client code:

import javax.xml.rpc.ServiceException;
import localhost.axis.TxResultSet_jws.*;
import java.util.Vector;
import java.util.ListIterator;

public class TxResultSetClient
{
    public static void main(String [] args)
    {
        localhost.axis.TxResultSet_jws.TxResultSet service;
        try {
            service = new TxResultSetServiceLocator().getTxResultSet();
            // getCoffee is in RxResultSet.jws and will return a Vector
            Vector v = service.getCoffee();
            // show the data from Sybase
            ListIterator iter = v.listIterator();
            while(iter.hasNext()) {
                System.out.println(iter.next());
            }
        } catch (ServiceException e) {
            e.printStackTrace();
        } catch (RemoteException e) {
            e.printStackTrace();
        }
    }
}

Here is the service code:

import java.util.Vector;
import java.util.ListIterator;
import java.io.*;
import java.sql.*;
import javax.sql.*;

public class TxResultSet{
    public static Connection con;
    public static Statement stmt;
    public static ResultSet rs;
    public static Vector v;

    public Vector getCoffee() {

        try {
            Class.forName("com.sybase.jdbc.SybDriver").newInstance();
            con = DriverManager.getConnection("jdbc:sybase:Tds:localhost:2638?ServiceName=asademo","dba","sql");
            stmt = con.createStatement();
            rs =  stmt.executeQuery("SELECT COF_NAME, PRICE FROM COFFEES");
        } catch(Exception e) {
            System.out.println("Something went wrong: " + e.getMessage());
        }

        try {
            v = new Vector();
            while( rs.next() )    {
                Vector row = new Vector();
                row.add(rs.getString("COF_NAME"));
                row.add(rs.getString("PRICE"));
                v.add(row);
           }
        } catch(SQLException se) {
            System.out.println("Bad vector: " + se.getMessage());
        }

        try {
            rs.close();
            stmt.close();
            con.close();
        } catch(Exception e) {
            System.out.println("Bad rs stmt or con" + e.getMessage());
        }

        return v;
    }
}

I thought Apache Axis knew how to handle Vector and that it was not necessary to learn how to handle
serialization and deserialization.

I deployed my service by copying the code to the axis folder with a .jws extension and I created the stubs with the
org.apache.axis.wsdl.WSDL2Java http://localhost:8080/axis/TxResultSet.jws?WSDL

Any suggestion would be appreciated as to what went wrong.

Regards.