Hi If the data you send over Jetty (HTTP) is already serialized into google protobuf, then you need to unmarshal that back into an object. Assuming you want to work with that object.
The Camel data format just makes it easier to do the marshal / unmarshal without knowing the API for doing that with protobuf. So you should not cast the payload to Camel DataFormat. As the Camel DataFormat is NOT serialized and send over the wire. Instead use the Google protobuf API to unmarshal it back to an object. Or use the Camel DataFormat API for doing that. On Mon, Dec 6, 2010 at 4:04 PM, Paulo Roberto <paulo.lis...@gmail.com> wrote: > Guys, > > I want build a test using protocolbuf inside a Jetty body. > > import java.io.InputStream; > > import junit.framework.TestCase; > > import org.apache.camel.CamelContext; > import org.apache.camel.Exchange; > import org.apache.camel.Message; > import org.apache.camel.Processor; > import org.apache.camel.ProducerTemplate; > import org.apache.camel.builder.RouteBuilder; > import org.apache.camel.dataformat.protobuf.ProtobufDataFormat; > import org.apache.camel.impl.DefaultCamelContext; > import org.apache.camel.spi.DataFormat; > > import br.com.novtis.proto.examples.ActivationRequest; > import br.com.novtis.proto.examples.ActivationRequest.PinPad.Builder; > > public class ProtoConverterJettyTest extends TestCase { > > public void testProtoConverter() throws Exception { > CamelContext context = new DefaultCamelContext(); > // Default Direct Route > context.addRoutes(new RouteBuilder() { > �...@override > public void configure() throws Exception { > > from("jetty:http://0.0.0.0:6920/proto").process(new Processor() { > public void process(Exchange exchange) > throws Exception { > Message message = > exchange.getIn(); > DataFormat format = > (DataFormat) > message.getBody(org.apache.camel.model.dataformat.ProtobufDataFormat.class); > //ProtobufDataFormat format = > (ProtobufDataFormat) > exchange.getIn().getBody(); > //format.toString(); > } > }).to("mock:reverse"); > > //unmarshal(format).to("mock:reverse"); > > } > }); > context.start(); > > ProducerTemplate template = context.createProducerTemplate(); > > Builder pinpad = ActivationRequest.PinPad.newBuilder(); > pinpad.setManufacturer("Manufator"); > pinpad.setVersion("0.1"); > pinpad.setSerialNumber("01030303"); > pinpad.setModel("modelv2"); > > // Encapsule on DataFormat > //ProtobufDataFormat format = new > ProtobufDataFormat(ActivationRequest.PinPad.getDefaultInstance() ); > DataFormat protob = new > ProtobufDataFormat(pinpad.build().getDefaultInstance() ); > > // Make me happy! > template.requestBody("http://127.0.0.1:6920/proto",protob , > String.class); > } > } > > I get this error! > Caused by: org.apache.camel.InvalidPayloadException: No body available > of type: java.io.InputStream but has value: > org.apache.camel.dataformat.protobuf.protobufdatafor...@ffeef1 of > type: org.apache.camel.dataformat.protobuf.ProtobufDataFormat on: > Message: org.apache.camel.dataformat.protobuf.protobufdatafor...@ffeef1. > Caused by: No type converter available to convert from type: > org.apache.camel.dataformat.protobuf.ProtobufDataFormat to the > required type: java.io.InputStream with value > org.apache.camel.dataformat.protobuf.protobufdatafor...@ffeef1. > Exchange[Message: > org.apache.camel.dataformat.protobuf.protobufdatafor...@ffeef1]. > Caused by: [org.apache.camel.NoTypeConversionAvailableException - No > type converter available to convert from type: > org.apache.camel.dataformat.protobuf.ProtobufDataFormat to the > required type: java.io.InputStream with value > org.apache.camel.dataformat.protobuf.protobufdatafor...@ffeef1] > at > org.apache.camel.impl.MessageSupport.getMandatoryBody(MessageSupport.java:102) > at > org.apache.camel.component.http.HttpProducer.createRequestEntity(HttpProducer.java:326) > at > org.apache.camel.component.http.HttpProducer.createMethod(HttpProducer.java:262) > at > org.apache.camel.component.http.HttpProducer.process(HttpProducer.java:70) > at > org.apache.camel.impl.converter.AsyncProcessorTypeConverter$ProcessorToAsyncProcessorBridge.process(AsyncProcessorTypeConverter.java:50) > at > org.apache.camel.processor.UnitOfWorkProcessor.process(UnitOfWorkProcessor.java:99) > at > org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:91) > at > org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:85) > at > org.apache.camel.processor.UnitOfWorkProducer.process(UnitOfWorkProducer.java:63) > at > org.apache.camel.impl.ProducerCache$1.doInProducer(ProducerCache.java:333) > at > org.apache.camel.impl.ProducerCache$1.doInProducer(ProducerCache.java:1) > at > org.apache.camel.impl.ProducerCache.doInProducer(ProducerCache.java:208) > at > org.apache.camel.impl.ProducerCache.sendExchange(ProducerCache.java:303) > at org.apache.camel.impl.ProducerCache.send(ProducerCache.java:171) > at > org.apache.camel.impl.DefaultProducerTemplate.send(DefaultProducerTemplate.java:114) > at > org.apache.camel.impl.DefaultProducerTemplate.sendBody(DefaultProducerTemplate.java:118) > ... 23 more > Caused by: org.apache.camel.NoTypeConversionAvailableException: No > type converter available to convert from type: > org.apache.camel.dataformat.protobuf.ProtobufDataFormat to the > required type: java.io.InputStream with value > org.apache.camel.dataformat.protobuf.protobufdatafor...@ffeef1 > at > org.apache.camel.impl.converter.BaseTypeConverterRegistry.mandatoryConvertTo(BaseTypeConverterRegistry.java:142) > at > org.apache.camel.impl.MessageSupport.getMandatoryBody(MessageSupport.java:100) > ... 38 more > > > How I can make this test work ? My first target is manipulate the > ProtocolBuffer inside a processor and not get in a unmarshal or > marshal stuff. > > Thanks. > -- Claus Ibsen ----------------- FuseSource Email: cib...@fusesource.com Web: http://fusesource.com Twitter: davsclaus Blog: http://davsclaus.blogspot.com/ Author of Camel in Action: http://www.manning.com/ibsen/