简体   繁体   English

在Weblogic中的ejb 3处具有远程接口的RMI调用

[英]RMI call with Remote interface at ejb 3 in weblogic

I have some problem with this code , when i am trying to call the Remote interface , that is deploy in other server (prewlsapp2) . 当我尝试调用Remote接口时,此代码存在一些问题,该接口部署在其他服务器(prewlsapp2)中。 this is my client : 这是我的客户:

Hashtable<String, String> pro = new Hashtable<String, String>();  
              //Properties pro = new Properties();  
              pro.put(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory");  
               pro.put(Context.PROVIDER_URL, "t3://prewlsapp2:7661");  
               //pro.put(Context.SECURITY_PRINCIPAL, "hemanth");  
              //pro.put(Context.SECURITY_CREDENTIALS, "hemnathn1"); 


               Context ctx = new InitialContext(pro);  
               MessagesEntityFacadeRemote t = (MessagesEntityFacadeRemote)ctx.lookup("MessagesEntityFacade#Message.MessagesEntityFacadeRemote");
               GOSIDebug.debugMessages("MessagesEntityFacadeRemote  "+t);
              List tt = t.findByTargetID("2004");

               System.out.print("xyz");

The System.out.print("xyz"); System.out.print(“ xyz”); never printed after call t.findByTargetID("2004") , also there is no Exception printed ! 在调用t.findByTargetID(“ 2004”)之后从不打印,也没有异常打印!

My Remote interface is : 我的远程接口是:

    package Message;

import java.util.List;
import javax.ejb.Remote;

@Remote
public interface MessagesEntityFacadeRemote {

    void create(MessagesEntity messagesEntity); 

    void edit(MessagesEntity messagesEntity);

    void remove(MessagesEntity messagesEntity);

    MessagesEntity find(MessagesEntity id);

    List<MessagesEntity> findAll();

     List<MessagesEntity> findByTargetID(String target) ;

    List<MessagesEntity> findRange(int[] range);

     MessagesEntity findByMessageID(String target);

      List<MessagesEntity> findNextByTargetID(String target,int f,int l) ;

    int count();

}

Also my Impl : 还有我的Impl:

package Message;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

@Stateless(mappedName="MessagesEntityFacade")
public class MessagesEntityFacade implements MessagesEntityFacadeLocal, MessagesEntityFacadeRemote, Serializable {
    @PersistenceContext(unitName = "Messaging_SystemPU")
    private EntityManager em;


    protected EntityManager getEntityManager() { 
        return em;
    }



    @Override
    public MessagesEntity find(MessagesEntity id) {
        throw new UnsupportedOperationException("Not supported yet.");
    }


    @Override
    public List<MessagesEntity> findAll() {

    return em.createQuery("select object(o) from MessagesEntity as o").getResultList();

    }



    @Override
        public List<MessagesEntity> findByTargetID(String target) throws Exception  {


        System.out.println("target are"+target);
        Query result=null;
        try{
       ArrayList <MessagesEntity>listOFMessages=new ArrayList<MessagesEntity>();
       List results = new ArrayList();
       MessagesEntity[] users;
       System.out.print("hiiiiiiiiiii");
            result = em.createNativeQuery("select * from T_MESSAGES  p where p.target = ?1 order by p.creationtimestamp desc",Message.MessagesEntity.class);
        System.out.print("out hiiiiiiii");
        result.setParameter(1, target);


        // results = result.getResultList();

      //  System.out.print("beforrrrrr");
            // users = (MessagesEntity[])result.getResultList().toArray(new MessagesEntity[0]);
       //  System.out.println("usersusers"+users);



        }
        catch(Exception e){
            System.out.print("xxxxxxxxxxxxxxxs"); 
            e.printStackTrace();
        }

         return result.getResultList();

    //SELECT c from PolicyShiftEntityEJB c where c.policyId = :policyId
      /*Query query=em.createQuery("SELECT object(c) FROM MessagesEntity as c WHERE  c.target = :target order by c.messageid desc");
      query.setParameter("target", target);
      List res= query.getResultList();

      System.out.print("ressssssss"+res);
        listOFMessages.addAll(res);

        return listOFMessages;*/
     // return query.getResultList();

    }

    @Override
    public MessagesEntity findByMessageID(String messageId) {

        Query result = em.createNativeQuery("select * from T_MESSAGES  p where p.messageid = ?1 ",Message.MessagesEntity.class);
        result.setParameter(1, messageId);
        return (MessagesEntity) result.getSingleResult();

    }

    @Override
    public List<MessagesEntity> findNextByTargetID(String target,int f,int l) {

        Query result = em.createNativeQuery("select * from T_MESSAGES  p where p.target = ?1 order by p.creationtimestamp desc",Message.MessagesEntity.class);
         result.setParameter(1, target);
         result.setFirstResult((f - 1) * l);
         result.setMaxResults(l);
         return result.getResultList();
    }

    @Override
    public void create(MessagesEntity messagesEntity) {
       em.persist(messagesEntity);
    }

    @Override
    public void edit(MessagesEntity messagesEntity) {
        em.merge(  messagesEntity);
    }

    @Override
    public void remove(MessagesEntity messagesEntity) {
     em.remove(em.merge(messagesEntity));
    }

    @Override
    public List<MessagesEntity> findRange(int[] range) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public int count() {
        throw new UnsupportedOperationException("Not supported yet.");
    }


}

Hint : when I am trying to call this function in my clients ( count() ), the Exception was : 提示:当我尝试在客户端( count() )中调用此函数时,异常为:

 java.lang.reflect.UndeclaredThrowableException
    at $Proxy334.count(Unknown Source)
    at gosi.core.security.viewcontrollers.LoginServlet.doPost(LoginServlet.java:1062)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
    at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:227)
    at weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:125)
    at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:292)
    at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:175)
    at weblogic.servlet.internal.RequestDispatcherImpl.invokeServlet(RequestDispatcherImpl.java:502)
    at weblogic.servlet.internal.RequestDispatcherImpl.forward(RequestDispatcherImpl.java:251)
    at gosi.core.security.viewcontrollers.SIMISLoginProxyServlet.doPost(SIMISLoginProxyServlet.java:124)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
    at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:227)
    at weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:125)
    at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:292)
    at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:175)
    at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:3495)
    at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
    at weblogic.security.service.SecurityManager.runAs(Unknown Source)
    at weblogic.servlet.internal.WebAppServletContext.securedExecute(WebAppServletContext.java:2180)
    at weblogic.servlet.internal.WebAppServletContext.execute(WebAppServletContext.java:2086)
    at weblogic.servlet.internal.ServletRequestImpl.run(ServletRequestImpl.java:1406)
    at weblogic.work.ExecuteThread.execute(ExecuteThread.java:201)
    at weblogic.work.ExecuteThread.run(ExecuteThread.java:173)
Caused by: java.lang.NoSuchMethodException: Message.MessagesEntityFacade_lpk28i_MessagesEntityFacadeRemoteImpl_1030_WLStub.count()
    at java.lang.Class.getMethod(Class.java:1605)
    at weblogic.ejb.container.internal.RemoteBusinessIntfProxy.getTargetMethod(RemoteBusinessIntfProxy.java:162)
    at weblogic.ejb.container.internal.RemoteBusinessIntfProxy.invoke(RemoteBusinessIntfProxy.java:53)
    ... 25 more

But when I call this function findByTargetID(String target) , nothing printed ! 但是,当我调用此函数findByTargetID(String target) ,没有打印任何内容! and I don't know if there is some Exception or not , olso this line in my client never printed System.out.print("xyz"); 而且我不知道是否有异常,所以我客户端中的这一行从未打印过System.out.print("xyz"); , thank you so much :) , 非常感谢 :)

I'm not sure which version of WebLogic you're using, but in 10.3 we used to have similar issues with executing EJBs via remote calls and having the generics in the Remote interface was what was causing the issue. 我不确定您使用的是哪个版本的WebLogic,但是在10.3中,我们曾经遇到过类似的问题,即通过远程调用执行EJB,并且在Remote接口中具有泛型是造成此问题的原因。 Try removing the generic type parameters from the interface and see if that works for you. 尝试从接口中删除泛型类型参数,看看是否适合您。

ie

List<MessagesEntity> findByTargetID(String target) ;

becomes

List findByTargetID(String target) ;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM