You are viewing a plain text version of this content. The canonical link for it is here.
Posted to soap-user@ws.apache.org by Michael Timpe <MT...@t-online.de> on 2002/02/07 14:15:36 UTC

Problem with SOAPContext

Hi,

I tried to get the SOAP-Kontext within my SOAP-service, but it didn't work. I get the following error message:

Generated fault:
  Fault Code   = SOAP-ENV:Server
  Fault String = Exception while handling service request: org/apache/soap/rpc/SOAPContext

Any idea?

Background: WinXP HOME; Apache 1.3.22; Apache Tomcat 4.01; Apache SOAP 2.2

I used the example from the SOAP-FAQ. The service method looks like this:

public String test(SOAPContext soapCtx,String name) { 
    HttpServletRequest req =
        (HttpServletRequest)soapCtx.getProperty(org.apache.soap.Constants.BAG_HTTPSERVLETREQUEST);
    String remoteIPAddress = req.getRemoteAddr();
    return(remoteIPAddress); 
}

The client-side call looks like this:

    // Build the call.
    Call call = new Call();

    call.setTargetObjectURI("urn:ootest");
    call.setMethodName("test");
    
    Vector params = new Vector();

    params.addElement(new Parameter("name", String.class,
                                    "Michael", null));

    // Invoke the call.
    Response resp;

    try
    {      
      resp = call.invoke(url, "");
    }
    catch (SOAPException e)
    {      
      return("Caught SOAPException (" +
                         e.getFaultCode() + "): " +
                         e.getMessage());
    }


The original text of the faq:

How can I get the IP address of a client that is using my SOAP Service?
If you add a SOAPContext Object as first Parameter in the signature of your SOAP-service java-method, a 'SOAPContext' Object is passed to your class, e.g.:
.mymethod(SOAPContext inContext, String inString)

This SOAPContext object gives you access to the HttpSession, HttpRequest, HttpResponse (see java doc for details).
So, your SOAP service method can get the servlet request out of the context object, and then call the getRemoteAddr() method on the service request object:

import javax.servlet.http.*;
....
HttpServletRequest req =
(HttpServletRequest)soapCtx.getProperty(org.apache.soap.Constants.BAG_HTTPSERVLETREQUEST);
String remoteIPAddress = req.getRemoteAddr();

NOTE: this will only work where the client and server are both using the Apache SOAP libraries. 



--------------------------------------------------------------------------------
Michael Timpe
Melchiorstr. 24
50670 Köln
eMail: mail@michael-timpe.de