0 Replies Latest reply on Jan 8, 2016 12:11 PM by onimurasame

    File path gets changed when passed through a different bundle

    onimurasame

      Hello all,

       

      I've been trying to pass an external file from a Bundle to another and when I call Bundle B's method from Bundle A... the path gets changed to my Jboss Fuse Home directory.

       

      My code looks like this:

       

      This is the implementation class that I'm trying to call from Bundle A:

       

      package com.externalxsl;
      
      
      import java.io.File;
      
      
      import javax.xml.transform.Source;
      import javax.xml.transform.stream.StreamSource;
      
      
      public class XSLTServiceImpl implements IXSLTService {
      
        @Override
        public Source getXSLTSource() {
        return new StreamSource(new File("c:\\messages\\schema\\example.xsd"));
        }
      
      }
      

       

      This is the blueprint to expose the method as a service:

      <?xml version="1.0" encoding="UTF-8"?>
      <blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="
             http://www.osgi.org/xmlns/blueprint/v1.0.0 http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd
             http://camel.apache.org/schema/blueprint http://camel.apache.org/schema/blueprint/camel-blueprint.xsd">
      
        <bean id="XSLTServiceImpl" class="com.externalxsl.XSLTServiceImpl" />
        <service ref="XSLTServiceImpl" interface="com.externalxsl.IXSLTService" />
      </blueprint>
      

       

      This is the actual caller, from bundle A, of the aforementioned method:

       

      /**
       * 
       */
      package com.transformer.impl;
      
      
      import javax.xml.transform.Source;
      
      
      import com.externalxsl.IXSLTService;
      import com.transformer.AbstractTransformer;
      
      
      /**
       * @author 
       */
      public class ClasspathTransformer extends AbstractTransformer {
      
      
        private IXSLTService externalXLST = null;
      
        @Override
        public Source getXSLT() {
        return getExternalXLST().getXSLTSource();
        }
      
      
        /**
        * @return the externalXLST
        */
        public IXSLTService getExternalXLST() {
        return externalXLST;
        }
      
      
        /**
        * @param externalXLST
        *            the externalXLST to set
        */
        public void setExternalXLST(IXSLTService externalXLST) {
        this.externalXLST = externalXLST;
        }
      
        public void init() {
              System.out.println("OSGi client started.");
              if (externalXLST != null) {
                  System.out.println("externalXLST.getXSLTSource()");
                  externalXLST.getXSLTSource();  // Invoke the OSGi service!
              }
          }
      }
      

       

       

      And this is the declaration of the bean and the route:

       

      <?xml version="1.0" encoding="UTF-8"?>
      <blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
             xmlns:camel="http://camel.apache.org/schema/blueprint"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://www.osgi.org/xmlns/blueprint/v1.0.0 http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd
             http://camel.apache.org/schema/blueprint http://camel.apache.org/schema/blueprint/camel-blueprint.xsd">
      
      
        <reference id="ClasspathXSLTReference" interface="ltf.externalxsl.IXSLTService"/>
      
        <bean id="ClasspathTransformater" class="ltf.transformer.impl.ClasspathTransformer" init-method="init">
        <property name="externalXLST" ref="ClasspathXSLTReference"/>
        </bean>
      
      
        <camelContext xmlns="http://camel.apache.org/schema/blueprint">
        <route>
        <from uri="activemq:JavaTransformation.IN" />
        <log message="Initiating transformation of message content = ${body}"
        loggingLevel="INFO" />
      
        <doTry>
        <log message="Initiating transformation of message content = ${body}"
        loggingLevel="INFO" />
        <bean ref="ClasspathTransformater" method="doTransformation" />
        <doCatch>
        <exception>java.lang.Exception</exception>
        <handled>
        <constant>false</constant>
        </handled>
        <log
        message="Transformation of ${id} raised and exception = ${exception.message}"
        loggingLevel="ERROR" />
        <transform>
        <simple>Exception Raised: ${exception.message} and your message was = ${body}</simple>
        </transform>
        <to uri="activemq:JavaTransformation.ERROR" />
        </doCatch>
        </doTry>
      
      
        <log message="Transformation of ${id} ended and delivering message to queue"
        loggingLevel="INFO" />
        <to uri="activemq:JavaTransformation.OUT" />
        </route>
        </camelContext>
      
      
      </blueprint>
      

       

      Any ideas?