Apache Cayenne ROP 服务器“没有与请求关联的会话".在 Tomcat 7 上 [英] Apache Cayenne ROP Server "No session associated with request." on Tomcat 7

查看:30
本文介绍了Apache Cayenne ROP 服务器“没有与请求关联的会话".在 Tomcat 7 上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开发了一个带有 Java 富客户端和远程对象持久性服务器的 cayenne 项目.如果我这个富人与部署在本地主机上的同一台机器上的 Cayenne-ROP-Server 连接(在 Jetty 上来自 Maven 目标,如 cayenne rop 教程中所述),一切都很好:

I develop a cayenne project with a java rich client and an remote obejct persistence server. If i the rich cient connects with a Cayenne-ROP-Server that is deployed on the same machine on localhost (on Jetty from maven goal like explained inside the cayenne rop tutorial) everythings fine:

ClientConnection clientConnection = new HessianConnection("http://localhost:8080/rop.server   /cayenne-service",
            "cayenne-user", "secret", SHARED_CAYENNE_SESSION_NAME);
DataChannel channel = new ClientChannel(clientConnection);
ObjectContext context = new CayenneContext(channel);
List<Object> someEntities = context.performQuery(allMovies);

如果我将第一行中要连接的 url 更改为非本地主机(ubuntu 上的 Tomcat7),则一切正常,直到到达第 4 行:

If i change the url that i want to connect to in the first line to a non local host (Tomcat7 on ubuntu) then everything works till it comes to the 4th line:

List<Object> someEntities = context.performQuery(allMovies);

然后我收到错误没有与请求关联的会话"

Then i get the Error "No session associated with request"

这是客户端的完整输出:

Here is the full Output of the Client:

Running de.pss.hdlist.client.dataservice.MovieDataServiceCayenneImplTest
Sep 07, 2012 10:21:37 AM org.apache.cayenne.remote.hessian.HessianConnection connect
INFO: Connecting to [cayenne-user:*******@http://comunity-server.hopto.org:8080    /rop.server-3.0.2/cayenne-service] - shared session 'global-cayenne-session'
Sep 07, 2012 10:21:40 AM org.apache.cayenne.remote.hessian.HessianConnection connect
INFO: === Connected, session:  org.apache.cayenne.remote.RemoteSession@12241e[sessionId=C47DD36ACE2A043401C8D0C44D5BD8C3,n    ame=global-cayenne-session] - took 3182 ms.
Sep 07, 2012 10:21:53 AM org.apache.cayenne.remote.BaseConnection sendMessage
INFO: --- Message 0: Bootstrap
Sep 07, 2012 10:21:53 AM org.apache.cayenne.remote.BaseConnection sendMessage
INFO: === Message 0: Bootstrap done - took 406 ms.
Sep 07, 2012 10:21:53 AM org.apache.cayenne.remote.BaseConnection sendMessage
INFO: --- Message 1: Query
Sep 07, 2012 10:21:53 AM org.apache.cayenne.remote.BaseConnection sendMessage
INFO: *** Message error for 1: Query - took 187 ms.

这是 Apache Tomcat 日志的服务器端输出:

Here is the Serverside output of the Apache Tomcat log:

WARNING: org.apache.cayenne.remote.service.MissingSessionException: [v.3.0.2 Jun 19 2011 09:29:50] No session associated with request.
org.apache.cayenne.remote.service.MissingSessionException: [v.3.0.2 Jun 19 2011 09:29:50] No session associated with request.
    at    org.apache.cayenne.remote.service.BaseRemoteService.processMessage(BaseRemoteService.java:148)
    at sun.reflect.GeneratedMethodAccessor39.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:616)
    at com.caucho.hessian.server.HessianSkeleton.invoke(HessianSkeleton.java:180)
    at com.caucho.hessian.server.HessianSkeleton.invoke(HessianSkeleton.java:109)
    at com.caucho.hessian.server.HessianServlet.service(HessianServlet.java:396)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:224)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:169)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:581)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:927)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:987)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:579)
    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:307)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
    at java.lang.Thread.run(Thread.java:679)

我使用 Apache Cayenne 3.0.2、Apache-Tomcat 7.0.29 和 Java 7 sdk

I use Apache Cayenne 3.0.2, Apache-Tomcat 7.0.29 and Java 7 sdk

为每个帮助提前 THX

THX in advance for every Help

附注.也许本地 Jetty 服务器以另一种方式处理事情,就像远程 unix 机器上的 Tomcat 服务器一样.

PS. Maybe the local Jetty server handles things in another way as the Tomcat Server on remote unix machine.

在 Andrus 在下面的答案中给出的提示之后,我添加了一个如下所示的 SessionListern:

After the hint given by Andrus in the answer below i added an SessionListern that looks like this:

public class HttpSessionListenerLogImpl implements HttpSessionListener {

private final static Logger LOGGER = Logger.getLogger(HttpSessionListenerLogImpl.class.getName());

@Override
public void sessionCreated(HttpSessionEvent hse) {
    LOGGER.log(Level.SEVERE,
            "!__Session created with ID: " + hse.getSession().getId());
    LOGGER.log(Level.SEVERE, "!__Session created by: " + hse.getSource());
    LOGGER.log(Level.SEVERE, "!__Session Attributes: " + hse.getSession().getAttributeNames());
    LOGGER.log(Level.SEVERE, "!__Session max inactivity: " + hse.getSession().getMaxInactiveInterval());
    LOGGER.log(Level.SEVERE, "!__Session context: " + hse.getSession().getServletContext().getServletContextName());
}

@Override
public void sessionDestroyed(HttpSessionEvent hse) {
    LOGGER.log(Level.SEVERE, "!__Session killed with ID: " + hse.getSession().getId());
    LOGGER.log(Level.SEVERE, "!__Session killed by: " + hse.getSource());
    LOGGER.log(Level.SEVERE, "!__Session Attributes: " + hse.getSession().getAttributeNames());
    LOGGER.log(Level.SEVERE, "!__Session max inactivity: " + hse.getSession().getMaxInactiveInterval());
    LOGGER.log(Level.SEVERE, "!__Session context: " + hse.getSession().getServletContext().getServletContextName());
}

因此,在此问题之上执行 4 行代码 statet 时,此侦听器为我提供了以下输出:

So this listern gives me the following output when executing the 4 lines of code statet on top of this Question:

Sep 11, 2012 11:06:27 AM de.pss.hdlist.HttpSessionListenerLogImpl sessionCreated
SEVERE: !__Session created with ID: B07648A2A5F0005AF6DF0741D7EF2D21
Sep 11, 2012 11:06:27 AM de.pss.hdlist.HttpSessionListenerLogImpl sessionCreated
SEVERE: !__Session created by: org.apache.catalina.session.StandardSessionFacade@515f9553
Sep 11, 2012 11:06:27 AM de.pss.hdlist.HttpSessionListenerLogImpl sessionCreated
SEVERE: !__Session Attributes: java.util.Collections$2@5a44a5e1
Sep 11, 2012 11:06:27 AM de.pss.hdlist.HttpSessionListenerLogImpl sessionCreated
SEVERE: !__Session max inactivity: 216000
Sep 11, 2012 11:06:27 AM de.pss.hdlist.HttpSessionListenerLogImpl sessionCreated
SEVERE: !__Session context: Cayenne Tutorial
Sep 11, 2012 11:06:27 AM com.caucho.hessian.server.HessianSkeleton invoke
WARNING: org.apache.cayenne.remote.service.MissingSessionException: [v.3.0.2 Jun 19 2011 09:29:50] No session associated with request.
org.apache.cayenne.remote.service.MissingSessionException: [v.3.0.2 Jun 19 2011 09:29:50] No session associated with request.
    at  org.apache.cayenne.remote.service.BaseRemoteService.processMessage(BaseRemoteService.java:148)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at  
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:616)
    at com.caucho.hessian.server.HessianSkeleton.invoke(HessianSkeleton.java:180)
    at com.caucho.hessian.server.HessianSkeleton.invoke(HessianSkeleton.java:109)
    at com.caucho.hessian.server.HessianServlet.service(HessianServlet.java:396)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:224)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:169)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:581)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:927)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:987)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:579)
    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:307)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
    at java.lang.Thread.run(Thread.java:679)

在这里你可以看到有一个会话被创建,没有会话被杀死.那么为什么我的代码行中的 ObjectContext

Here you can see there is a session that gets created and there is no session that gets killed. So why does the ObjectContext from my line of code

List<Object> someEntities = context.performQuery(allMovies);

确实忽略会话.我是否必须在进行查询之前明确设置它?客户端访问远程部署的 cayenne 服务器的标准初始化代码是什么.它与 cayenne rop 教程中给出的不同吗?

does ignore the session. Do i have to set it explicitly before doing a query? What is the standard initializing code on the client side to access an remotly deployed cayenne server. Does it differ from the one given inside the cayenne rop tutorial?

提前确认.

我升级到 cayenne 3.1B1 希望摆脱这个错误,但这里的情况相同:尝试发送查询时没有会话...".

I upgraded to cayenne 3.1B1 hoping to get rid of this error, but same Situation here: "No session..." when trying to send a query.

我还在本地主机上设置了一个 tomcat,并将其配置为与远程相同.尝试发送查询时出现同样的问题无会话...".

I also setup a tomcat on localhost and configured it the same as the remote is. Same Problem here "No Session..." when trying to send a query.

所以 localhost 上的 Jetty 是唯一一个从上面获取 4 行初始化代码并为每个后续查询保持会话的人.所以这是我的问题.这个星球上有没有人尝试过在 tomcat 上部署 cayenne rop 服务器并成功了?

So the Jetty on localhost is the only one that takes the 4 line init code from above and holds the session for every following query. So here is my Question. Does anyone on this planet ever tried to deploy a cayenne rop server on a tomcat and succeeded?

对于每一个小提示,提前感谢.

THX in advance for every little hint.

所以我在我的本地 tomcat7 上做了一点服务器端调试.

So i did a litte bit of server side debugging on my local tomcat7.

1.Client 执行上面代码的第 2 行:

1.Client executes line 2 of code from above:

DataChannel channel = new ClientChannel(clientConnection);

在服务器端,我的会话侦听器被触发并告诉我已创建一个会话,ID 为:B6565298F222294F601B76333DBE4911

on the Serverside my session listener gets triggerd and tells me a session has been created with id: B6565298F222294F601B76333DBE4911

2.Client 从上面执行第 3 行:

2.Client executes line 3 from above:

ObjectContext context = new CayenneContext(channel);

在服务器端,类 org.apache.cayenne.remote.service.HttpRemoteSession 的方法被调用:

On the server side the method of class org.apache.cayenne.remote.service.HttpRemoteSession gets called:

/**
 * Returns a ServerSession object that represents Cayenne-related state associated
 * with the current session. If ServerSession hasn't been previously saved, returns
 * null.
 */
@Override
protected ServerSession getServerSession() {
    HttpSession httpSession = getSession(true);
    return (ServerSession) httpSession.getAttribute(SESSION_ATTRIBUTE);
}

通过此方法的第一行创建一个新会话.其 ID 为:ECC4A81D6240A1D04DA0A646200C4CE6.这个新会话只包含一个属性:键是org.apache.cayenne.remote.service.HttpRemoteService.ServerSession",值是(谁猜到了?)之前在步骤 1 中创建的会话让我感到奇怪的是,虽然创建了新会话,但我的 serveltListener 不会被触发.

a new session gets created by line one of this method. Its ID is: ECC4A81D6240A1D04DA0A646200C4CE6. This new Session contains exactly one attribute: the key is "org.apache.cayenne.remote.service.HttpRemoteService.ServerSession" and the value is (who guessed it?) the session created before in step 1 What makes me wonder is that my serveltListener dont gets triggerd though a new session gets created.

3.Client 执行上面的第 4 行

3.Client executes line 4 from above

List<Object> someEntities = context.performQuery(allMovies);

现在在服务器端再次调用 getServerSession() 方法.这次还创建了一个新会话(为什么?).并且这个会话不包含任何属性.所以行返回(ServerSession)httpSession.getAttribute(SESSION_ATTRIBUTE);"在方法 getServerSession() 内部返回 null 并且正是这触发了异常没有与请求关联的会话".

at the serverside now the getServerSession() method is called again. This time also a new session gets created (why?). And this session does not contain any attribute. So the line "return (ServerSession) httpSession.getAttribute(SESSION_ATTRIBUTE);" inside the method getServerSession() returns null and exactly this triggers the exception "No Session associated with request".

那么为什么 cayenne 服务器端创建 e ne 会话而不使用之前创建的旧会话?我是否必须在查询中明确发送会话?

So why is the cayenne serverside creating e ne session and doesnt use the old one created befor? Do i have to explicitly send the session within the query?

我在运行上面的四行代码时从 netbeans http-monitor 制作了屏幕截图:

I made screenshots from the netbeans http-monitor while running the four lines of code from above:

推荐答案

这是 Cayenne ROP 和较新容器之间的问题:

This is an issue between Cayenne ROP and newer containers:

https://issues.apache.org/jira/browse/CAY-1739

这是一个 Tomcat 解决方案 - 创建具有以下内容的 context.xml 文件,并将其放置在您的 web 应用程序的 META-INF/中:

Here is a Tomcat solution - create context.xml file with the following contents, and place it in META-INF/ of your webapp:

<Context>
    <Valve className="org.apache.catalina.authenticator.BasicAuthenticator"
        changeSessionIdOnAuthentication="false" />
</Context>

这篇关于Apache Cayenne ROP 服务器“没有与请求关联的会话".在 Tomcat 7 上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆