开发者

Getting Exception in basic webservice

I have made a webservice which is simply displaying a user data from a database. but i am keep on getting this exception when i run the client side.

Couldn't create SOAP message due to exception: XML reader error: com.ctc.wstx.exc.WstxEOFException: Unexpected EOF; was expecting a close tag for element at [row,col {unknown-source}]: [1,110]

/////////////////////This is webservice code////////////////////////////////

@WebMethod(operationName = "viewUserData")

public ArrayList viewUserData() {
    //TODO write your implementation code here:
    Statement stmt = null;
    ResultSet rs = null;
    String query = "";
    //ArrayList<HashMap> list = new ArrayList<HashMap>();
    ArrayList list = new ArrayList();

    try {
        String connectionURL = "jdbc:oracle:thin:@p5";
        Connection connection = null;
        Class.forName("oracle.jdbc.driver.OracleDriver");
        connection = DriverManager.getConnection(connectionURL, "backconnect", "backconnect");
        query = "select * from users";
        stmt = connection.createStatement();
        rs = stmt.executeQuery(query);

        while(rs.next()){
            /*HashMap<String,Object> map = new HashMap<String,Object>();
            map.put("USER_ID", rs.getString("USER_ID"));
            map.put("NAME", rs.getString("NAME"));
            map.put("SHORT_NAME", rs.getString("SHORT_NAME"));
            map.put("PASSWORD", rs.getString("PASSWORD"));*/
            SetData sdata = new SetData();
            sdata.setUSER_ID(rs.getString("USER_ID"));
            sdata.setNAME(rs.getString("NAME"));
            sdata.setSHORT_NAME(rs.getString("SHORT_NAME"));
            sdata.setPASSWORD(rs.getString("PASSWORD"));
            /*list.add(rs.getString("USER_ID"));
            list.add(rs.getString("NAME"));
            list.add(rs.getString("SHORT_NAME"));
            list.add(rs.getString("PASSWORD"));*/
            list.add(sdata);
        }
    } catch (Exception ex) {

        System.out.println(ex.getMessage());
    }
    return list;
} 

SetData is a java bean ////////////////////This is client code///////////////////

开发者_JS百科    package1.GetUserDataService service = new package1.GetUserDataService();
package1.GetUserData port = service.getGetUserDataPort();
// TODO process result here
java.util.List<java.lang.Object> result = port.viewUserData();
out.println("Result = "+result);

I am stuck into this. How to solve this.


The first thing I'd try to do is work out whether this is really a client error or a server error.

Use Fiddler or Wireshark to intercept the traffic from the client to the server, and check whether the SOAP request looks valid.

You haven't said whether you get the exception itself on the client side or the server side, so it's possible that the request is getting there okay, but the client isn't reading the response properly.

EDIT: To simplify things, you may want to just hard code some data for the moment. It doesn't look like the problem is within the database code itself, so make diagnostics easier by just removing all of that - just hard code a couple of names to return... you might even want to change it to return an int, just to see whether the problem is using an ArrayList.


As an alternative you may want to return a WebRowSet from your web service if your jdbc provider supports it. Here is an example

import javax.sql.rowset.WebRowSet;
import com.sun.rowset.WebRowSetImpl; // Reference implementation
...
// get ResultSet rs from db
WebRowSet webrowset = new WebRowSetImpl();
webrowset.populate(rs);
// return webrowset from web service

This way you can get rid of SetData java bean that you are using.


I have faced the same issue and I solved it by adding some missing artifacts to my project. It seems that cxf is not able to fill the payload in the message on the client side due to this missing artifacts:

<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-transports-http-jetty</artifactId>
<version>${cxf.version}</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>ezmorph</groupId>
        <artifactId>ezmorph</artifactId>
        <version>1.0.5</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>fife</groupId>
        <artifactId>rsyntaxtextarea</artifactId>
        <version>1.3.4</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>commons-httpclient</groupId>
        <artifactId>commons-httpclient</artifactId>
        <version>3.1</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>commons-cli</groupId>
        <artifactId>commons-cli</artifactId>
        <version>1.0</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>bouncycastle</groupId>
        <artifactId>bcprov-jdk15</artifactId>
        <version>143</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>jtidy</groupId>
        <artifactId>jtidy</artifactId>
        <version>r820</version>
        <scope>test</scope>
    </dependency>

PS: i used unit test class to call the WS cxf version: 2.4

Hope it helps!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜