How to read a file that is packaged in ESB in JBoss SOA?

Solution Verified - Updated -

Issue

  • I deployed my ESB-component into JBoss SOA 4.3.0 deploy folder.
  • The esb contains resources/conf/xsd/my.xsd that needs to be loaded within one of my action classes.
  • This code fails to find the file packaged in the esb.

    public Message compose(T masterFile) throws MessageDeliverException 
    {
    ...
         SchemaFactory schemaFactory = SchemaFactory.newInstance(javax.xml.XMLConstants.W3C_XML_SCHEMA_NS_URI);
         String resource = "resources/conf/xsd/my.xsd";
         Schema schema = schemaFactory.newSchema(new File(resource));
         Unmarshaller unmarshaller = jxbCtx.createUnmarshaller();
         unmarshaller.setSchema(schema);
         Source streamSource = new StreamSource(new FileReader(masterFile));
         JAXBElement<SubscriptionXmlType> result = unmarshaller.unmarshal(streamSource, SubscriptionXmlType.class);
         return message;
    }
    
    
    
    
    ERROR [com.mycompany.esb.myapp.actions.MasterApplicationListener] <<<MasterApplicationListener.compose>>> Unable to unmarshal!
    org.xml.sax.SAXParseException: schema_reference.4: Failed to read schema document 'file:/jboss-soa/soa-4.3.0.GA_CP02/jboss-soa-p.4.3.0/jboss-as/bin/resources/conf/xsd/my.xsd', because 1) could not find the document; 2) the document could not be read; 3) the root element of the document is not <xsd:schema>.
     at org.apache.xerces.util.ErrorHandlerWrapper.createSAXParseException(Unknown Source)
     at org.apache.xerces.util.ErrorHandlerWrapper.error(Unknown Source)
     at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source)
     at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source)
     at org.apache.xerces.impl.xs.traversers.XSDHandler.reportSchemaError(Unknown Source)
     at org.apache.xerces.impl.xs.traversers.XSDHandler.getSchemaDocument(Unknown Source)
     at org.apache.xerces.impl.xs.traversers.XSDHandler.parseSchema(Unknown Source)
     at org.apache.xerces.impl.xs.XMLSchemaLoader.loadSchema(Unknown Source)
     at org.apache.xerces.impl.xs.XMLSchemaLoader.loadGrammar(Unknown Source)
     at org.apache.xerces.impl.xs.XMLSchemaLoader.loadGrammar(Unknown Source)
     at org.apache.xerces.jaxp.validation.XMLSchemaFactory.newSchema(Unknown Source)
     at javax.xml.validation.SchemaFactory.newSchema(SchemaFactory.java:594)
     at javax.xml.validation.SchemaFactory.newSchema(SchemaFactory.java:610)
     at com.xyz.esb.example.csc.actions.MasterApplicationListener.compose(MasterApplicationListener.java:147)
     at com.xyz.esb.example.csc.actions.MasterApplicationListener.compose(MasterApplicationListener.java:73)
     at org.jboss.soa.esb.listeners.gateway.AbstractFileGateway.onSchedule(AbstractFileGateway.java:139)
     at org.jboss.soa.esb.listeners.lifecycle.AbstractScheduledManagedLifecycle$1.onSchedule(AbstractScheduledManagedLifecycle.java:68)
     at org.jboss.soa.esb.schedule.SchedulerJob$ESBScheduledJob.execute(SchedulerJob.java:289)
     at org.quartz.core.JobRunShell.run(JobRunShell.java:203)
     at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:520)
    

Environment

  • JBoss Service Oriented Architecture Platform (SOA-P)
    • 4.3

Subscriber exclusive content

A Red Hat subscription provides unlimited access to our knowledgebase, tools, and much more.

Current Customers and Partners

Log in for full access

Log In

New to Red Hat?

Learn more about Red Hat subscriptions

Using a Red Hat product through a public cloud?

How to access this content