You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by Steve Revilak <sr...@KAYAK.com> on 2012/11/01 23:55:32 UTC

static intializers and "Can not initialize ..."

I have a question about the static initializer that WSDL2Java places
in service stubs.

When using wsdl2java to generate code, my service classes have static
initializers like the following:

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     static {
         URL url = CompanyService.class.getResource("data/wsdl/dfp-CompanyService.wsdl");
         if (url == null) {
             java.util.logging.Logger.getLogger(CompanyService.class.getName())
                 .log(java.util.logging.Level.INFO,
                      "Can not initialize the default wsdl from {0}",
         "data/wsdl/dfp-CompanyService.wsdl");
         }
         WSDL_LOCATION = url;
     }
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

The path "data/wsdl/dfp-CompanyService.wsdl" is the wsdl argument
given to wsdl2java.

I'm a little confused about this initializer.  getResource(...) finds
named a item in the JVM's classpath; and for me, that would be a path
inside a jar file.

I thought, "No problem -- I'll just package the wsdls in a jar, using
the same relative paths that I gave to wsdl2java".  However

   getResource("data/wsdl/dfp-CompanyService.wsdl")

returns a null pointer.  To get a jar:file: URL from getResource(),
you'd need a leading slash:

   getResource("/data/wsdl/dfp-CompanyService.wsdl")

I'd like to avoid the "Can not initialize ..." message every time my
JVM loads a Service class.  How should I be specifying the wsdl
location to wsdl2java to avoid this?

Thanks in advance.

Steve


SOLVED: static intializers and "Can not initialize ..."

Posted by Steve Revilak <sr...@KAYAK.com>.
Here is the what I ultimately ended up doing.  Giving -wsdlLocation
(to provide a "deployed" WSDL location) seems like a good option when
you're using one WSDL at a time.  But in my case, I'm using -wsdlList
to process several WSDLs.

Giving an empty string as -wsdlLocation generates this static
initializer:

     static {
         WSDL_LOCATION = null;
     }

I have to provide the wsdl location when instantiating Services, but
it eliminates the "Can not initialize ..." message when the Service
Class is loaded.

My final wsdl2java command line ended up looking like this:

   java -DexitOnFinish=TRUE org.apache.cxf.tools.wsdlto.WSDLToJava \
    -d /path/to/output/directory \
    -verbose \
    -wsdlLocation "" \
    -validate \
    -databinding xmlbeans \
    -b data/wsdl/dfp.xsdconfig \
    -p my.package.name \
    -wsdlList \
    data/wsdl/wsdl-list.txt

-DexitOnFinish=TRUE tells WSDLToJava to exit with a non-zero status
code if wsdl generation fails (so that build tools can notice).

Steve



>Date: Thu, 1 Nov 2012 18:55:32 -0400
>From: Steve Revilak <sr...@KAYAK.com>
>To: users@cxf.apache.org
>Subject: static intializers and "Can not initialize ..."
>Message-ID: <20...@KAYAK.com>
>User-Agent: Mutt/1.5.21 (2010-09-15)
>
>I have a question about the static initializer that WSDL2Java places
>in service stubs.
>
>When using wsdl2java to generate code, my service classes have static
>initializers like the following:
>
>~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>    static {
>        URL url = CompanyService.class.getResource("data/wsdl/dfp-CompanyService.wsdl");
>        if (url == null) {
>            java.util.logging.Logger.getLogger(CompanyService.class.getName())
>                .log(java.util.logging.Level.INFO,
>                     "Can not initialize the default wsdl from {0}",
>        "data/wsdl/dfp-CompanyService.wsdl");
>        }
>        WSDL_LOCATION = url;
>    }
>~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>
>The path "data/wsdl/dfp-CompanyService.wsdl" is the wsdl argument
>given to wsdl2java.
>
>I'm a little confused about this initializer.  getResource(...) finds
>named a item in the JVM's classpath; and for me, that would be a path
>inside a jar file.
>
>I thought, "No problem -- I'll just package the wsdls in a jar, using
>the same relative paths that I gave to wsdl2java".  However
>
>  getResource("data/wsdl/dfp-CompanyService.wsdl")
>
>returns a null pointer.  To get a jar:file: URL from getResource(),
>you'd need a leading slash:
>
>  getResource("/data/wsdl/dfp-CompanyService.wsdl")
>
>I'd like to avoid the "Can not initialize ..." message every time my
>JVM loads a Service class.  How should I be specifying the wsdl
>location to wsdl2java to avoid this?
>
>Thanks in advance.
>
>Steve
>



Re: static intializers and "Can not initialize ..."

Posted by Steve Revilak <sr...@KAYAK.com>.
>You might want to try putting the WSDL (and XSDs) into the JAR project in a
>folder called META-INF/wsdl.  When you generate the artifacts using
>wsdl2java, you can do something like the pattern shown with this Ant task
>(yes, you could do similar with Maven)
>
><target name="cxfWSDLToJava" depends="init, copy-wsdl-local">
><java classname="org.apache.cxf.tools.wsdlto.WSDLToJava" fork="true">
>* **<arg value="-wsdlLocation" />*
>* <arg value="/META-INF/wsdl/${ws.endpointName}.wsdl" />*
><arg value="-d" />
><arg value="${src}" />
><arg value="-client" />
><arg value="-verbose" />
>* **<arg value="${src}/META-INF/wsdl/${ws.endpointName}.wsdl" />*
><classpath>
><path refid="cxf.classpath" />
><path refid="project.classpath" />
></classpath>
></java>
></target>
>
>This causes the generated code to look like this and it IS found in the JAR
>in the classpath as you describe:  (notice the generated path is
>"/META-INF/wsdl/... "


Mark,

Thanks for this suggestion -- this makes much more sense.

I have one follow-up question.  In my case, I'm using -wsdlList to
process a collection of wsdl at once.  Is there a way to provide a
list of wsdlLocations?  (If it matters, I'm using XmlBeans data
bindings.)

Steve

Re: static intializers and "Can not initialize ..."

Posted by Mark Streit <mc...@gmail.com>.
You might want to try putting the WSDL (and XSDs) into the JAR project in a
folder called META-INF/wsdl.  When you generate the artifacts using
wsdl2java, you can do something like the pattern shown with this Ant task
(yes, you could do similar with Maven)

<target name="cxfWSDLToJava" depends="init, copy-wsdl-local">
<java classname="org.apache.cxf.tools.wsdlto.WSDLToJava" fork="true">
* **<arg value="-wsdlLocation" />*
* <arg value="/META-INF/wsdl/${ws.endpointName}.wsdl" />*
<arg value="-d" />
<arg value="${src}" />
<arg value="-client" />
<arg value="-verbose" />
* **<arg value="${src}/META-INF/wsdl/${ws.endpointName}.wsdl" />*
<classpath>
<path refid="cxf.classpath" />
<path refid="project.classpath" />
</classpath>
</java>
</target>

This causes the generated code to look like this and it IS found in the JAR
in the classpath as you describe:  (notice the generated path is
"/META-INF/wsdl/... "


/**
 * This class was generated by Apache CXF 2.7.0
 * 2012-10-27T16:53:04.359-04:00
 * Generated source version: 2.7.0
 *
 */
@WebServiceClient(name = "BookOrderManagerService",
                  wsdlLocation =
"/META-INF/wsdl/BookOrderManagerService.wsdl",
                  targetNamespace = "http://webservices.book.acme.com/")
public class BookOrderManagerService_Service extends Service {

    public final static URL WSDL_LOCATION;

    public final static QName SERVICE = new QName("
http://webservices.book.acme.com/", "BookOrderManagerService");
    public final static QName BookOrderManagerServicePort = new QName("
http://webservices.book.acme.com/", "BookOrderManagerServicePort");
    static {
*        URL url =
BookOrderManagerService_Service.class.getResource("/META-INF/wsdl/BookOrderManagerService.wsdl");
*
        if (url == null) {

java.util.logging.Logger.getLogger(BookOrderManagerService_Service.class.getName())
                .log(java.util.logging.Level.INFO,
                     "Can not initialize the default wsdl from {0}",
"/META-INF/wsdl/BookOrderManagerService.wsdl");
        }
        WSDL_LOCATION = url;
    }



Hope this helps.

On Thu, Nov 1, 2012 at 6:55 PM, Steve Revilak <sr...@kayak.com> wrote:

> I have a question about the static initializer that WSDL2Java places
> in service stubs.
>
> When using wsdl2java to generate code, my service classes have static
> initializers like the following:
>
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~**~~~
>     static {
>         URL url = CompanyService.class.**getResource("data/wsdl/dfp-**
> CompanyService.wsdl");
>         if (url == null) {
>             java.util.logging.Logger.**getLogger(CompanyService.**
> class.getName())
>                 .log(java.util.logging.Level.**INFO<http://java.util.logging.Level.INFO>
> ,
>                      "Can not initialize the default wsdl from {0}",
>         "data/wsdl/dfp-CompanyService.**wsdl");
>         }
>         WSDL_LOCATION = url;
>     }
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~**~~~
>
> The path "data/wsdl/dfp-CompanyService.**wsdl" is the wsdl argument
> given to wsdl2java.
>
> I'm a little confused about this initializer.  getResource(...) finds
> named a item in the JVM's classpath; and for me, that would be a path
> inside a jar file.
>
> I thought, "No problem -- I'll just package the wsdls in a jar, using
> the same relative paths that I gave to wsdl2java".  However
>
>   getResource("data/wsdl/dfp-**CompanyService.wsdl")
>
> returns a null pointer.  To get a jar:file: URL from getResource(),
> you'd need a leading slash:
>
>   getResource("/data/wsdl/dfp-**CompanyService.wsdl")
>
> I'd like to avoid the "Can not initialize ..." message every time my
> JVM loads a Service class.  How should I be specifying the wsdl
> location to wsdl2java to avoid this?
>
> Thanks in advance.
>
> Steve
>
>


-- 
Mark
*
*