You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@cxf.apache.org by Dan Diephouse <da...@envoisolutions.com> on 2007/03/26 06:36:32 UTC

URL in Client stub

Hola,

When using the WSDL2Java program it always generates hard coded urls in the
client stub like so:

    static {
        URL url = null;
        try {
            url = new URL("file:/C:/cygwin/home/Dan%20Diephouse/some.wsdl");
        } catch (MalformedURLException e) {
            e.printStackTrace();
        }
        WSDL_LOCATION = url;
    }

There is a problem with this though - It may not be in that same location
when I deploy my service. I can specify a relative URL using wsdl to java,
but then the URL string will be something like "some.wsdl" - which is not a
valid URL and will throw a MalformedURLException.

First, the exception is caught, which strikes me as odd. If its important,
we should do something about it. If its not important, then why is it
there??

Is there anyway around this?

Thanks,
- Dan
-- 
Dan Diephouse
Envoi Solutions
http://envoisolutions.com | http://netzooid.com/blog

Re: URL in Client stub

Posted by James Mao <ja...@iona.com>.
Dan Diephouse wrote:
> My problem with this is that:
>
> a) Its completely impossible to do relative urls when calling new 
> URL(). If
> we are going to enable the -wsdlLocation flag for this, we should be 
> using
> the URIResolver class to create a URL. Are there any issues with doing 
> that?

Yes, i agree, that's why i said it's a bug introduced when i fix the 
issue CXF-426
If you take a look at the 
cxf/tools/wsdlto/frontend/jaxws/src/main/java/org/apache/cxf/tools/wsdlto/frontend/jaxws/template/service.vm
You'll see static block and annotation they use the same variable, which 
should not.
The static block should still use the absolute path , and the annotation 
should use what ever user input.
>
> b) If, as Jervis says, the exception can be safely ignored, why do we 
> print
> the stack trace? Its annoying for those who don't have a WSDL around. 
> I can
> see how we need the WSDL to pull metadata out of sometimes, but it 
> shouldn't
> be required in my mind. Is the stack trace printing just there so 
> people can
> figure out why their WSDL isn't loading on the client side if that is in
> fact what they want to do? \\

If we changed to absolute path, i don't think we will see any 
exceptions. if you really don't want to print stack trace, i suggest we 
print some useful info/hints to user

Cheers,
James.
>
> - Dan
>
> On 3/26/07, Daniel Kulp <dk...@apache.org> wrote:
>>
>>
>> For wsdl2java, I added a -wsdlLocation flag last week that is opionally
>> used to specify the wsdlLocation that is embedded into the annotations.
>> Most likely, the sample here should also use that flag if specified.
>>
>> Dan
>>
>>
>> On Monday 26 March 2007 03:41, Liu, Jervis wrote:
>> > Is this a bug? I believe the logic here is that we generate a Stub
>> > that always has an absolute path as default, then if you know this
>> > absolute path does not work for your client (you know this because you
>> > write the client code, you know how the client bundle is deployed,
>> > where to expect the WSDL), you need to use a relative path or using
>> > whatever revolvers to resolve your WSDL location in your client code
>> > then pass the resolved result into the service stub. So I do not see
>> > this as a bug unless we want to change the default behavior of Service
>> > stub to be able to work with both relative path and absolute path. But
>> > my feeling is its better to leave the resolving job to the users as
>> > they most likely want to clearly control where they get the WSDL
>> > loaded.
>> >
>> > Cheers,
>> > Jervis
>> >
>> > > -----Original Message-----
>> > > From: James Mao [mailto:james.mao@iona.com]
>> > > Sent: 2007?3?26? 14:52
>> > > To: cxf-dev@incubator.apache.org
>> > > Subject: Re: URL in Client stub
>> > >
>> > >
>> > > This seems a bug to me, we just fixed a bug about the
>> > > relative URI for
>> > > annotation in SEI and Service class.
>> > > The static block in service class should still use absolute
>> > > path, which
>> > > used as a default wsdl location.
>> > >
>> > > Please fire an issue for this.
>> > >
>> > > Thanks,
>> > > James.
>> > >
>> > > > Hola,
>> > > >
>> > > > When using the WSDL2Java program it always generates hard
>> > >
>> > > coded urls
>> > >
>> > > > in the
>> > > > client stub like so:
>> > > >
>> > > >    static {
>> > > >        URL url = null;
>> > > >        try {
>> > > >            url = new
>> > > > URL("file:/C:/cygwin/home/Dan%20Diephouse/some.wsdl");
>> > > >        } catch (MalformedURLException e) {
>> > > >            e.printStackTrace();
>> > > >        }
>> > > >        WSDL_LOCATION = url;
>> > > >    }
>> > > >
>> > > > There is a problem with this though - It may not be in that
>> > >
>> > > same location
>> > >
>> > > > when I deploy my service. I can specify a relative URL
>> > >
>> > > using wsdl to
>> > >
>> > > > java,
>> > > > but then the URL string will be something like "some.wsdl"
>> > >
>> > > - which is
>> > >
>> > > > not a
>> > > > valid URL and will throw a MalformedURLException.
>> > > >
>> > > > First, the exception is caught, which strikes me as odd. If its
>> > > > important,
>> > > > we should do something about it. If its not important, then
>> > >
>> > > why is it
>> > >
>> > > > there??
>> > > >
>> > > > Is there anyway around this?
>> > > >
>> > > > Thanks,
>> > > > - Dan
>>
>> -- 
>> J. Daniel Kulp
>> Principal Engineer
>> IONA
>> P: 781-902-8727    C: 508-380-7194
>> daniel.kulp@iona.com
>> http://www.dankulp.com/blog
>>
>
>
>


Re: URL in Client stub

Posted by Dan Diephouse <da...@envoisolutions.com>.
My problem with this is that:

a) Its completely impossible to do relative urls when calling new URL(). If
we are going to enable the -wsdlLocation flag for this, we should be using
the URIResolver class to create a URL. Are there any issues with doing that?

b) If, as Jervis says, the exception can be safely ignored, why do we print
the stack trace? Its annoying for those who don't have a WSDL around. I can
see how we need the WSDL to pull metadata out of sometimes, but it shouldn't
be required in my mind. Is the stack trace printing just there so people can
figure out why their WSDL isn't loading on the client side if that is in
fact what they want to do?

- Dan

On 3/26/07, Daniel Kulp <dk...@apache.org> wrote:
>
>
> For wsdl2java, I added a -wsdlLocation flag last week that is opionally
> used to specify the wsdlLocation that is embedded into the annotations.
> Most likely, the sample here should also use that flag if specified.
>
> Dan
>
>
> On Monday 26 March 2007 03:41, Liu, Jervis wrote:
> > Is this a bug? I believe the logic here is that we generate a Stub
> > that always has an absolute path as default, then if you know this
> > absolute path does not work for your client (you know this because you
> > write the client code, you know how the client bundle is deployed,
> > where to expect the WSDL), you need to use a relative path or using
> > whatever revolvers to resolve your WSDL location in your client code
> > then pass the resolved result into the service stub. So I do not see
> > this as a bug unless we want to change the default behavior of Service
> > stub to be able to work with both relative path and absolute path. But
> > my feeling is its better to leave the resolving job to the users as
> > they most likely want to clearly control where they get the WSDL
> > loaded.
> >
> > Cheers,
> > Jervis
> >
> > > -----Original Message-----
> > > From: James Mao [mailto:james.mao@iona.com]
> > > Sent: 2007?3?26? 14:52
> > > To: cxf-dev@incubator.apache.org
> > > Subject: Re: URL in Client stub
> > >
> > >
> > > This seems a bug to me, we just fixed a bug about the
> > > relative URI for
> > > annotation in SEI and Service class.
> > > The static block in service class should still use absolute
> > > path, which
> > > used as a default wsdl location.
> > >
> > > Please fire an issue for this.
> > >
> > > Thanks,
> > > James.
> > >
> > > > Hola,
> > > >
> > > > When using the WSDL2Java program it always generates hard
> > >
> > > coded urls
> > >
> > > > in the
> > > > client stub like so:
> > > >
> > > >    static {
> > > >        URL url = null;
> > > >        try {
> > > >            url = new
> > > > URL("file:/C:/cygwin/home/Dan%20Diephouse/some.wsdl");
> > > >        } catch (MalformedURLException e) {
> > > >            e.printStackTrace();
> > > >        }
> > > >        WSDL_LOCATION = url;
> > > >    }
> > > >
> > > > There is a problem with this though - It may not be in that
> > >
> > > same location
> > >
> > > > when I deploy my service. I can specify a relative URL
> > >
> > > using wsdl to
> > >
> > > > java,
> > > > but then the URL string will be something like "some.wsdl"
> > >
> > > - which is
> > >
> > > > not a
> > > > valid URL and will throw a MalformedURLException.
> > > >
> > > > First, the exception is caught, which strikes me as odd. If its
> > > > important,
> > > > we should do something about it. If its not important, then
> > >
> > > why is it
> > >
> > > > there??
> > > >
> > > > Is there anyway around this?
> > > >
> > > > Thanks,
> > > > - Dan
>
> --
> J. Daniel Kulp
> Principal Engineer
> IONA
> P: 781-902-8727    C: 508-380-7194
> daniel.kulp@iona.com
> http://www.dankulp.com/blog
>



-- 
Dan Diephouse
Envoi Solutions
http://envoisolutions.com | http://netzooid.com/blog

Re: URL in Client stub

Posted by Daniel Kulp <dk...@apache.org>.
For wsdl2java, I added a -wsdlLocation flag last week that is opionally 
used to specify the wsdlLocation that is embedded into the annotations.   
Most likely, the sample here should also use that flag if specified. 

Dan


On Monday 26 March 2007 03:41, Liu, Jervis wrote:
> Is this a bug? I believe the logic here is that we generate a Stub
> that always has an absolute path as default, then if you know this
> absolute path does not work for your client (you know this because you
> write the client code, you know how the client bundle is deployed,
> where to expect the WSDL), you need to use a relative path or using
> whatever revolvers to resolve your WSDL location in your client code
> then pass the resolved result into the service stub. So I do not see
> this as a bug unless we want to change the default behavior of Service
> stub to be able to work with both relative path and absolute path. But
> my feeling is its better to leave the resolving job to the users as
> they most likely want to clearly control where they get the WSDL
> loaded.
>
> Cheers,
> Jervis
>
> > -----Original Message-----
> > From: James Mao [mailto:james.mao@iona.com]
> > Sent: 2007?3?26? 14:52
> > To: cxf-dev@incubator.apache.org
> > Subject: Re: URL in Client stub
> >
> >
> > This seems a bug to me, we just fixed a bug about the
> > relative URI for
> > annotation in SEI and Service class.
> > The static block in service class should still use absolute
> > path, which
> > used as a default wsdl location.
> >
> > Please fire an issue for this.
> >
> > Thanks,
> > James.
> >
> > > Hola,
> > >
> > > When using the WSDL2Java program it always generates hard
> >
> > coded urls
> >
> > > in the
> > > client stub like so:
> > >
> > >    static {
> > >        URL url = null;
> > >        try {
> > >            url = new
> > > URL("file:/C:/cygwin/home/Dan%20Diephouse/some.wsdl");
> > >        } catch (MalformedURLException e) {
> > >            e.printStackTrace();
> > >        }
> > >        WSDL_LOCATION = url;
> > >    }
> > >
> > > There is a problem with this though - It may not be in that
> >
> > same location
> >
> > > when I deploy my service. I can specify a relative URL
> >
> > using wsdl to
> >
> > > java,
> > > but then the URL string will be something like "some.wsdl"
> >
> > - which is
> >
> > > not a
> > > valid URL and will throw a MalformedURLException.
> > >
> > > First, the exception is caught, which strikes me as odd. If its
> > > important,
> > > we should do something about it. If its not important, then
> >
> > why is it
> >
> > > there??
> > >
> > > Is there anyway around this?
> > >
> > > Thanks,
> > > - Dan

-- 
J. Daniel Kulp
Principal Engineer
IONA
P: 781-902-8727    C: 508-380-7194
daniel.kulp@iona.com
http://www.dankulp.com/blog

RE: URL in Client stub

Posted by "Liu, Jervis" <jl...@iona.com>.
Is this a bug? I believe the logic here is that we generate a Stub that always has an absolute path as default, then if you know this absolute path does not work for your client (you know this because you write the client code, you know how the client bundle is deployed, where to expect the WSDL), you need to use a relative path or using whatever revolvers to resolve your WSDL location in your client code then pass the resolved result into the service stub. So I do not see this as a bug unless we want to change the default behavior of Service stub to be able to work with both relative path and absolute path. But my feeling is its better to leave the resolving job to the users as they most likely want to clearly control where they get the WSDL loaded.

Cheers,
Jervis


> -----Original Message-----
> From: James Mao [mailto:james.mao@iona.com]
> Sent: 2007?3?26? 14:52
> To: cxf-dev@incubator.apache.org
> Subject: Re: URL in Client stub
> 
> 
> This seems a bug to me, we just fixed a bug about the 
> relative URI for 
> annotation in SEI and Service class.
> The static block in service class should still use absolute 
> path, which 
> used as a default wsdl location.
> 
> Please fire an issue for this.
> 
> Thanks,
> James.
> > Hola,
> >
> > When using the WSDL2Java program it always generates hard 
> coded urls 
> > in the
> > client stub like so:
> >
> >    static {
> >        URL url = null;
> >        try {
> >            url = new 
> > URL("file:/C:/cygwin/home/Dan%20Diephouse/some.wsdl");
> >        } catch (MalformedURLException e) {
> >            e.printStackTrace();
> >        }
> >        WSDL_LOCATION = url;
> >    }
> >
> > There is a problem with this though - It may not be in that 
> same location
> > when I deploy my service. I can specify a relative URL 
> using wsdl to 
> > java,
> > but then the URL string will be something like "some.wsdl" 
> - which is 
> > not a
> > valid URL and will throw a MalformedURLException.
> >
> > First, the exception is caught, which strikes me as odd. If its 
> > important,
> > we should do something about it. If its not important, then 
> why is it
> > there??
> >
> > Is there anyway around this?
> >
> > Thanks,
> > - Dan
> 
> 

Re: URL in Client stub

Posted by James Mao <ja...@iona.com>.
This seems a bug to me, we just fixed a bug about the relative URI for 
annotation in SEI and Service class.
The static block in service class should still use absolute path, which 
used as a default wsdl location.

Please fire an issue for this.

Thanks,
James.
> Hola,
>
> When using the WSDL2Java program it always generates hard coded urls 
> in the
> client stub like so:
>
>    static {
>        URL url = null;
>        try {
>            url = new 
> URL("file:/C:/cygwin/home/Dan%20Diephouse/some.wsdl");
>        } catch (MalformedURLException e) {
>            e.printStackTrace();
>        }
>        WSDL_LOCATION = url;
>    }
>
> There is a problem with this though - It may not be in that same location
> when I deploy my service. I can specify a relative URL using wsdl to 
> java,
> but then the URL string will be something like "some.wsdl" - which is 
> not a
> valid URL and will throw a MalformedURLException.
>
> First, the exception is caught, which strikes me as odd. If its 
> important,
> we should do something about it. If its not important, then why is it
> there??
>
> Is there anyway around this?
>
> Thanks,
> - Dan


Re: URL in Client stub

Posted by James Mao <ja...@iona.com>.
> If a WSDL location is always passed in, then why is there a default?

It's defined in JAX-WS spec Section 2.7

"The JAX-WS 2.0 mandates that two constructors be present on every 
generated service class"
That's why there is a default one.
>
> I disagree with a subsequent statement, to the effect that you 
> generated the code, therefore, you know where the WSDL resides.  That 
> is usually NOT the case for the kinds of applications *I* write, 
> unless I am writing a hello-world-like demo program, which of course 
> is not a realistic example.
>
> I agree with Dan, at a minimum, that a stacktrace to stderr is 
> misleading, at best, and should be removed.

I agree,  so i suggested that we print some useful info to user, instead 
of  meaningless stacktrace.

>
> I'd go one step further and say that i) hard-coded paths should not go 
> into generated code, and ii) this URL should not get a default -- 
> failing to present a value when it's expected should be treated as an 
> error condition.

I don't see any harm of generating hard-code path in the generated code, 
it's just a skeleton, a sample code, it's generated for user to modify, 
to enhance, to meet their needs in the deploy time.
You can not assume that the generated code can meet all your needs 
without any modification to deploy.
I think to change the location of your wsdl in a few places is ok.
What we can do is like DanK said, add another argument for user to 
specify the wsdlLocation, but too many arguments sometime also annoying  
to users.

James.
>
> By relying on a default like this, you may end up i) giving yourself a 
> false sense of confidence that you've dotted your i's and crossed your 
> t's, because an application works in a specific scenario, and ii) 
> making it really hard to diagnose a bug, because you don't know where 
> a WSDL contract is getting loaded from.
>
> -Fred
>
> On Mar 26, 2007, at 2:46 AM, Liu, Jervis wrote:
>
>> this exception is safely to be ignored as the real WSDL_LOCATION is 
>> always passed into Service from client code to overload the original URL
>
>


RE: URL in Client stub

Posted by "Soltysik, Seumas" <Se...@iona.com>.
I completely agree with Fred. A default value should not be set. Just because I used a WSDL from a particular location to generate code, doesn't mean I want that location burned into my generated code. This can only be problematic when a user moves from demo type code to real world deploys.

-----Original Message-----
From: Fred Dushin [mailto:fred@dushin.net]
Sent: Monday, March 26, 2007 9:35 AM
To: cxf-dev@incubator.apache.org
Subject: Re: URL in Client stub


If a WSDL location is always passed in, then why is there a default?

I disagree with a subsequent statement, to the effect that you  
generated the code, therefore, you know where the WSDL resides.  That  
is usually NOT the case for the kinds of applications *I* write,  
unless I am writing a hello-world-like demo program, which of course  
is not a realistic example.

I agree with Dan, at a minimum, that a stacktrace to stderr is  
misleading, at best, and should be removed.

I'd go one step further and say that i) hard-coded paths should not  
go into generated code, and ii) this URL should not get a default --  
failing to present a value when it's expected should be treated as an  
error condition.

By relying on a default like this, you may end up i) giving yourself  
a false sense of confidence that you've dotted your i's and crossed  
your t's, because an application works in a specific scenario, and  
ii) making it really hard to diagnose a bug, because you don't know  
where a WSDL contract is getting loaded from.

-Fred

On Mar 26, 2007, at 2:46 AM, Liu, Jervis wrote:

> this exception is safely to be ignored as the real WSDL_LOCATION is  
> always passed into Service from client code to overload the  
> original URL


Re: URL in Client stub

Posted by Fred Dushin <fr...@dushin.net>.
If a WSDL location is always passed in, then why is there a default?

I disagree with a subsequent statement, to the effect that you  
generated the code, therefore, you know where the WSDL resides.  That  
is usually NOT the case for the kinds of applications *I* write,  
unless I am writing a hello-world-like demo program, which of course  
is not a realistic example.

I agree with Dan, at a minimum, that a stacktrace to stderr is  
misleading, at best, and should be removed.

I'd go one step further and say that i) hard-coded paths should not  
go into generated code, and ii) this URL should not get a default --  
failing to present a value when it's expected should be treated as an  
error condition.

By relying on a default like this, you may end up i) giving yourself  
a false sense of confidence that you've dotted your i's and crossed  
your t's, because an application works in a specific scenario, and  
ii) making it really hard to diagnose a bug, because you don't know  
where a WSDL contract is getting loaded from.

-Fred

On Mar 26, 2007, at 2:46 AM, Liu, Jervis wrote:

> this exception is safely to be ignored as the real WSDL_LOCATION is  
> always passed into Service from client code to overload the  
> original URL


RE: URL in Client stub

Posted by "Liu, Jervis" <jl...@iona.com>.
Hi Dan, the reason why we catch this exception is because this exception is safely to be ignored as the real WSDL_LOCATION is always passed into Service from client code to overload the original URL, see below:

        URL wsdlURL;
        File wsdlFile = new File(args[0]);
        if (wsdlFile.exists()) {
            wsdlURL = wsdlFile.toURL();
        } else {
            wsdlURL = new URL(args[0]);
        }
        
        System.out.println(wsdlURL);
        SOAPService ss = new SOAPService(wsdlURL, SERVICE_NAME);

Cheers,
Jervis

> -----Original Message-----
> From: Dan Diephouse [mailto:dan@envoisolutions.com]
> Sent: 2007?3?26? 12:37
> To: cxf-dev@incubator.apache.org
> Subject: URL in Client stub
> 
> 
> Hola,
> 
> When using the WSDL2Java program it always generates hard 
> coded urls in the
> client stub like so:
> 
>     static {
>         URL url = null;
>         try {
>             url = new 
> URL("file:/C:/cygwin/home/Dan%20Diephouse/some.wsdl");
>         } catch (MalformedURLException e) {
>             e.printStackTrace();
>         }
>         WSDL_LOCATION = url;
>     }
> 
> There is a problem with this though - It may not be in that 
> same location
> when I deploy my service. I can specify a relative URL using 
> wsdl to java,
> but then the URL string will be something like "some.wsdl" - 
> which is not a
> valid URL and will throw a MalformedURLException.
> 
> First, the exception is caught, which strikes me as odd. If 
> its important,
> we should do something about it. If its not important, then why is it
> there??
> 
> Is there anyway around this?
> 
> Thanks,
> - Dan
> -- 
> Dan Diephouse
> Envoi Solutions
> http://envoisolutions.com | http://netzooid.com/blog
>