【问题标题】:Error when connect web services deployed on tomcat?连接部署在 tomcat 上的 Web 服务时出错?
【发布时间】:2014-01-23 11:01:26
【问题描述】:

我已经在我的本地主机中安装了 Tomcat 7.0 和 Netbeans IDE 7.4, 我创建了一个 JSF 2.2 Web 应用程序,在这个项目中我创建了一个 Web 服务名称 ChargingGateway 有一个这样的 WebMethod:

@WebMethod(operationName = "LoginandCharging")
    public String LoginandCharging(@WebParam(name = "usernameVMG") String txtusernameVMG,@WebParam(name = "passwordVMG") String txtpasswordVMG,@WebParam(name = "servicename") String txtservicename, @WebParam(name = "serial") String txtserial, @WebParam(name = "pin") String txtpin, @WebParam(name = "cardtype") String txtcardtype) throws JSONException, Exception {
    //login
     String output="";
     int ID=-1;
     boolean loginOK =false;
     Connection conn1=DBUlti.DBConnect.getConnectionVMG();
     UserDAL dal = new UserDAL(conn1);
      VMGLog log1= new VMGLog();
    log1.WriteLog(txtusernameVMG+","+txtpasswordVMG+","+txtserial+","+txtpin+","+txtservicename+","+txtcardtype);

   ResultSet rs = dal.LoginVMG(txtusernameVMG, txtpasswordVMG);

   if(rs.next()){
       log1.WriteLog("login success");
       UserEntityVMG entity = new UserEntityVMG();
         entity.setID(rs.getInt("ID"));
         ID=rs.getInt("ID");
        entity.setUsername(rs.getString("Username"));
        entity.setPassword(rs.getString("Password"));
        entity.setMsisdn(rs.getString("msisdn"));
        entity.setEmail(rs.getString("email"));
        entity.setRegister_date(rs.getDate("register_date"));
        entity.setIsBanned(rs.getBoolean("isBanned"));
        entity.setRoll(rs.getInt("Roll")); 
        loginOK=true;
   } 
     if(loginOK==true){
          StringBuilder data = new StringBuilder(); 
    String cardtype = "";
    int minlengthOfPin = 0;
    int maxlengthOfPin = 0;
    int minlengOfSerial = 0;
    int maxlengOfSerial = 0;
    boolean isSendserial = true;
    boolean isSendcardtype=true;
    //servicename:fpt,epay,vtc
    log1.WriteLog("login=true");
    String servicename = txtservicename;
      log1.WriteLog(servicename);
    if (servicename.equalsIgnoreCase("EPAY")) {
        String temp = txtcardtype;
        if (temp.equalsIgnoreCase("VNP")) {
            minlengthOfPin = 12;
            maxlengthOfPin = 15;
            minlengOfSerial = 9;
            maxlengOfSerial = 9;
        } else if (temp.equalsIgnoreCase("VMS")) {
            minlengthOfPin = 12;
            maxlengthOfPin = 14;
            minlengOfSerial = 9;
            maxlengOfSerial = 15;
        } else if (temp.equalsIgnoreCase("VTT")) {
            minlengthOfPin = 13;
            maxlengthOfPin = 15;
            minlengOfSerial = 11;
            maxlengOfSerial = 15;
        } else if (temp.equalsIgnoreCase("MGC")) {
            minlengthOfPin = 12;
            maxlengthOfPin = 12;
            minlengOfSerial = 12;
            maxlengOfSerial = 12;
            isSendserial = false;
        }
        cardtype = temp;
    }
    else if (servicename.equalsIgnoreCase("FPT")) {
        cardtype = "FPT";
        minlengthOfPin = 10;
        maxlengthOfPin = 10;
        minlengOfSerial = 10;
        maxlengOfSerial = 10;
    }
    else if (servicename.equalsIgnoreCase("VTC")) {
        cardtype = "VTC";
        minlengthOfPin = 12;
        maxlengthOfPin = 12;
        minlengOfSerial = 12;
        maxlengOfSerial = 12;
    }
 if(cardtype.length()<=0){
     isSendcardtype=false;
 }
 log1.WriteLog("Sname:"+servicename);
    data.append(servicename);
    log1.WriteLog("user"+Bussiness.user);
    data.append(Bussiness.user);
    log1.WriteLog("txtserial"+txtserial);
    if(isSendserial==true){
    data.append(txtserial);
    }
    log1.WriteLog("pin"+txtpin);
    log1.WriteLog("cardtype:"+cardtype);
    data.append(txtpin);
    if(isSendcardtype==true){
    data.append(cardtype);
    }
    log1.WriteLog("subcpid"+Bussiness.subcpid);
    data.append(Bussiness.subcpid);

   String mac = des.DESMAC(data.toString(), EpurseConfig.keyUI, "DESede");
   log1.WriteLog("Mac="+mac+",data="+data.toString());
   String username = Bussiness.user;

    String serial = "";
    System.out.println("serial length:" + txtserial.length());
    if (txtserial.length() >= minlengOfSerial && txtserial.length() <= maxlengOfSerial) {
        serial = des.Encrypt(txtserial, EpurseConfig.keyUI, "DESede");
    }
    else output="";

    String pin = "";
    System.out.println("pin length:" + txtpin.length());
    if (txtpin.length() >= minlengthOfPin && txtpin.length() <= maxlengthOfPin) {
        pin = des.Encrypt(txtpin, EpurseConfig.keyUI, "DESede");
    }
    else output="";
   String subcp = Bussiness.subcpid;
    log1.WriteLog("Bat dau day JSON");
    JSONObject json = new JSONObject();
    json.put("servicename", servicename);
    json.put("username", username);
    if(serial.length()>0){
    json.put("serial", serial);
    }
    json.put("pin", pin);
     if(cardtype.length()>0){
    json.put("cardtype", cardtype);
     }
    json.put("subcp", subcp);
    json.put("mac", mac);
     log1.WriteLog("BGoi webservice");
    String response = new ServiceCardProxy(endpoint).gateCardInput(json.toString());
     log1.WriteLog("Response="+response);
    JSONObject jsonResponse = (JSONObject) new JSONParser().parse(response);
            String Flag=jsonResponse.get("flag").toString();
            String Description=jsonResponse.get("description").toString();
             String cardAmount=jsonResponse.get("cardAmount").toString();
              String cardID=jsonResponse.get("cardID").toString();

         ChargingDAL dalCharge= new ChargingDAL(conn1);

         int InsertData=dalCharge.ChargeVMG(ID,servicename,serial, pin, cardtype, Flag,Description,cardAmount,cardID);

     output= response;
      }                
    return output;

}

用于记录来自另一个 API 的用户信息和响应信息。 我构建并部署了 OK => 在构建项目后得到了 war 文件:“Building jar: D:\Setup\Java\RDB_JSF\dist\RDB_JSF.war”。

我遵循本教程: 部署和测试 Web 服务

将 Web 服务部署到服务器后,如果服务器有测试客户端,您可以使用 IDE 打开服务器的测试客户端。 GlassFish 和 WebLogic 服务器提供测试客户端。

If you are using the Tomcat Web Server, there is no test client. **You can only run the project and see if the Tomcat Web Services page opens. In this case, before you run the project, you need to make the web service the entry point to your application. To make the web service the entry point to your application, right-click the CalculatorWSApplication project node and choose Properties. Open the Run properties and type /CalculatorWS in the Relative URL field. Click OK. To run the project, right-click the project node again and select Run.**

在此链接:https://netbeans.org/kb/docs/websvc/jax-ws.html#Exercise_1 所以我将相对 URL 字段更改为 /ChargingGateway,这是我的服务名称。然后我运行项目并浏览到“localhost:8080/RDB_JSF/ChargingGateway”,出现“HTTP Status 404 - /RDB_JSF/ChargingGateway”错误。

请帮助我在 Tomcat 上部署 Web 服务。

【问题讨论】:

  • 当你尝试 localhost:8080/RDB_JSF/ChargingGateway/LoginAndCharging 时你会得到什么??
  • 同样的错误:HTTP Status 404 - /RDB_JSF/ChargingGateway/LoginAndCharging type 状态报告消息 /RDB_JSF/ChargingGateway/LoginAndCharging 描述请求的资源不可用。

标签: java web-services tomcat netbeans


【解决方案1】:

Java EE 项目需要 GlassFish Server 或 Oracle WebLogic Server 12c。 捆绑的 Tomcat Web 服务器不是完全符合 Java EE 的 Web 服务器。但是,可以将 Tomcat 7.x Web 服务器配置为支持某些 Java EE 功能。有关如何向 tomcat 添加对 Java EE 的支持的信息,请参阅 Apache TomEE 项目 (http://openejb.apache.org/)。

【讨论】:

    猜你喜欢
    • 2015-05-27
    • 2015-11-13
    • 1970-01-01
    • 2016-04-10
    • 2017-10-24
    • 2010-12-16
    • 1970-01-01
    • 2011-02-25
    相关资源
    最近更新 更多