Failed to load Smooks configuration resource <import>

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Failed to load Smooks configuration resource <import>

fabio.tollini
Hi all,
I have a problem with smooks import statement running under Apache Tomcat.
Why does it look for files to be imported in the application server bin directory?

MyReadClass.java:
...
public Object read(InputStream stream){
    InputStream is = myServlet.getServletContext().getResourceAsStream("/WEB-INF/smooks/smooks-config.xml");
    Smooks smooks = new Smooks();          
    smooks.addConfigurations(is);
    JavaResult result = new JavaResult();
    smooks.filterSource(new StreamSource(stream), result);
    smooks.close();
    return result.getBean(ENTITY_NAME);
}

smooks-config.xml:
<?xml version="1.0" encoding="UTF-8"?>
< smooks-resource-list xmlns="http://www.milyn.org/xsd/smooks-1.1.xsd">
    <import file="smooks-config-MetaData.xml"></import>
    <import file="smooks-config-Declaration.xml">
        < param name="ID">ID_1< /param>
        < param name="element">ELEMENT_1< /param>
    </import>
    <import file="smooks-config-Declaration.xml">
        < param name="ID">ID_2< /param>
        < param name="element">ELEMENT_2< /param>
    </import>
</smooks-resource-list>

In the same folder where smooks-config.xml file is there are also smooks-config-MetaData.xml and smooks-config-Declaration.xml.

When the program is running, smooks-config.xml file is loaded correctly, but I get a SmooksConfigurationException:

org.milyn.cdr.SmooksConfigurationException: Failed to load Smooks configuration resource <import> 'smooks-config-MetaData.xml': Failed to access data stream for resource [smooks-config-MetaData.xml]. Tried (in order):
        File System: C:\Program Files\Apache Software Foundation\Apache Tomcat 8.0.3\bin\smooks-config-MetaData.xml
        File System: C:\Program Files\Apache Software Foundation\Apache Tomcat 8.0.3\bin\smooks-config-MetaData.xml
        Classpath: /smooks-config-MetaData.xml

        at org.milyn.cdr.XMLConfigDigester.digestImport(XMLConfigDigester.java:413)
        at org.milyn.cdr.XMLConfigDigester.digestV11XSDValidatedConfig(XMLConfigDigester.java:332)
        at org.milyn.cdr.XMLConfigDigester.digestConfigRecursively(XMLConfigDigester.java:226)
        at org.milyn.cdr.XMLConfigDigester.digestConfig(XMLConfigDigester.java:184)
        at org.milyn.cdr.SmooksResourceConfigurationStore.registerResources(SmooksResourceConfigurationStore.java:229)
        at org.milyn.Smooks.addConfigurations(Smooks.java:340)
        at org.milyn.Smooks.addConfigurations(Smooks.java:358)
        at com.MyReaderClass.read(B2MSWReader.java:70)
        ....
Caused by: java.io.IOException: Failed to access data stream for resource [smooks-config-MetaData.xml]. Tried (in order):
        File System: C:\Program Files\Apache Software Foundation\Apache Tomcat 8.0.3\bin\smooks-config-MetaData.xml
        File System: C:\Program Files\Apache Software Foundation\Apache Tomcat 8.0.3\bin\smooks-config-MetaData.xml
        Classpath: /smooks-config-MetaData.xml

        at org.milyn.resource.URIResourceLocator.getResource(URIResourceLocator.java:142)
        at org.milyn.resource.URIResourceLocator.getResource(URIResourceLocator.java:84)
        at org.milyn.cdr.XMLConfigDigester.digestImport(XMLConfigDigester.java:388)
        ... 13 more

P.S.: if I run this code as a simple Java application, it works...
Reply | Threaded
Open this post in threaded view
|

Re: Failed to load Smooks configuration resource <import>

Tom Fennelly
It tries loading from there because that is the cwd of the running
tomcat process. If the imported resources are on the classpath then I
think you'll need to specify the fully qualified path to them.


On 13/01/2015 14:28, fabio.tollini wrote:

> Hi all,
> I have a problem with smooks import statement running under Apache Tomcat.
> Why does it look for files to be imported in the application server bin
> directory?
>
> MyReadClass.java:
> ...
> public Object read(InputStream stream){
>      InputStream is =
> myServlet.getServletContext().getResourceAsStream("/WEB-INF/smooks/smooks-config.xml");
>      Smooks smooks = new Smooks();
>      smooks.addConfigurations(is);
>      JavaResult result = new JavaResult();
>      smooks.filterSource(new StreamSource(stream), result);
>      smooks.close();
>      return result.getBean(ENTITY_NAME);
> }
>
> smooks-config.xml:
> <?xml version="1.0" encoding="UTF-8"?>
> < smooks-resource-list xmlns="http://www.milyn.org/xsd/smooks-1.1.xsd">
>      <import file="smooks-config-MetaData.xml"></import>
>      <import file="smooks-config-Declaration.xml">
>          < param name="ID">ID_1< /param>
>          < param name="element">ELEMENT_1< /param>
>      </import>
>      <import file="smooks-config-Declaration.xml">
>          < param name="ID">ID_2< /param>
>          < param name="element">ELEMENT_2< /param>
>      </import>
> </smooks-resource-list>
>
> In the same folder where smooks-config.xml file is there are also
> smooks-config-MetaData.xml and smooks-config-Declaration.xml.
>
> When the program is running, smooks-config.xml file is loaded correctly, but
> I get a SmooksConfigurationException:
>
> org.milyn.cdr.SmooksConfigurationException: Failed to load Smooks
> configuration resource <import> 'smooks-config-MetaData.xml': Failed to
> access data stream for resource [smooks-config-MetaData.xml]. Tried (in
> order):
> File System: C:\Program Files\Apache Software Foundation\Apache Tomcat
> 8.0.3\bin\smooks-config-MetaData.xml
> File System: C:\Program Files\Apache Software Foundation\Apache Tomcat
> 8.0.3\bin\smooks-config-MetaData.xml
> Classpath: /smooks-config-MetaData.xml
>
> at org.milyn.cdr.XMLConfigDigester.digestImport(XMLConfigDigester.java:413)
> at
> org.milyn.cdr.XMLConfigDigester.digestV11XSDValidatedConfig(XMLConfigDigester.java:332)
> at
> org.milyn.cdr.XMLConfigDigester.digestConfigRecursively(XMLConfigDigester.java:226)
> at org.milyn.cdr.XMLConfigDigester.digestConfig(XMLConfigDigester.java:184)
> at
> org.milyn.cdr.SmooksResourceConfigurationStore.registerResources(SmooksResourceConfigurationStore.java:229)
> at org.milyn.Smooks.addConfigurations(Smooks.java:340)
> at org.milyn.Smooks.addConfigurations(Smooks.java:358)
> at com.MyReaderClass.read(B2MSWReader.java:70)
> ....
> Caused by: java.io.IOException: Failed to access data stream for resource
> [smooks-config-MetaData.xml]. Tried (in order):
> File System: C:\Program Files\Apache Software Foundation\Apache Tomcat
> 8.0.3\bin\smooks-config-MetaData.xml
> File System: C:\Program Files\Apache Software Foundation\Apache Tomcat
> 8.0.3\bin\smooks-config-MetaData.xml
> Classpath: /smooks-config-MetaData.xml
>
> at
> org.milyn.resource.URIResourceLocator.getResource(URIResourceLocator.java:142)
> at
> org.milyn.resource.URIResourceLocator.getResource(URIResourceLocator.java:84)
> at org.milyn.cdr.XMLConfigDigester.digestImport(XMLConfigDigester.java:388)
> ... 13 more
>
> P.S.: if I run this code as a simple Java application, it works...
>
>
>
> --
> View this message in context: http://milyn.996300.n3.nabble.com/Failed-to-load-Smooks-configuration-resource-import-tp8978.html
> Sent from the milyn - user mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe from this list, please visit:
>
>      http://xircles.codehaus.org/manage_email
>
>


---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|

Re: Failed to load Smooks configuration resource <import>

fabio.tollini
Thank you Tom!!
It works now!

Best regards,
Fabio