【问题标题】:Web Services using Java on NetBeans在 NetBeans 上使用 Java 的 Web 服务
【发布时间】:2011-11-23 17:34:36
【问题描述】:

这段代码完全错误吗?我正在为一个 uni 项目制作web service。是否可以在 web service 方法中连接到数据库。 连接代码在标准 SE 项目中有效,但在 Web 服务中 NetBeans 不允许我部署项目,它说它无法创建 WSDL

/* * 要更改此模板,请选择工具 |模板 * 并在编辑器中打开模板。 */ 包 org.me.calculator;

 import com.mysql.jdbc.Statement;
 import java.sql.Connection;
 import java.sql.DriverManager;
 import java.sql.SQLException;
 import javax.jws.WebService;
 import javax.jws.WebMethod;
 import javax.jws.WebParam;
 import javax.ejb.Stateless;

 /**
 *
 * @author ericman
  */
  @WebService(serviceName = "CalculatorWS")
  @ Stateless()
  public class CalculatorWS {


/**
 * Web service operation
 */
@WebMethod(operationName = "UppDateBook")
public String UppDateBook(@WebParam(name = "name") String name) throws SQLException {
    //TODO write your implementation code here:
    Connection con = DriverManager.getConnection("jdbc:mysql://localhost/bookcatalog","ericman","ericman");
    Statement stmt = (Statement) con.createStatement();
    String insert = "INSERT INTO `bookcatalog`.`books` (`name`, `isbn`, `price`, `publisher`, `img`) VALUES ('BookOne', '12456789', '45', 'publisher', 'httpfile');";
    int numUpdate = stmt.executeUpdate(insert);
    stmt.close();
    return null;
}

}

错误信息

严重:无法找到端点的适配器 警告:MEX0008:无法使用协议 SOAP_1_1 解析从位于 http://localhost:8080/WebSercviceOne/WebSercviceOne?WSDL/mex 的服务器返回的元数据。不断尝试。 信息:[错误] 服务器返回 HTTP 响应代码:405 用于 URL:http://localhost:8080/WebSercviceOne/WebSercviceOne?WSDL 读取WSDL文档失败:http://localhost:8080/WebSercviceOne/WebSercviceOne?WSDL,因为1)找不到文档; /2) 文件无法读取; 3) 文档的根元素不是 . INFO: [ERROR] failed.noservice=在提供的 WSDL(s) 中找不到 wsdl:service: 需要提供至少一个具有至少一个服务定义的 WSDL。 信息:无法解析 WSDL。 信息:使用 http://localhost:8080/WebSercviceOne/WebSercviceOne?WSDL 调用 wsimport 严重:wsimport 失败 信息: Metro 监控 rootname 成功设置为:amx:pp=/mon/server-mon[server],type=WSEndpoint,name=WebServiceOne-WebServiceOnePort 警告:容器 org.glassfish.webservices.JAXWSContainer@7339ea2c 不支持类 com.sun.xml.ws.api.server.Module 信息:WS00019:已部署 EJB 端点 ServiceOne 监听地址http://ericman-PC:8080/WebSercviceOne/WebSercviceOne 信息:WEB0671:在 [/ServiceOne] 加载应用程序 [ServiceOne] INFO:ServiceOne 在 511 毫秒内成功部署。 信息:解析 WSDL...

【问题讨论】:

  • WebServices 可以肯定地访问数据库,我自己做的。我们需要有关异常的更多详细信息。也许堆栈跟踪可以提供帮助?我真的怀疑这就是失败的原因。
  • Error generating artifacts for the following WSDL http://localhost:8080/CalculatorWS/CalculatorWS?WSDL Possible causes can be invoking https when the application is not configured for security 这是我尝试测试 Web 服务时告诉我的内容
  • 注意:你应该注入 DataSource/EntityManager。不要调用 DriverManager.getConnection。
  • 注意:遵守 Java 命名约定:方法名以小写开头。
  • "但是当在 Web 服务中 NetBeans 不允许我部署项目时,它说它无法创建 WSDL。"你能进一步解释一下吗?您如何部署 WebService?

标签: java mysql web-services netbeans


【解决方案1】:

您不能以这种方式抛出异常,您需要根据以下几点创建自己的异常: 1)您的自定义异常是一个扩展异常的类。 2) 将标签 @WebFault(name="exception name") 添加到您的异常类 3) 创建一个保存异常消息的 bean,该 bean 有一个带有所有构造函数和一个 getter 的 String 参数。 4)您的异常类需要具有该 bean 的属性。 5) 必须有两个构造函数,一个带有消息和 bean 的实例,另一个带有消息,bean 的实例和 Throwable 对象代表问题。

【讨论】:

    猜你喜欢
    • 2014-05-24
    • 2016-04-07
    • 1970-01-01
    • 1970-01-01
    • 2023-03-13
    • 2014-01-26
    • 1970-01-01
    • 1970-01-01
    • 2015-09-02
    相关资源
    最近更新 更多