users@jax-rpc.java.net

Re: Determine address of the client in JAX-WS 2.0, etc...

From: Doug Kohlert <Doug.Kohlert_at_Sun.COM>
Date: Tue, 04 Oct 2005 07:42:41 -0700

Dmytro Rud wrote:

>Hi!
>
>I use JAX-WS 2.0 and try to implement a simple client accounting using
>SOAP handlers. How can a service-side SOAP handler determine the
>requester's address (IP/FQDN)?
>
>
>
If you get the MessageContext there are a number of HTTP properties you
have access to.
Here is the MessageContext class:
public interface MessageContext extends Map<String, Object> {

  /** Standard property: message direction, <code>true</code> for
   * outbound messages, <code>false</code> for inbound.
   * <p>Type: boolean
  **/
  public static final String MESSAGE_OUTBOUND_PROPERTY =
                      "javax.xml.ws.handler.message.outbound";

  /** Standard property: Map of attachments to a message, key is
   * the MIME Content-ID, value is a DataHandler.
   * <p>Type: java.util.Map<String,DataHandler>
  **/
  public static final String MESSAGE_ATTACHMENTS =
        "javax.xml.ws.binding.attachments";

  /** Standard property: input source for WSDL document.
   * <p>Type: org.xml.sax.InputSource
  **/
  public static final String WSDL_DESCRIPTION =
        "javax.xml.ws.wsdl.description";

  /** Standard property: name of WSDL service.
   * <p>Type: javax.xml.namespace.QName
  **/
  public static final String WSDL_SERVICE =
        "javax.xml.ws.wsdl.service";

  /** Standard property: name of WSDL port.
   * <p>Type: javax.xml.namespace.QName
  **/
  public static final String WSDL_PORT =
        "javax.xml.ws.wsdl.port";

  /** Standard property: name of wsdl interface (2.0) or port type (1.1).
   * <p>Type: javax.xml.namespace.QName
  **/
  public static final String WSDL_INTERFACE =
        "javax.xml.ws.wsdl.interface";

  /** Standard property: name of WSDL operation.
   * <p>Type: javax.xml.namespace.QName
  **/
  public static final String WSDL_OPERATION =
        "javax.xml.ws.wsdl.operation";

  /** Standard property: HTTP response status code.
   * <p>Type: java.lang.Integer
  **/
  public static final String HTTP_RESPONSE_CODE =
        "javax.xml.ws.http.response.code";

  /** Standard property: HTTP request headers.
   * <p>Type: java.util.Map<java.lang.String,
java.util.List<java.lang.String>>
  **/
  public static final String HTTP_REQUEST_HEADERS =
        "javax.xml.ws.http.request.headers";

  /** Standard property: HTTP response headers.
   * <p>Type: java.util.Map<java.lang.String,
java.util.List<java.lang.String>>
  **/
  public static final String HTTP_RESPONSE_HEADERS =
        "javax.xml.ws.http.response.headers";

  /** Standard property: HTTP request method.
   * <p>Type: java.lang.String
  **/
  public static final String HTTP_REQUEST_METHOD =
        "javax.xml.ws.http.request.method";
 
  /** Standard property: servlet request object.
   * <p>Type: javax.servlet.http.HttpServletRequest
  **/
  public static final String SERVLET_REQUEST =
        "javax.xml.ws.servlet.request";
 
  /** Standard property: servlet response object.
   * <p>Type: javax.servlet.http.HttpServletResponse
  **/
  public static final String SERVLET_RESPONSE =
        "javax.xml.ws.servlet.response";
 
  /** Standard property: servlet session object.
   * <p>Type: javax.servlet.http.HttpSession
  **/
  public static final String SERVLET_SESSION =
        "javax.xml.ws.servlet.session";
 
  /** Standard property: servlet context object.
   * <p>Type: javax.servlet.ServletContext
  **/
  public static final String SERVLET_CONTEXT =
        "javax.xml.ws.servlet.context";
 
  /**
   * Property scope. Properties scoped as <code>APPLICATION</code> are
   * visible to handlers,
   * client applications and service endpoints; properties scoped as
   * <code>HANDLER</code>
   * are only normally visible to handlers.
  **/
  public enum Scope {APPLICATION, HANDLER};
   
  /** Sets the scope of a property.
   *
   * @param name Name of the property associated with the
   * <code>MessageContext</code>
   * @param scope Desired scope of the property
   * @throws java.lang.IllegalArgumentException if an illegal
   * property name is specified
   *
  **/
  public void setScope(String name, Scope scope);

  /** Gets the scope of a property.
   *
   * @param name Name of the property
   * @return Scope of the property
   * @throws java.lang.IllegalArgumentException if a non-existant
   * property name is specified
   *
  **/
  public Scope getScope(String name);
}

>Other minor questions and suggestions:
>
>1. I have deployed a single WAR with two web services --
> CurrencyConverter and BatchCurrencyConverter. Both pages --
> http://localhost:8080/testproject1/CurrencyConverter and
> http://localhost:8080/testproject1/BatchCurrencyConverter --
> show the same overall table describing the two web services.
> It doesn't give any troubles, but looks a little bit illogical.
>
>2. The only operation of BatchCurrencyConverter calls CurrencyConverter,
> and every invocation of this operation is accompanied by a refetching
> of CurrencyConverter's WSDL document. Why? Can it be somehow
> reconfigured to fetch the WSDL document only once, e.g. immediately
> after the initialization of the web service's servlet?
>
>
>
How does your BatchCurrenclyConverter get the proxy for
CurrencyConverter? If it keeps getting a new one this will happen, if
it caches it, I think the problem will be solved.

>3. When a method that returns void is annotated @Oneway, wsgen/apt task
> should extra check if this method is declared to throw an exception.
> Currently (JAXWS_SI_20050929) it is possible to generate and deploy a
> web service with exception-throwing oneway operations/methods, but
> problems come naturally while calling wsimport to generate a client.
>
>
>
This is probably a bug and I will look into it. Thanks for bringing it
to our attention.

>Thank you in advance.
>
>
>

-- 
 - Doug