You are viewing a plain text version of this content. The canonical link for it is here.
Posted to soap-dev@ws.apache.org by Mi...@swisscom.com on 2002/07/11 11:32:48 UTC

Practical changes to rpcrouter and ServerHttpUtils?

Hi all,

I had to develop a SOAP access to a service which runs on Jetty Servlet Engine. We used SOAP to integrate a client, which runs on Win2k deep in the system. The service object deployed on SOAP needs
to know the IP of the client, so it had to have access to the servletContext and the request object of the embedding web server (Jetty). Thus, I made this changes:

in the RPCRouterServlet's post method I synchronized the provider invokation:

synchronized(provider){
            provider.locate( dd, callEnv, call, call.getMethodName(), fullTargetID, 
                         reqCtx );
            provider.invoke( reqCtx, resCtx );
        }

I added the class WebContextTargetObject to the org.apache.soap.server Package:

/*
 * WebContexTargetObject.java
 *
 * Created on 23. Juni 2002, 18:05
 */

package org.apache.soap.server;

import javax.servlet.*;
import javax.servlet.http.*;

/**
 *
 * @author  szalay
 * @version 
 */
public class WebContextTargetObject {

    protected ServletContext servletContext;
    protected HttpServletRequest request;
    
    /** Creates new WebContexTargetObject */
    public WebContextTargetObject() {
    }
    
    /**
     *  setter method for ServletContext
     *
     *  @param ServletContext context
     */
    public void setServletContext(ServletContext c){
        servletContext = c;
    }    
        
        
    /**
     *  getter method for servlet context
     *
     * @returns ServletContext context
     */
    public ServletContext getServletContext(){
        return servletContext;
    }
    
    /**
     *  setter method for request
     */
    public void setRequest(HttpServletRequest request){
        this.request = request;
    }
     
    /**
     *  getter method for request
     */
    public HttpServletRequest getRequest(){
        return this.request;
    }
        
        
}


Then I added this bit of code to the RPCJavaProviders locate-Method:

      if (targetObject instanceof WebContextTargetObject){
          WebContextTargetObject wcto = (WebContextTargetObject) targetObject;
          wcto.setServletContext(context);
          wcto.setRequest((HttpServletRequest) reqContext.getProperty(Constants.BAG_HTTPSERVLETREQUEST));
      }

My webService object then is a subclass of WebContextTargetObject, and so I can access the servletContext and the request in the deployed webService object.

Does anyone know how this could "officially" whitout changes to provider and rpcrouter code?
Thanx for help.
Michael

Re: Practical changes to rpcrouter and ServerHttpUtils?

Posted by Scott Nichol <sn...@scottnichol.com>.
Michael,

The "official" way to do this was added for either release 2.2 or 2.3 (I
don't ecall which).  You might notice in RPCRouter#invoke that if no method
in the service class has the appropriate signature, there is a search for a
method with the same signature, but with an additional lead parameter of
type SOAPContext.  If found, this is executed, with the current SOAPContext
passed to the service method.  The service method can then get the
HttpServletRequest instance as you do below.

To be clear, I mean that a service like

    public class Foo {
        public void bar(SOAPContext ctx, String realArg) {
            ...
        }
    }

would be invoked by a client call like

    Vector params = new Vector();
    params.addElement(new Parameter("realArg", String.class, "my arg",
null));
    call.setParams(params);

In other words, the client does *not* send the SOAPContext parameter.

Thanks for posting your code.  There are undoubtedly plenty of things for
which there is no "official" way to do, so code contributions are always
welcome.

Scott Nichol

----- Original Message -----
From: <Mi...@swisscom.com>
To: <so...@xml.apache.org>
Sent: Thursday, July 11, 2002 5:32 AM
Subject: Practical changes to rpcrouter and ServerHttpUtils?



Hi all,

I had to develop a SOAP access to a service which runs on Jetty Servlet
Engine. We used SOAP to integrate a client, which runs on Win2k deep in the
system. The service object deployed on SOAP needs
to know the IP of the client, so it had to have access to the servletContext
and the request object of the embedding web server (Jetty). Thus, I made
this changes:

in the RPCRouterServlet's post method I synchronized the provider
invokation:

synchronized(provider){
            provider.locate( dd, callEnv, call, call.getMethodName(),
fullTargetID,
                         reqCtx );
            provider.invoke( reqCtx, resCtx );
        }

I added the class WebContextTargetObject to the org.apache.soap.server
Package:

/*
 * WebContexTargetObject.java
 *
 * Created on 23. Juni 2002, 18:05
 */

package org.apache.soap.server;

import javax.servlet.*;
import javax.servlet.http.*;

/**
 *
 * @author  szalay
 * @version
 */
public class WebContextTargetObject {

    protected ServletContext servletContext;
    protected HttpServletRequest request;

    /** Creates new WebContexTargetObject */
    public WebContextTargetObject() {
    }

    /**
     *  setter method for ServletContext
     *
     *  @param ServletContext context
     */
    public void setServletContext(ServletContext c){
        servletContext = c;
    }


    /**
     *  getter method for servlet context
     *
     * @returns ServletContext context
     */
    public ServletContext getServletContext(){
        return servletContext;
    }

    /**
     *  setter method for request
     */
    public void setRequest(HttpServletRequest request){
        this.request = request;
    }

    /**
     *  getter method for request
     */
    public HttpServletRequest getRequest(){
        return this.request;
    }


}


Then I added this bit of code to the RPCJavaProviders locate-Method:

      if (targetObject instanceof WebContextTargetObject){
          WebContextTargetObject wcto = (WebContextTargetObject)
targetObject;
          wcto.setServletContext(context);
          wcto.setRequest((HttpServletRequest)
reqContext.getProperty(Constants.BAG_HTTPSERVLETREQUEST));
      }

My webService object then is a subclass of WebContextTargetObject, and so I
can access the servletContext and the request in the deployed webService
object.

Does anyone know how this could "officially" whitout changes to provider and
rpcrouter code?
Thanx for help.
Michael

--
To unsubscribe, e-mail:   <ma...@xml.apache.org>
For additional commands, e-mail: <ma...@xml.apache.org>




--
To unsubscribe, e-mail:   <ma...@xml.apache.org>
For additional commands, e-mail: <ma...@xml.apache.org>


Re: Practical changes to rpcrouter and ServerHttpUtils?

Posted by Scott Nichol <sn...@scottnichol.com>.
Michael,

The "official" way to do this was added for either release 2.2 or 2.3 (I
don't ecall which).  You might notice in RPCRouter#invoke that if no method
in the service class has the appropriate signature, there is a search for a
method with the same signature, but with an additional lead parameter of
type SOAPContext.  If found, this is executed, with the current SOAPContext
passed to the service method.  The service method can then get the
HttpServletRequest instance as you do below.

To be clear, I mean that a service like

    public class Foo {
        public void bar(SOAPContext ctx, String realArg) {
            ...
        }
    }

would be invoked by a client call like

    Vector params = new Vector();
    params.addElement(new Parameter("realArg", String.class, "my arg",
null));
    call.setParams(params);

In other words, the client does *not* send the SOAPContext parameter.

Thanks for posting your code.  There are undoubtedly plenty of things for
which there is no "official" way to do, so code contributions are always
welcome.

Scott Nichol

----- Original Message -----
From: <Mi...@swisscom.com>
To: <so...@xml.apache.org>
Sent: Thursday, July 11, 2002 5:32 AM
Subject: Practical changes to rpcrouter and ServerHttpUtils?



Hi all,

I had to develop a SOAP access to a service which runs on Jetty Servlet
Engine. We used SOAP to integrate a client, which runs on Win2k deep in the
system. The service object deployed on SOAP needs
to know the IP of the client, so it had to have access to the servletContext
and the request object of the embedding web server (Jetty). Thus, I made
this changes:

in the RPCRouterServlet's post method I synchronized the provider
invokation:

synchronized(provider){
            provider.locate( dd, callEnv, call, call.getMethodName(),
fullTargetID,
                         reqCtx );
            provider.invoke( reqCtx, resCtx );
        }

I added the class WebContextTargetObject to the org.apache.soap.server
Package:

/*
 * WebContexTargetObject.java
 *
 * Created on 23. Juni 2002, 18:05
 */

package org.apache.soap.server;

import javax.servlet.*;
import javax.servlet.http.*;

/**
 *
 * @author  szalay
 * @version
 */
public class WebContextTargetObject {

    protected ServletContext servletContext;
    protected HttpServletRequest request;

    /** Creates new WebContexTargetObject */
    public WebContextTargetObject() {
    }

    /**
     *  setter method for ServletContext
     *
     *  @param ServletContext context
     */
    public void setServletContext(ServletContext c){
        servletContext = c;
    }


    /**
     *  getter method for servlet context
     *
     * @returns ServletContext context
     */
    public ServletContext getServletContext(){
        return servletContext;
    }

    /**
     *  setter method for request
     */
    public void setRequest(HttpServletRequest request){
        this.request = request;
    }

    /**
     *  getter method for request
     */
    public HttpServletRequest getRequest(){
        return this.request;
    }


}


Then I added this bit of code to the RPCJavaProviders locate-Method:

      if (targetObject instanceof WebContextTargetObject){
          WebContextTargetObject wcto = (WebContextTargetObject)
targetObject;
          wcto.setServletContext(context);
          wcto.setRequest((HttpServletRequest)
reqContext.getProperty(Constants.BAG_HTTPSERVLETREQUEST));
      }

My webService object then is a subclass of WebContextTargetObject, and so I
can access the servletContext and the request in the deployed webService
object.

Does anyone know how this could "officially" whitout changes to provider and
rpcrouter code?
Thanx for help.
Michael

--
To unsubscribe, e-mail:   <ma...@xml.apache.org>
For additional commands, e-mail: <ma...@xml.apache.org>