3

服务器,一个运行 Spring 2.5.6 的独立 SE 应用程序和一个嵌入式码头。客户端,Swing 应用程序,使用 HttpInvoker 连接到服务器。

服务器公开了很多服务,现在出现了新的要求,即我需要记录(几乎)客户端的每次调用。

我想做的是让客户端发送一些额外的信息,(用户名、工作站 ID 等字符串和整数)。服务器上的典型方法如下所示

public void doStuff(int someParam) {
   // Do stuff
   List result = method(someParam)

   // Audit
   // get the client information from somewhere?!!
   String username;
   int workstationId;

   auditDao.doStuffPerformed(username, workstationId, someParam, result);

}

那么,如何从服务器上的方法中获取客户端信息。

我尝试过的一种解决方案是将客户端信息添加为请求属性并调用方法 RequestContextHolder.getRequestAttributes(); 从方法内部。

我在客户端添加了一个 CommonsHttpInvokerRequestExecutor 并重载了以下方法以添加其他信息。

@Override
protected PostMethod createPostMethod(HttpInvokerClientConfiguration config) throws IOException {
  PostMethod postMethod = super.createPostMethod(config);
  postMethod.addRequestHeader("someHeader", "someHeader2");
  postMethod.addParameter("someParam", "someParam2");
  postMethod.setRequestHeader("someRequestHeader", "someRequestHeader2");
  return postMethod;
}

然而,这将不起作用。服务器上无法访问标头或参数。

任何回应将不胜感激。

4

1 回答 1

0

我认为你在正确的轨道上。您应该只在服务器端使用自定义SimpleHttpInvokerServiceExporter子类,并覆盖以从参数readRemoteInvocation中提取客户端设置的标头。HttpExchange

这些标头值可以存储在静态ThreadLocal会话变量中,可以在服务器端代码的任何位置访问。

于 2011-09-29T16:49:56.787 回答