Java开发网 Java开发网
注册 | 登录 | 帮助 | 搜索 | 排行榜 | 发帖统计  

您没有登录

» Java开发网 » Java EE 综合讨论区  

按打印兼容模式打印这个话题 打印话题    把这个话题寄给朋友 寄给朋友    该主题的所有更新都将Email到你的邮箱 订阅主题
flat modethreaded modego to previous topicgo to next topicgo to back
作者 re: 一个简单的servlet CORBA client程序
sothis



CJSDN高级会员


发贴: 168
积分: 60
于 2003-01-16 18:03 user profilesend a private message to usersend email to sothissearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
本文回答
http://www.chinajavaworld.net/forum/topic.cgi?forum=33&topic=268&show=0

下面是一个简单的servlet程序,该程序作为CORBA客户端存取一个CORBA服务器,返回服务器程序所在的主机的当前UNIX时间。如果想试一下该程序的话,可以使用BES5.1,使用BES所携带的J2SDK1.3.1_04。

public class Servlet2 extends HttpServlet {
private org.omg.CORBA.ORB myOrb = null ;
private servletclient.MyServices.TimeServer myServer = null;
static final private String CONTENT_TYPE = "text/html; charset=GBK";
//Initialize global variables
public void init() throws ServletException {
if (myServer == null) {
if (myOrb == null) {
myOrb = org.omg.CORBA.ORB.init((String[])null, System.getProperties());
}
myServer = servletclient.MyServices.TimeServerHelper.bind(myOrb, "/TimeServer_poa", "TimeServer".getBytes());
}
}
//Process the HTTP Get request
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType(CONTENT_TYPE);
PrintWriter out = response.getWriter();
out.println("<html>");
out.println("<head><title>Servlet2</title></head>");
out.println("<body>");
out.println("<p>The servlet has received a GET. This is the reply.</p>");
out.println(myServer.getTime());
out.println("</body></html>");
}
//Clean up resources
public void destroy() {
}
}

当然,别忘了跑SmartAgent(如果运行了BES那么smartAgent就起来了,否则需要运行osagent跑smartAgent)以及服务程序,下面是服务程序的代码

public class MyServicesServerApp {

public static void main(String[] args) {
try{

org.omg.CORBA.ORB orb = org.omg.CORBA.ORB.init(args, System.getProperties());

POA poaRoot = POAHelper.narrow(orb.resolve_initial_references("RootPOA"));

name = "TimeServer";
org.omg.CORBA.Policy[] TimeServerPolicies = {
poaRoot.create_lifespan_policy(LifespanPolicyValue.PERSISTENT)
};
POA poaTimeServer = poaRoot.create_POA(name + "_poa",
poaRoot.the_POAManager(),
TimeServerPolicies);
poaTimeServer.activate_object_with_id(name.getBytes(), new TimeServerImpl());
poaRoot.the_POAManager().activate();
orb.run();
}
catch(Exception ex) {
System.err.println(ex);
}
}
}

在C/S之间使用的IDL定义为
module MyServices {

interface TimeServer {
string getTime();
};
};


sothis edited on 2003-02-21 17:58

天狼星

话题树型展开
人气 标题 作者 字数 发贴时间
8941 re: 一个简单的servlet CORBA client程序 sothis 2393 2003-01-16 18:03
7541 Re:一个简单的servlet CORBA client程序 sothis 347 2003-01-16 18:36

flat modethreaded modego to previous topicgo to next topicgo to back
  已读帖子
  新的帖子
  被删除的帖子
Jump to the top of page

   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923