users@jax-rpc.java.net

Re: Can a Web Service know where itself is deployed??

From: Guadalupe Ortiz <gobellot_at_hotmail.com>
Date: Sun, 9 May 2004 22:20:50 +0200

Hi, I tried the next lines:

package libservice;

import java.util.*;
import javax.xml.rpc.server.*;

public class LibImpl implements LibIF, ServiceLifecycle{

private ServletEndpointContext sec;



    public boolean bookAvailability (String ISBN) {
     boolean Result=false;
     if ((ISBN.compareTo("1111"))==0)
       Result=true;
     return Result;
    }

     private void myRemoteMethod(){
       String contextName =
          sec.getServletContext().getServletContextName();

    }

    public void destroy() {
    }

    public void init(Object arg0) throws ServiceException {
       sec = (ServletEndpointContext)arg0;
    }


 }

I get the next compilation error "This compilation unit indirectly
references the mising type javax.servlet.ServletContext" How can I solve it,
please? and how do I use the information you provided me for example inside
the method "bookAvailability" to get the context if it is posible in this
way??

Thanks
Gobellot

----- Original Message -----
From: "Andy Wolf" <andy.wolf_at_schwaben.de>
To: <users_at_jax-rpc.dev.java.net>
Sent: Sunday, May 09, 2004 8:32 PM
Subject: Re: Can a Web Service know where itself is deployed??


> Hello,
>
> Guadalupe Ortiz wrote:
> > I have a web service developed with jaxrpc. I can deploy it anywhere.
Can
> > the web service know at run time where it has been deployed? Because I
can
> > even deploy it, the same service, in two different uris, can it
distinguish
> > in which uri its operations are invoked??
>
> Well, I wonder what difference it makes where the service is running but
> you can find out the ContextName via the ServletEndpointContext which is
> available through the ServletLifecycle:
>
> public class MyServiceImpl implements MyService, ServiceLifecycle {
> private ServletEndpointContext sec;
>
> [...]
>
> public void myRemoteMethod(){
> String contextName =
> sec.getServletContext().getServletContextName();
>
> [...]
> }
>
> public void destroy() {
> }
>
> public void init(Object arg0) throws ServiceException {
> sec = (ServletEndpointContext)arg0;
> }
> }
>
> For the name of the virtual host under which this service is deployed
> you might want to check the servlet container attributes which can be
> accessed via the ServletContext as well.
>
> regards...Andy
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jax-rpc.dev.java.net
> For additional commands, e-mail: users-help_at_jax-rpc.dev.java.net
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe_at_jax-rpc.dev.java.net
For additional commands, e-mail: users-help_at_jax-rpc.dev.java.net