开发者

Import location in wsit-client.xml to file in another jar, using an URL string to locate a file on the classpath

Normally the wsi开发者_运维技巧t-client.xml has import statements like this:

<import location="foo.xml" namespace="http://foo.org/" />

I've found that their can be online one wsit-client.xml on the classpath/META-INF, but can I refer to an xml who's located into another jar in that wsit-client.xml? Something like :

<import location="classPathResource/WEB-INF/foo.xml" namespace="http://foo.org/" />

I would like to create a single wsit-client.xml who contains the imports for all my webservices but I want to separate the configuration for all the different webservices in to different projects.


I've fixed it by creating an URLStreamHandler in the wsit-client.xml I can now define location="myprotocol://foo.xml"

I've used spring's PathMatchingResourcePatternResolver to locate my xml file in another project/jar.

public class Handler extends URLStreamHandler {

@Override
protected URLConnection openConnection(URL u) throws IOException {
    PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
    final URL resourceUrl = resolver.getResource(u.getPath()).getURL();
    if (resourceUrl == null) {
        throw new IOException(String.format("File %s not found on the classpath", u.getFile()));
    }
    return resourceUrl.openConnection();
}
}

I'm not using the VM arguments to define the handler but I've implemented an URLStreamHandlerFActory like explained over here URL to load resources from the classpath in Java

More info about writing your own protocol handlers can be find on this site: http://java.sun.com/developer/onlineTraining/protocolhandlers/

I've still got 1 project who contains the single wsit-client.xml with references to all my web service configurations, but at least I've managed to separate the configuration for all the different services in different maven projects.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜