Thank you willem....
I am able to write in a file using CamelContextFactory...
I am adding the way i did for future reference.
1) Create an Activator class which implements BundleActivator.
Store the BundleContext variable in a static variable added by us in the
Activator class.
Do the following code where u want to create the CamelContext instance
bundleContext = Activator.getBundleContext(); //static
BundleContext
camelContextFactory = new CamelContextFactory();
camelContextFactory.setBundleContext(bundleContext);
camel = camelContextFactory.createContext();
camel.addComponent("file", new FileComponent());
camel.start();
Harbeer kadian
willem.jiang wrote:
>
> Hi,
>
> Since there are some difference between the OSGi and normal java class
> for loading the files in META-INF (camel component, lanaguage and type
> converter finding are based on it ) . We introduce a camel-osgi module
> to resolve these kind of issue.
>
> You can use the CamelContextFactory in the camel-osig module to create
> the CamelContext and you need to set the BundleContext before calling
> the createContext method.
>
> Willem
>
>
> Harbeer Kadian wrote:
>> Hi,
>>
>> I created one webservice in the OSGI format and installed it in the
>> servicemix.
>> The webservice worked fine and i was able to send and receive requests
>> through SoapUI software.
>>
>> I tried to add some apache camel code inside this so that i can send a
>> string to a file.
>>
>> The implementation is as follows
>> This is my webservice implementation class.
>>
>> package com.webservice.calculator;
>>
>> import java.util.logging.Logger;
>> import javax.jws.WebMethod;
>> import javax.jws.WebParam;
>> import javax.jws.WebResult;
>> import javax.jws.WebService;
>> import javax.xml.bind.annotation.XmlSeeAlso;
>> import javax.xml.ws.RequestWrapper;
>> import javax.xml.ws.ResponseWrapper;
>>
>> import org.apache.camel.CamelContext;
>> import org.apache.camel.Component;
>> import org.apache.camel.Endpoint;
>> import org.apache.camel.Exchange;
>> import org.apache.camel.Producer;
>> import org.apache.camel.ProducerTemplate;
>> import org.apache.camel.component.file.FileComponent;
>> import org.apache.camel.component.log.LogComponent;
>> import org.apache.camel.impl.DefaultCamelContext;
>>
>> import com.progress.pso.payments_api.PaymentsApi;
>>
>> /**
>> * This class was generated by Apache CXF 2.2.5
>> * Tue Dec 01 17:46:59 IST 2009
>> * Generated source version: 2.2.5
>> *
>> */
>>
>> @javax.jws.WebService(
>> serviceName = "CalculatorService",
>> portName = "CalculatorSoapPort",
>> targetNamespace =
>> "http://calculator.webservice.com",
>> wsdlLocation =
>> "file:/D:/harbeer/Maven_Project/payment-web-service-osgi/src/main/resources/wsdl/Calculator.wsdl",
>> endpointInterface =
>> "com.webservice.calculator.CalculatorPortType")
>>
>> public class CalculatorPortTypeImpl implements CalculatorPortType {
>>
>> private static final Logger LOG =
>> Logger.getLogger(CalculatorPortTypeImpl.class.getName());
>> private PaymentsApi paymentApi;
>> private CamelContext camel;
>> private ProducerTemplate template;
>>
>>
>> public CalculatorPortTypeImpl() throws Exception {
>> camel = new DefaultCamelContext();
>> template = camel.createProducerTemplate();
>> camel.addComponent("file", new FileComponent());
>> camel.start();
>> }
>>
>> public void setPaymentApi(PaymentsApi paymentApi) {
>> this.paymentApi = paymentApi;
>> }
>>
>> /* (non-Javadoc)
>> * @see
>> com.webservice.calculator.CalculatorPortType#subtractNumbers(java.math.BigInteger
>>
>> inputOne ,)java.math.BigInteger inputTwo )*
>> */
>> public java.math.BigInteger subtractNumbers(java.math.BigInteger
>> inputOne,java.math.BigInteger inputTwo) {
>> try {
>> sendToCamelFile("harbeer");
>> return paymentApi.subtractNumbers(inputOne, inputTwo);
>> } catch (Exception ex) {
>> ex.printStackTrace();
>> throw new RuntimeException(ex);
>> }
>> }
>>
>>
>> private void sendToCamelFile(String name) {
>> try {
>>
>> // get the log component
>> Component component = camel.getComponent("file");
>>
>> Endpoint endpoint =
>> component.createEndpoint("file:///D:/harbeer");
>> Exchange exchange = endpoint.createExchange();
>> exchange.getIn().setBody(name);
>> exchange.getIn().setHeader(FileComponent.HEADER_FILE_NAME,
>> "harbeer.txt");
>>
>> // now we want to send the exchange to this endpoint and we
>> then
>> need a producer
>> // for this, so we create and start the producer.
>> Producer producer = endpoint.createProducer();
>> System.out.println(producer);
>> producer.start();
>> System.out.println(name);
>> producer.process(exchange);
>> producer.stop();
>>
>> } catch (Exception e) {
>> // we ignore any exceptions and just rethrow as runtime
>> throw new RuntimeException(e);
>>
>> }
>>
>> }
>>
>> }
>>
>> I installed this new webservice implementation inside servicemix 4 as an
>> osgi bundle.
>> I got following exception when i called webservice method
>> subtractNumbers();
>>
>>
>> Caused by: org.apache.camel.NoTypeConversionAvailableException: No type
>> converte
>> r available to convert from type: class
>> org.apache.camel.component.file.FileMess
>> age to the required type: java.io.InputStream with value FileMessage:
>> D:\harbeer
>>
>> at
>> org.apache.camel.impl.converter.DefaultTypeConverter.doConvertTo(Defa
>> ultTypeConverter.java:147)
>> at
>> org.apache.camel.impl.converter.DefaultTypeConverter.convertTo(Defaul
>> tTypeConverter.java:90)
>> at
>> org.apache.camel.impl.converter.DefaultTypeConverter.convertTo(Defaul
>> tTypeConverter.java:86)
>> at
>> org.apache.camel.impl.MessageSupport.getBody(MessageSupport.java:85)
>> at
>> org.apache.camel.impl.MessageSupport.getBody(MessageSupport.java:52)
>> at
>> org.apache.camel.util.ExchangeHelper.getMandatoryInBody(ExchangeHelpe
>> r.java:130)
>> at
>> org.apache.camel.component.file.FileProducer.process(FileProducer.jav
>> a:78)
>> at
>> org.apache.camel.component.file.FileProducer.process(FileProducer.jav
>> a:61)
>> at
>> com.webservice.calculator.CalculatorPortTypeImpl.sendToCamelFile(Calc
>> ulatorPortTypeImpl.java:129)
>> ... 31 more
>>
>> Please help if i am missing some thing.
>>
>> With Regards
>> Harbeer Kadian
>
>
>
--
View this message in context:
http://old.nabble.com/Getting-error-when-using-Apache-camel-inside-servicemix.-tp26635823p26689871.html
Sent from the ServiceMix - User mailing list archive at Nabble.com.