mrinalsharma commented on issue #500:
URL: https://github.com/apache/camel-karavan/issues/500#issuecomment-1293939418

   I don't have any specific problem to solve, I was trying jbang/karavan 
capabilities. In my test case, pipeline looks like
   
   Rest Consumer(with some string body) => sort( tokanize(\n)) 
   
   Sort will return a sorted java.util.LinkedList and restResponse need an 
InputStream. That's why a converter is needed from List to InputStream.
   
   BTW, Is there a way to Eagerly create a Bean, I am following the [steps 
](https://quarkus.io/guides/lifecycle) but StartupEvent  is not available 
during jbang export.
   ```
   //DEPS io.quarkus:quarkus-core
   import javax.inject.Inject;
   import javax.annotation.PostConstruct;
   import javax.enterprise.context.ApplicationScoped;
   import java.util.stream.Collectors;
   import java.util.List;
   import org.apache.camel.CamelContext;
   import java.io.InputStream;
   import org.apache.camel.TypeConverter;
   import java.io.ByteArrayInputStream;
   import java.util.LinkedList;
   import org.apache.camel.Exchange;
   import org.apache.camel.support.TypeConverterSupport;
   import org.jboss.logging.Logger;
   import org.apache.camel.Exchange;
   import org.apache.camel.Processor;
   import javax.inject.Named;
   import javax.inject.Singleton;
   import javax.enterprise.event.Observes;
   import io.quarkus.runtime.ShutdownEvent;
   import io.quarkus.runtime.StartupEvent;
   @Singleton @Named("myconverter")
   public class Ioconverter {
        private static final Logger LOG = Logger.getLogger(Ioconverter.class);
       CamelContext context;
   
       @Inject 
       Ioconverter(CamelContext contex) {
           this.context = context;
       }
   
       void startup(@Observes StartupEvent event) { 
           LOG.info("The application is starting...");
       }
   
       @PostConstruct
       public void init() {
           LOG.info("Adding converter");
           
context.getTypeConverterRegistry().addTypeConverter(java.io.InputStream.class, 
java.util.LinkedList.class, new MyConverter());
       }
   
       static class MyConverter extends TypeConverterSupport {
           public <T> T convertTo(Class<T> type, Object value) {
               // converter from value to the MyOrder bean
               return (T) new java.io.ByteArrayInputStream("My Hello 
World".getBytes());
           }
           public <T> T convertTo(Class<T> type, Exchange exchange, Object 
value) {
               // this method with the Exchange parameter will be preferd by 
Camel to invoke
               // this allows you to fetch information from the exchange during 
convertions
               // such as an encoding parameter or the likes
               return convertTo(type, value);
           }
           public <T> T mandatoryConvertTo(Class<T> type, Object value) {
               return convertTo(type, value);
           }
           public <T> T mandatoryConvertTo(Class<T> type, Exchange exchange, 
Object value) {
               return convertTo(type, value);
           }
       }
   }
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@camel.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to