weblogic6.1+jb6在研究EntityBean的时候发生的问题~~

cxhz_cn 2002-04-15 10:23:30
我是用ejb2.x的,编译都能通过~~
我的qq:503071
package myentitybean;
import javax.naming.*;
import java.util.Properties;
import javax.rmi.PortableRemoteObject;

public class HelloTestClient2 {
private static final String ERROR_NULL_REMOTE = "Remote interface reference is null. It must be created by calling one of the Home interface methods first.";
private static final int MAX_OUTPUT_LINE_LENGTH = 100;
private boolean logging = true;
private HelloRemoteHome helloRemoteHome = null;
private HelloRemote helloRemote = null;

//Construct the EJB test client
public HelloTestClient2() {
long startTime = 0;
if (logging) {
log("Initializing bean access.");
startTime = System.currentTimeMillis();
}

try {
//get naming context
Context ctx = getInitialContext();

//look up jndi name
Object ref = ctx.lookup("HelloRemote");

//cast to Home interface
helloRemoteHome = (HelloRemoteHome) PortableRemoteObject.narrow(ref, HelloRemoteHome.class);
if (logging) {
long endTime = System.currentTimeMillis();
log("Succeeded initializing bean access.");
log("Execution time: " + (endTime - startTime) + " ms.");
}
}
catch(Exception e) {
if (logging) {
log("Failed initializing bean access.");
}
e.printStackTrace();
}
}

private Context getInitialContext() throws Exception {
String url = "t3://localhost:7001";
String user = null;
String password = null;
Properties properties = null;
try {
properties = new Properties();
properties.put(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory");
properties.put(Context.PROVIDER_URL, url);
if (user != null) {
properties.put(Context.SECURITY_PRINCIPAL, user);
properties.put(Context.SECURITY_CREDENTIALS, password == null ? "" : password);
}

return new InitialContext(properties);
}
catch(Exception e) {
log("Unable to connect to WebLogic server at " + url);
log("Please make sure that the server is running.");
throw e;
}
}

//----------------------------------------------------------------------------
// Methods that use Home interface methods to generate a Remote interface reference
//----------------------------------------------------------------------------
...全文
47 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
cxhz_cn 2002-04-15
  • 打赏
  • 举报
回复
在线等待
cxhz_cn 2002-04-15
  • 打赏
  • 举报
回复

public HelloRemote create(String name1, String balance) {
long startTime = 0;
if (logging) {
log("Calling create(" + name1 + ", " + balance + ")");
startTime = System.currentTimeMillis();
}
try {
helloRemote = helloRemoteHome.create(name1, balance);
if (logging) {
long endTime = System.currentTimeMillis();
log("Succeeded: create(" + name1 + ", " + balance + ")");
log("Execution time: " + (endTime - startTime) + " ms.");
}
}
catch(Exception e) {
if (logging) {
log("Failed: create(" + name1 + ", " + balance + ")");
}
e.printStackTrace();
}

if (logging) {
log("Return value from create(" + name1 + ", " + balance + "): " + helloRemote + ".");
}
return helloRemote;
}

public HelloRemote findByPrimaryKey(String name1) {
long startTime = 0;
if (logging) {
log("Calling findByPrimaryKey(" + name1 + ")");
startTime = System.currentTimeMillis();
}
try {
helloRemote = helloRemoteHome.findByPrimaryKey(name1);
if (logging) {
long endTime = System.currentTimeMillis();
log("Succeeded: findByPrimaryKey(" + name1 + ")");
log("Execution time: " + (endTime - startTime) + " ms.");
}
}
catch(Exception e) {
if (logging) {
log("Failed: findByPrimaryKey(" + name1 + ")");
}
e.printStackTrace();
}

if (logging) {
log("Return value from findByPrimaryKey(" + name1 + "): " + helloRemote + ".");
}
return helloRemote;
}

//----------------------------------------------------------------------------
// Methods that use Remote interface methods to access data through the bean
//----------------------------------------------------------------------------

public String getName1() {
String returnValue = "";
if (helloRemote == null) {
System.out.println("Error in getName1(): " + ERROR_NULL_REMOTE);
return returnValue;
}
long startTime = 0;
if (logging) {
log("Calling getName1()");
startTime = System.currentTimeMillis();
}

try {
returnValue = helloRemote.getName1();
if (logging) {
long endTime = System.currentTimeMillis();
log("Succeeded: getName1()");
log("Execution time: " + (endTime - startTime) + " ms.");
}
}
catch(Exception e) {
if (logging) {
log("Failed: getName1()");
}
e.printStackTrace();
}

if (logging) {
log("Return value from getName1(): " + returnValue + ".");
}
return returnValue;
}

public void setBalance(String balance) {
if (helloRemote == null) {
System.out.println("Error in setBalance(): " + ERROR_NULL_REMOTE);
return ;
}
long startTime = 0;
if (logging) {
log("Calling setBalance(" + balance + ")");
startTime = System.currentTimeMillis();
}

try {
helloRemote.setBalance(balance);
if (logging) {
long endTime = System.currentTimeMillis();
log("Succeeded: setBalance(" + balance + ")");
log("Execution time: " + (endTime - startTime) + " ms.");
}
}
catch(Exception e) {
if (logging) {
log("Failed: setBalance(" + balance + ")");
}
e.printStackTrace();
}
}

public String getBalance() {
String returnValue = "";
if (helloRemote == null) {
System.out.println("Error in getBalance(): " + ERROR_NULL_REMOTE);
return returnValue;
}
long startTime = 0;
if (logging) {
log("Calling getBalance()");
startTime = System.currentTimeMillis();
}

try {
returnValue = helloRemote.getBalance();
if (logging) {
long endTime = System.currentTimeMillis();
log("Succeeded: getBalance()");
log("Execution time: " + (endTime - startTime) + " ms.");
}
}
catch(Exception e) {
if (logging) {
log("Failed: getBalance()");
}
e.printStackTrace();
}

if (logging) {
log("Return value from getBalance(): " + returnValue + ".");
}
return returnValue;
}

//----------------------------------------------------------------------------
// Utility Methods
//----------------------------------------------------------------------------

private void log(String message) {
if (message == null) {
System.out.println("-- null");
return ;
}
if (message.length() > MAX_OUTPUT_LINE_LENGTH) {
System.out.println("-- " + message.substring(0, MAX_OUTPUT_LINE_LENGTH) + " ...");
}
else {
System.out.println("-- " + message);
}
}
//Main method

public static void main(String[] args) {
HelloTestClient2 client = new HelloTestClient2();
System.out.println("haha");
// Use the client object to call one of the Home interface wrappers
// above, to create a Remote interface reference to the bean.
// If the return value is of the Remote interface type, you can use it
// to access the remote interface methods. You can also just use the
// client object to call the Remote interface wrappers.
}
}



-- Initializing bean access.

javax.naming.NameNotFoundException: Unable to resolve HelloRemote. Resolved: '' Unresolved:'HelloRemote' ; remaining name ''

at weblogic.rmi.internal.BasicOutboundRequest.sendReceive(BasicOutboundRequest.java:85)

at weblogic.rmi.cluster.ReplicaAwareRemoteRef.invoke(ReplicaAwareRemoteRef.java:262)

at weblogic.rmi.cluster.ReplicaAwareRemoteRef.invoke(ReplicaAwareRemoteRef.java:229)-- Failed initializing bean access.



at weblogic.rmi.internal.ProxyStub.invoke(ProxyStub.java:35)

at $Proxy0.lookup(Unknown Source)

at weblogic.jndi.internal.WLContextImpl.lookup(WLContextImpl.java:339)

at javax.naming.InitialContext.lookup(InitialContext.java:350)

at myentitybean.HelloTestClient2.<init>(HelloTestClient2.java:27)

at myentitybean.HelloTestClient2.main(HelloTestClient2.java:242)

1,236

社区成员

发帖
与我相关
我的任务
社区描述
企业软件 中间件技术
社区管理员
  • 中间件
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧