Announcement Announcement Module
Collapse
No announcement yet.
Hessian and the request.. Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Hessian and the request..

    I'm using spring and the hessian services to create a connection to a content management system. Tthe files that get uploaded now have to make three jumps, browser to the spring/tapestry application, Tapestry to WebService, Webservice to ContentManagment system. Obviously I don't want to handles this with out some kind of streaming interface.

    My current question is how do I get to the Http request from the body of hessian method. I see how the bean gets instantiated, and I've found the dispatching mechanisim, but I can't figure out how to get a reference to the http request.

    Can someone help me with this?


    Tony Giaccone

  • #2
    Use an interceptor

    Code:
    <bean id="myRemote" class="org.springframework.aop.framework.ProxyFactoryBean">
        <property name="target" ref="myRemoteTarget" />
        <property name="interceptorNames">
          <list>
            <value>logBillingIpAddressInterceptor</value>
          </list>
        </property>
      </bean>
    Where "myRemoteTarget" is your HessianServiceExporter'ed class that has your serviceInterface defined.

    Have the logBillingIpAddressInterceptor class extend a class that implements the MethodBefore Advice like so:
    Code:
    public abstract void processRequest&#40;HttpServletRequest req,
                HttpServletResponse res&#41;;
           public void before&#40;Method method, Object&#91;&#93; args, Object arg2&#41;
                throws Throwable &#123;
            if &#40;!method.getDeclaringClass&#40;&#41;.equals&#40;HessianServiceExporter.class&#41;&#41;
                return;
            if &#40;!method.getName&#40;&#41;.equals&#40;"handleRequest"&#41;&#41;
                return;
            if &#40;args.length != 2&#41;
                return;
            if &#40;!args&#91;0&#93;.getClass&#40;&#41;.equals&#40;HttpServletRequest.class&#41;&#41;
                return;
            if &#40;!args&#91;1&#93;.getClass&#40;&#41;.equals&#40;HttpServletResponse.class&#41;&#41;
                return;
            processRequest&#40;&#40;HttpServletRequest&#41; args&#91;0&#93;,
                    &#40;HttpServletResponse&#41; args&#91;1&#93;&#41;;
        &#125;
    and then your class can have a method like this:
    Code:
    public void processRequest&#40;HttpServletRequest req, HttpServletResponse res&#41; &#123;
            log.info&#40;"Request from " + req.getRemoteAddr&#40;&#41; + " for "
                    + req.getRequestURI&#40;&#41;&#41;;
        &#125;
    granted that doesn't get you the httprequest in your myRemoteTarget class, but it might help you out.

    Comment


    • #3
      Confusion...

      I'm just a little confused.

      I see this definition:

      Code:
      <bean id="myRemote" class="org.springframework.aop.framework.ProxyFactoryBean">
          <property name="target" ref="myRemoteTarget" />
          <property name="interceptorNames">
            <list>
              <value>logBillingIpAddressInterceptor</value>
            </list>
          </property>
        </bean>
      That seems to me to be a client side declaration. Obviously I have to grab this connection on both sides, the server side and the client side, but in particular in my question I was asking about gaining access to the httprequest on the server side.

      Did I miss something here?

      Tony

      Comment

      Working...
      X