加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

普元7.2发布WebService

发布时间:2020-12-16 22:53:49 所属栏目:安全 来源:网络整理
导读:普元7.2发布WebService要求: 1.必须有接口。类必须实现某个接口 2.访问效果如下 3.代码: 接口: package com.primeton.eos; import org.osoa.sca.annotations.Remotable; @Remotable public interface IOrgOper { ?? ?public String executeSql(String dsN

普元7.2发布WebService要求:

1.必须有接口。类必须实现某个接口

2.访问效果如下

3.代码:

接口:

package com.primeton.eos;

import org.osoa.sca.annotations.Remotable;

@Remotable
public interface IOrgOper {
?? ?public String executeSql(String dsName);
}

实现类:

package com.primeton.eos;

import static com.eos.system.annotation.ParamType.CONSTANT;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import org.osoa.sca.annotations.Remotable;

import com.eos.common.connection.ConnectionHelper;
import com.eos.system.annotation.Bizlet;
import com.eos.system.annotation.BizletParam;

@Remotable
public class OrgOper implements IOrgOper {
?? ?@Bizlet(value = "执行一条sql",params = { @BizletParam(index = 0,defaultValue = "default",type = CONSTANT) })
?? ?//加@Bizlet这一行使executeSql方法成为运算逻辑,供构件调用
?? ?public String executeSql(String dsName) {
?? ??? ?String result = "";
?? ??? ?if (dsName == null || dsName.length() == 0)
?? ??? ??? ?dsName = "default";
?? ??? ?Connection conn = ConnectionHelper
?? ??? ??? ??? ?.getCurrentContributionConnection(dsName);
?? ??? ?Statement stmt = null;
?? ??? ?try {
?? ??? ??? ?stmt = conn.createStatement();
?? ??? ??? ?String sql = "select * from org where orgid=1";
?? ??? ??? ?ResultSet rs = stmt.executeQuery(sql);
?? ??? ??? ?while (rs.next()) {
?? ??? ??? ??? ?result = rs.getString("ORGNAME");
?? ??? ??? ?}
?? ??? ?} catch (Throwable e) {
?? ??? ??? ?throw new RuntimeException(e);
?? ??? ?} finally {
?? ??? ??? ?close(stmt);
?? ??? ??? ?close(conn);
?? ??? ?}
?? ??? ?return result;
?? ?}

?? ?private static void close(Connection conn) {
?? ??? ?if (conn == null)
?? ??? ??? ?return;
?? ??? ?try {
?? ??? ??? ?conn.close();
?? ??? ?} catch (SQLException e) {
?? ??? ??? ?// ignore
?? ??? ?}
?? ?}

?? ?private static void close(Statement stmt) {
?? ??? ?if (stmt == null)
?? ??? ??? ?return;
?? ??? ?try {
?? ??? ??? ?stmt.close();
?? ??? ?} catch (SQLException e) {
?? ??? ??? ?// ignore
?? ??? ?}
?? ?}
}

代码目录:

访问方式:http://127.0.0.1:8080/default/OrgOperService?wsdl

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读