У меня есть некоторые проблемы с этим кодом, когда я пытаюсь вызвать удаленный интерфейс, который развернут на другом сервере (prewlsapp2).
это мой клиент:
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");
System.out.print ("xyz"); никогда не печатается после вызова t.findByTargetID ("2004"), также не печатается никаких исключений!
Мой удаленный интерфейс:
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();
}
Также мой 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.");
}
}
Подсказка: когда я пытаюсь вызвать эту функцию в моих клиентах (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
Но когда я вызываю эту функцию findByTargetID(String target)
, ничего не печатается! и я не знаю, есть ли какое-то Исключение или нет, также эта строка в моем клиенте никогда не печаталась System.out.print("xyz");
, большое спасибо:)