I'm using an @WebServiceProvider to deploy a web service that uses
Castor (rather than JAXB) to
do the binding of XML to existing Java objects.
To do this, I deploy a Castor mapping.xml file in the WAR. Then, I need
to get it from inside the Provider. Now, I am using injection of
@WebServiceContext to get to ServletContext. But, is there a way that I
can inject the file (mapping.xml) directly into a File instance - more
elegantly?
Here is my code:
@Resource
WebServiceContext wscontext;
// ... snip
public Source invoke(Source payload) {
if ( webServiceContext == null ) {
throw new RuntimeException("WebServiceContext not injected.");
}
MessageContext mc = webServiceContext.getMessageContext();
ServletContext sc = (ServletContext)
mc.get(MessageContext.SERVLET_CONTEXT);
if ( sc == null ) {
throw new RuntimeException("ServletContext is null.");
}
InputStream castorMappingFile =
sc.getResourceAsStream("/WEB-INF/castor/mapping.xml");
if ( castorMappingFile == null ) {
throw new IOException("Castor mapping file not found.");
}
I am wonderin if it is possible to do something like this:
@Resource(name="/WEB-INF/castor/mapping.xml")
File castorMappingFile;