Guillaume

Thabnks for the input. Responses inline

gnodet wrote:
> 
> Have you tried using the JaxenXPathExpression instead of the
> JaxenStringXPathExpression ?
> 
> Yes, I got the same result.
> 
> Also, I think you need to change the getContentToSend() method because
> using
> toString() on the result won't work.  Try using the
> org.apache.servicemix.jbi.jaxp.*SourceTransformer* to convert the DOM node
> to a String instead.
> 
> Okay, I'll play with this but the call to contentExpression.evaluate() in
> getContentToSend() returns a String object. At any rate I'll give it a
> shot and let you know how it goes.
> 
> Thanks
> Tom
> 
> On Wed, Apr 2, 2008 at 11:27 PM, Tom Purcell
> <[EMAIL PROTECTED]>
> wrote:
> 
>>
>> Guillaume
>>
>> Below is all of what I'm doing. Notice in the logs at the bottom that
>> what
>> comes in on the NM is of type DOMSource but the object returned by the
>> contentExpression.evaluate() method is of type String. I think it want I
>> want is for that to be a DOMSource too. I also see the "Content is not
>> allowed in prolog" meesage but I think that is caused by the fact that my
>> content is just the values and not the XML.
>>
>> Here's the xbean config:
>>
>>    <http:provider service="wile:wileRestService"
>>                   interfaceName="wileCreate"
>>                   endpoint="wileRestCreate"
>>                   marshaler="#createMarshaler"/>
>>
>>    <bean id="createMarshaler" class="jbi.marshal.RestProviderMarshaler">
>>        <property name="locationURIExpression">
>>            <bean
>> class="org.apache.servicemix.expression.JaxenStringXPathExpression">
>>                <constructor-arg
>> value="concat('
>> http://localhost:8080/wile-www/assetmanagement/assetservice/
>> ',/assetRequest/perspective)"/>
>>            </bean>
>>        </property>
>>        <property name="method"
>>                  value="POST"/>
>>        <property name="contentType"
>>                  value="application/x-www-form-urlencoded"/>
>>        <property name="contentExpression">
>>            <bean
>> class="org.apache.servicemix.expression.JaxenStringXPathExpression">
>>                <constructor-arg value="//asset"/>
>>            </bean>
>>        </property>
>>    </bean>
>> </pre>
>>
>> In my RestProviderMarshaler class I added a property for
>> contentExpression
>> and replaced the createRequest method. Here are the relevant methods:
>>
>>    public void createRequest(MessageExchange exchange, NormalizedMessage
>> inMsg, SmxHttpExchange httpExchange) throws Exception {
>>        logger.debug("*** Before CREATE MessageExchange: " + exchange);
>>        logger.debug("*** NM In Content: " + inMsg.getContent());
>>        logger.debug("*** LocationURI: " + getLocationUri(exchange,
>> inMsg));
>>
>>        httpExchange.setURL(getLocationUri(exchange, inMsg));
>>        httpExchange.addRequestHeader(HttpHeaders.HOST_BUFFER, new
>> ByteArrayBuffer(new URI(getLocationUri(exchange, inMsg)).getHost()));
>>        httpExchange.setMethod(getMethod(exchange, inMsg));
>>        httpExchange.setRequestHeader(HttpHeaders.CONTENT_TYPE,
>> getContentType(exchange, inMsg));
>>
>>        if (getHeaders() != null) {
>>            for (Map.Entry<String, String> e : getHeaders().entrySet()) {
>>                httpExchange.setRequestHeader(e.getKey(), e.getValue());
>>            }
>>        }
>>
>>        String contentToSend = getContentToSend(exchange, inMsg);
>>        logger.debug("*** Content: " + contentToSend);
>>
>>        if (contentToSend != null) {
>>            httpExchange.setRequestContent(new
>> ByteArrayBuffer(contentToSend.getBytes()));
>>        }
>>    }
>>
>>    protected String getContentToSend(MessageExchange exchange,
>> NormalizedMessage inMsg) throws Exception {
>>        String content = null;
>>        if (contentExpression != null) {
>>            Object o = contentExpression.evaluate(exchange, inMsg);
>>            logger.debug("*** Content Object Type: " + o.getClass());
>>            content = (o != null) ? o.toString() : null;
>>        }
>>        if (content == null) {
>>            throw new IllegalStateException("Unable to find Content for
>> exchange");
>>        }
>>        return content;
>>    }
>>
>> Here is what I see from the debugs:
>>
>> 16:18:59,407 - DEBUG - RestProviderMarshaler          - *** Before CREATE
>> MessageExchange: InOut[
>>  id: ID:127.0.0.2-11910ec49ca-3:4
>>  status: Active
>>  role: provider
>>  service:
>> {http://www.sungard.com/wile}wileRestService<http://www.sungard.com/wile%7DwileRestService>
>>  endpoint: wileRestCreate
>>  in: <?xml version="1.0"
>> encoding="UTF-8"?><assetRequest><perspective>asset</perspective><asset
>> name="TestAsset"> <class_type>BigAsset</class_type> <description>This is
>> a
>> Test Asset</description> <serial_number>12345</serial_number>
>> <enabled>true</enabled> <category guid="67890" value="Default"/> <type
>> guid="09876" value="Default"/> <state guid="54321" value="Default"/>
>> </asset> </assetRequest>
>> ]
>> 16:18:59,408 - DEBUG - RestProviderMarshaler          - *** NM In
>> Content:
>> [EMAIL PROTECTED]
>> 16:18:59,408 - DEBUG - RestProviderMarshaler          - *** LocationURI:
>> http://localhost:8080/wile-www/assetmanagement/assetservice/asset
>> 16:18:59,409<http://localhost:8080/wile-www/assetmanagement/assetservice/asset16:18:59,409>-
>> DEBUG - RestProviderMarshaler          - *** Content Object
>> Type: class java.lang.String
>> 16:18:59,409 - DEBUG - RestProviderMarshaler          - *** Content:
>> BigAsset This is a Test Asset 12345 true
>> 16:18:59,446 - DEBUG - DeliveryChannelImpl            - Send
>> ID:127.0.0.2-11910ec49ca-3:4 in DeliveryChannel{servicemix-http}
>> [Fatal Error] :1:1: Content is not allowed in prolog.
>> 16:18:59,451 - TRACE - DeliveryChannelImpl            - Sent: InOut[
>>  id: ID:127.0.0.2-11910ec49ca-3:4
>>  status: Active
>>  role: provider
>>  service:
>> {http://www.sungard.com/wile}wileRestService<http://www.sungard.com/wile%7DwileRestService>
>>  endpoint: wileRestCreate
>>  in: <?xml version="1.0"
>> encoding="UTF-8"?><assetRequest><perspective>asset</perspective><asset
>> name="TestAsset"> <class_type>BigAsset</class_type> <description>This is
>> a
>> Test Asset</description> <serial_number>12345</serial_number>
>> <enabled>true</enabled> <category guid="67890" value="Default"/> <type
>> guid="09876" value="Default"/> <state guid="54321" value="Default"/>
>> </asset> </assetRequest>
>>  fault: Unable to display: org.xml.sax.SAXParseException: Content is not
>> allowed in prolog.
>> ]
>> 16:18:59,454 - DEBUG - SedaFlow                       - Called Flow send
>>
>> Thanks
>> Tom
>>
>>
>> gnodet wrote:
>> >
>> > I suppose the creation of the content does not support writing an xml
>> > element and maybe use toString() or something like that to create the
>> > content of the request.  Could you paste the endpoint definition and
>> > snippet
>> > of code, I'm not sure to fully understand your configuration.
>> > I think if you use a marshaler, you can really do anything you need.
>> I'm
>> > sure we could come with something reusable using an expression for the
>> > URL,
>> > the method and the content.
>> >
>> > On Wed, Apr 2, 2008 at 2:33 PM, Tom Purcell
>> > <[EMAIL PROTECTED]>
>> > wrote:
>> >
>> >>
>> >> Guillaume
>> >>
>> >> The message gets sent to the correct URI but the issue is the content
>> of
>> >> the
>> >> message. I need to send the XML (<foo>bar</foo>) but what gets
>> returned
>> >> by
>> >> contentExpression.evaluate(exchange, inMsg), subsequently sent to the
>> >> RESTful service, is just the values (bar).
>> >>
>> >> At this point I guess its really a Jaxen question. Can you get it to
>> >> return
>> >> the XML instead of just the values? Otherwise some other parsing
>> strategy
>> >> is
>> >> needed. However, I really liked the idea of just defining an XPath
>> >> expression on the endpoint. It seems it would make the marshaler
>> pretty
>> >> flexible.
>> >>
>> >> Thanks
>> >> Tom
>> >>
>> >>
>> >>
>> >> gnodet wrote:
>> >> >
>> >> > Well, it sounds realy good.
>> >> > What exactly does not work when using POST with your marshaler ?
>> >> >
>> >> > On Wed, Apr 2, 2008 at 12:00 AM, Tom Purcell
>> >> > <[EMAIL PROTECTED]>
>> >> > wrote:
>> >> >
>> >> >>
>> >> >> Guillaume
>> >> >>
>> >> >> Okay, I'm new to REST so I may be missing something there too but
>> this
>> >> is
>> >> >> where I'm at. SMX will receive a JMS message with an XML payload.
>> The
>> >> XML
>> >> >> will have two high level nodes. One node's value will be the
>> service
>> >> to
>> >> >> call
>> >> >> (will become part of the REST URL). The other node will be a big
>> chunk
>> >> of
>> >> >> XML to be POSTed to the service. The content-type is
>> >> >> x-www-form-urlencoded.
>> >> >>
>> >> >> I extended DefaultHttpProviderMarshaler and I call
>> >> >> httpExchange.setRequestContent(bigXmlChunkContentOfTheSecondNode).
>> >> >>
>> >> >> This almost works. I use JaxenStringXPathExpression to get the
>> value
>> >> of
>> >> >> the
>> >> >> first node and set the REST URL. Then my class has a new property,
>> >> >> contentExpression, also a JaxenStringXPathExpression. I use this to
>> >> >> define
>> >> >> the XPath to the second node, the one with the big chunk of XML,
>> but
>> >> it
>> >> >> adds
>> >> >> the values of the second node. What I need is the chunk of XML,
>> >> elements,
>> >> >> attributes and all.
>> >> >>
>> >> >> I guess I could introduce a Saxon endpoint to do a transformation
>> and
>> >> a
>> >> >> router to send the message to different HTTP endpoints based on the
>> >> first
>> >> >> node but that seems a lot less elegant than just dynamically
>> >> determining
>> >> >> the
>> >> >> REST URL in the marshaler. It works fine for GETs but then POST,
>> I'm
>> >> >> learning, is a different story.
>> >> >>
>> >> >> Any thoughts?
>> >> >>
>> >> >> Thanks
>> >> >> Tom
>> >> >>
>> >> >>
>> >> >> gnodet wrote:
>> >> >> >
>> >> >> > I really think the best way would be to create your own marshaler
>> if
>> >> >> the
>> >> >> > default one does not work for you.  If you come up with something
>> >> >> generic
>> >> >> > enough feel free to contribute it back.  However, the
>> >> >> > DefaultHttpProviderMarshaler should send a POST request if the
>> input
>> >> >> > message
>> >> >> > is not null, but this is more like a soap POST rather than a form
>> >> post
>> >> >> > with
>> >> >> > key/value pairs.  Is that what you'd need ?  How do you extract
>> the
>> >> >> > key/value pairs from the exchange ?
>> >> >> >
>> >> >> > On Tue, Apr 1, 2008 at 3:26 PM, Tom Purcell
>> >> >> > <[EMAIL PROTECTED]>
>> >> >> > wrote:
>> >> >> >
>> >> >> >>
>> >> >> >> Hello
>> >> >> >>
>> >> >> >> I'm trying to use the servicemix-http http:provider to call a
>> >> RESTful
>> >> >> >> service. GET works fine but I'm having trouble trying to
>> configure
>> >> it
>> >> >> to
>> >> >> >> do
>> >> >> >> a post. It appears to me that DefaultHttpProviderMarshaler does
>> not
>> >> >> >> directly
>> >> >> >> support this and so I must write my own Marshaler to set the
>> >> content.
>> >> >> My
>> >> >> >> first question is just a request to verify that is correct and
>> that
>> >> >> I'm
>> >> >> >> not
>> >> >> >> missing something.
>> >> >> >>
>> >> >> >> My next question is about
>> >> >> >> http://issues.apache.org/activemq/browse/SM-580
>> >> >> >> SM-580 <http://issues.apache.org/activemq/browse/SM-580SM-580> .
>> >> This
>> >> >> >> appears to address this situation although I'm not certain it
>> >> >> >> does so in a RESTful way (I'm new to REST). SM-580 appears to be
>> >> >> >> scheduled
>> >> >> >> for 3.3 so is this what I would use once 3.3 is released and
>> when
>> >> is
>> >> >> 3.3
>> >> >> >> scheduled for release?
>> >> >> >>
>> >> >> >> Thanks
>> >> >> >> Tom
>> >> >> >> --
>> >> >> >> View this message in context:
>> >> >> >>
>> >> >>
>> >>
>> http://www.nabble.com/servicemix-http-Post-support-tp16418421s12049p16418421.html
>> >> >> >> Sent from the ServiceMix - User mailing list archive at
>> Nabble.com.
>> >> >> >>
>> >> >> >>
>> >> >> >
>> >> >> >
>> >> >> > --
>> >> >> > Cheers,
>> >> >> > Guillaume Nodet
>> >> >> > ------------------------
>> >> >> > Blog: http://gnodet.blogspot.com/
>> >> >> >
>> >> >> >
>> >> >>
>> >> >> --
>> >> >> View this message in context:
>> >> >>
>> >>
>> http://www.nabble.com/servicemix-http-Post-support-tp16418421p16427193.html
>> >> >> Sent from the ServiceMix - User mailing list archive at Nabble.com.
>> >> >>
>> >> >>
>> >> >
>> >> >
>> >> > --
>> >> > Cheers,
>> >> > Guillaume Nodet
>> >> > ------------------------
>> >> > Blog: http://gnodet.blogspot.com/
>> >> >
>> >> >
>> >>
>> >> --
>> >> View this message in context:
>> >>
>> http://www.nabble.com/servicemix-http-Post-support-tp16418421p16446910.html
>> >> Sent from the ServiceMix - User mailing list archive at Nabble.com.
>> >>
>> >>
>> >
>> >
>> > --
>> > Cheers,
>> > Guillaume Nodet
>> > ------------------------
>> > Blog: http://gnodet.blogspot.com/
>> >
>> >
>>
>> --
>> View this message in context:
>> http://www.nabble.com/servicemix-http-Post-support-tp16418421p16452156.html
>> Sent from the ServiceMix - User mailing list archive at Nabble.com.
>>
>>
> 
> 
> -- 
> Cheers,
> Guillaume Nodet
> ------------------------
> Blog: http://gnodet.blogspot.com/
> 
> 

-- 
View this message in context: 
http://www.nabble.com/servicemix-http-Post-support-tp16418421p16467425.html
Sent from the ServiceMix - User mailing list archive at Nabble.com.

Reply via email to