Hi,

You are send the protocolbuf dataformat , not marshalling or unmarshalling the objects.

Please check out this unit test[1] of camel protocol buffer as an example.

[1] https://svn.apache.org/repos/asf/camel/trunk/components/camel-protobuf/src/test/java/org/apache/camel/dataformat/protobuf/ProtobufMarshalAndUnmarshallTest.java

On 12/6/10 11:04 PM, Paulo Roberto 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.



--
Willem
----------------------------------
FuseSource
Web: http://www.fusesource.com
Blog:    http://willemjiang.blogspot.com (English)
         http://jnn.javaeye.com (Chinese)
Twitter: willemjiang

Reply via email to