基本 Web 服务中出现异常

发布于 2024-11-02 03:49:04 字数 2461 浏览 1 评论 0原文

我制作了一个网络服务,它只是显示数据库中的用户数据。但当我运行客户端时,我不断收到此异常。

由于异常而无法创建 SOAP 消息:XML 读取器错误:com.ctc.wstx.exc.WstxEOFException:意外的 EOF;期望 [row,col {unknown-source}] 处的元素有一个关闭标记:[1,110]

//////////////////////这是 Web 服务代码/// /////////////////////////////

@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 是一个 java bean ////////////////////这是客户端代码

    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 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///////////////////

    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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

心舞飞扬 2024-11-09 03:49:04

我要做的第一件事是确定这确实是客户端错误还是服务器错误。

使用 FiddlerWireshark拦截从客户端到服务器的流量,并检查 SOAP 请求是否有效。

您还没有说明您是在客户端还是服务器端收到异常,因此请求可能正常到达,但客户端没有读取响应正确地。

编辑:为了简化事情,您可能只想暂时对一些数据进行硬编码。它看起来不像是数据库代码本身的问题,因此只需删除所有这些即可使诊断变得更容易 - 只需硬编码几个要返回的名称...您甚至可能想要将其更改为返回 int,只是为了查看问题是否出在使用 ArrayList 上。

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.

£噩梦荏苒 2024-11-09 03:49:04

作为替代方案,如果您的 jdbc 提供程序支持,您可能希望从 Web 服务返回 WebRowSet。
这是一个示例

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

,这样您就可以摆脱正在使用的 SetData java bean。

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.

无声静候 2024-11-09 03:49:04

我遇到了同样的问题,我通过向我的项目添加一些缺失的工件来解决它。由于缺少工件,cxf 似乎无法在客户端填充消息中的有效负载:

<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:我使用单元测试类来调用 WS
cxf版本:2.4

希望有帮助!

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!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文