Return-Path: X-Original-To: apmail-camel-users-archive@www.apache.org Delivered-To: apmail-camel-users-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id C2345CF49 for ; Mon, 24 Nov 2014 07:55:35 +0000 (UTC) Received: (qmail 64003 invoked by uid 500); 24 Nov 2014 07:55:35 -0000 Delivered-To: apmail-camel-users-archive@camel.apache.org Received: (qmail 63950 invoked by uid 500); 24 Nov 2014 07:55:35 -0000 Mailing-List: contact users-help@camel.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: users@camel.apache.org Delivered-To: mailing list users@camel.apache.org Received: (qmail 63938 invoked by uid 99); 24 Nov 2014 07:55:34 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 24 Nov 2014 07:55:34 +0000 X-ASF-Spam-Status: No, hits=-0.7 required=5.0 tests=RCVD_IN_DNSWL_LOW,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of tdudgeon.ml@gmail.com designates 209.85.212.182 as permitted sender) Received: from [209.85.212.182] (HELO mail-wi0-f182.google.com) (209.85.212.182) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 24 Nov 2014 07:55:28 +0000 Received: by mail-wi0-f182.google.com with SMTP id h11so4788809wiw.9 for ; Sun, 23 Nov 2014 23:55:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=message-id:date:from:user-agent:mime-version:to:subject:references :in-reply-to:content-type:content-transfer-encoding; bh=Tlf0VB3FE7/nz9cERuH5nyFCAZcMgrVjz0QrsjbyQRE=; b=Z5og4mkeZg8ZK9oCb92sFn4cHEUyvygMnbZ1/eR9LQvEZNLYLzLKA8G8zXXfEt3eD2 ZEyc9dCUd7xEa7iapXrkoHMxvexXX0mIHhnWZbhM4wpHpye2UgNBYD39O9vUNDyXYF4X 2rdj6lrFNhgrw7KnvxDods3nl6tUn2MY3hvQ+3Y3SVrok5uqYtJ6k6MRx8LEotg9vuUj E1chXvbgO7bSiQPbWddENzNlk6O34W2xIjJuvoVWsELDK6cMq5JrouE9v6TEU2U1gNv6 SKOIY4EAwxQkIYplIUfn4GidDrPj8Ds66MGsbTg6LCtc8w6jVu4Pvo5/inFT3X81VD+H i4+A== X-Received: by 10.194.170.232 with SMTP id ap8mr31658805wjc.2.1416815707470; Sun, 23 Nov 2014 23:55:07 -0800 (PST) Received: from timbomac-2.local (204-185.199-178.cust.bluewin.ch. [178.199.185.204]) by mx.google.com with ESMTPSA id j8sm10869782wib.10.2014.11.23.23.55.06 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Sun, 23 Nov 2014 23:55:06 -0800 (PST) Message-ID: <5472E458.1010902@gmail.com> Date: Mon, 24 Nov 2014 07:55:04 +0000 From: Tim Dudgeon User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.9; rv:24.0) Gecko/20100101 Thunderbird/24.6.0 MIME-Version: 1.0 To: users@camel.apache.org Subject: Re: POJO binding with the Rest DSL References: <546F6ECF.4030107@gmail.com> <546F7938.4020302@gmail.com> In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Checked: Checked by ClamAV on apache.org Yes, I understand that, and got it working that way. I had misunderstood where the POJO binding fitted in. Thanks for your help. Tim On 22/11/2014 09:27, Claus Ibsen wrote: > Hi > > The rest DSL is on the other side, eg on the server side, to exposes > Camel routes as REST services. > Not on the client side how to call another REST service. > > For POJO -> Json you can use jackson to turn that into json. > > On Fri, Nov 21, 2014 at 6:41 PM, Tim Dudgeon wrote: >> OK, that figures, and I got it to work. >> But it seems to circumvent the whole purpose of the POJO binding with rest >> DSL. >> How are you supposed to send POJO to Rest DSL within Camel. >> I briefly tried using restlet like this: >> >> t.requestBody('restlet:http://$BASE_URL/foo?restletMethod=POST', p) >> >> but that didn't work. >> >> Thanks >> Tim >> >> >> >> >> >> On 21/11/2014 17:12, Claus Ibsen wrote: >>> Hi >>> >>> Its the client code you write to send the Person using http4. It does >>> not know how to convert that to json. You need to convert it to json >>> first, and then send that instead of the Person java object. >>> >>> On Fri, Nov 21, 2014 at 5:56 PM, Tim Dudgeon >>> wrote: >>>> I'm having problems getting POJO binding working with the Rest DSL. >>>> I put together a simple example in Groovy, but it fails: >>>> >>>> >>>> >>>> package com.im.examples.search >>>> >>>> import org.apache.camel.CamelContext >>>> import org.apache.camel.ProducerTemplate >>>> import org.apache.camel.builder.RouteBuilder >>>> import org.apache.camel.impl.DefaultCamelContext >>>> import org.apache.camel.model.rest.RestBindingMode >>>> import org.apache.camel.model.dataformat.JsonLibrary >>>> >>>> String HOST = 'localhost' >>>> String PORT = '43256' >>>> String BASE_URL = "$HOST:$PORT/search" >>>> >>>> class Person { >>>> String firstName >>>> String lastName >>>> } >>>> >>>> CamelContext camelContext = new DefaultCamelContext() >>>> camelContext.addRoutes(new RouteBuilder() { >>>> def void configure() { >>>> >>>> restConfiguration().component("restlet").host(HOST).port(PORT).bindingMode(RestBindingMode.json) >>>> rest("/search") >>>> .post("/foo").type(Person.class).to("direct:end") >>>> from('direct:end') >>>> .log('${body}') >>>> .transform().constant('Welcome') >>>> from('direct:testmarshal') >>>> .marshal().json(JsonLibrary.Jackson) >>>> .log('JSON: ${body}') >>>> } >>>> }) >>>> camelContext.start() >>>> >>>> Person p = new Person(firstName: 'John', lastName: 'Doe') >>>> ProducerTemplate t = camelContext.createProducerTemplate() >>>> t.sendBody('direct:testmarshal', p) >>>> def resp = t.requestBody("http4:$BASE_URL/foo", p) >>>> println "resp: $resp" >>>> >>>> camelContext.stop() >>>> >>>> >>>> >>>> >>>> The error I get is: >>>> >>>> >>>> Caused by: org.apache.camel.InvalidPayloadException: No body available of >>>> type: java.io.InputStream but has value: >>>> com.im.examples.search.Person@6c4b8217 of type: >>>> com.im.examples.search.Person on: Message: >>>> com.im.examples.search.Person@6c4b8217. Caused by: No type converter >>>> available to convert from type: com.im.examples.search.Person to the >>>> required type: java.io.InputStream with value >>>> com.im.examples.search.Person@6c4b8217. Exchange[Message: >>>> com.im.examples.search.Person@6c4b8217]. Caused by: >>>> [org.apache.camel.NoTypeConversionAvailableException - No type converter >>>> available to convert from type: com.im.examples.search.Person to the >>>> required type: java.io.InputStream with value >>>> com.im.examples.search.Person@6c4b8217] >>>> at >>>> >>>> org.apache.camel.impl.MessageSupport.getMandatoryBody(MessageSupport.java:101) >>>> at >>>> >>>> org.apache.camel.component.http4.HttpProducer.createRequestEntity(HttpProducer.java:461) >>>> at >>>> >>>> org.apache.camel.component.http4.HttpProducer.createMethod(HttpProducer.java:368) >>>> at >>>> >>>> org.apache.camel.component.http4.HttpProducer.process(HttpProducer.java:106) >>>> at >>>> >>>> org.apache.camel.util.AsyncProcessorConverterHelper$ProcessorToAsyncProcessorBridge.process(AsyncProcessorConverterHelper.java:61) >>>> at >>>> >>>> org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:191) >>>> at >>>> >>>> org.apache.camel.processor.UnitOfWorkProducer.process(UnitOfWorkProducer.java:74) >>>> at >>>> >>>> org.apache.camel.impl.ProducerCache$2.doInProducer(ProducerCache.java:375) >>>> at >>>> >>>> org.apache.camel.impl.ProducerCache$2.doInProducer(ProducerCache.java:343) >>>> at >>>> org.apache.camel.impl.ProducerCache.doInProducer(ProducerCache.java:233) >>>> at >>>> org.apache.camel.impl.ProducerCache.sendExchange(ProducerCache.java:343) >>>> at org.apache.camel.impl.ProducerCache.send(ProducerCache.java:201) >>>> at >>>> >>>> org.apache.camel.impl.DefaultProducerTemplate.send(DefaultProducerTemplate.java:128) >>>> at >>>> >>>> org.apache.camel.impl.DefaultProducerTemplate.sendBody(DefaultProducerTemplate.java:132) >>>> ... 28 more >>>> Caused by: org.apache.camel.NoTypeConversionAvailableException: No type >>>> converter available to convert from type: com.im.examples.search.Person >>>> to >>>> the required type: java.io.InputStream with value >>>> com.im.examples.search.Person@6c4b8217 >>>> at >>>> >>>> org.apache.camel.impl.converter.BaseTypeConverterRegistry.mandatoryConvertTo(BaseTypeConverterRegistry.java:182) >>>> at >>>> >>>> org.apache.camel.impl.MessageSupport.getMandatoryBody(MessageSupport.java:99) >>>> ... 41 more >>>> >>>> >>>> I thought I had carefully followed the documentation :-( >>>> Can anyone help spot what is wrong? >>>> >>>> Thanks >>>> Tim >>>> >>> > >