javaapache-camelrestletjbossfuseblueprint

Camel restlet terminate after POST rather than return body


I am using blueprint to develop a camel restlet project to deploy on Fuse. It is a very simple HTTP POST with simple text body. I set the exchange pattern to Inonly.

However, I was expecting the connection to be terminated after the actual post, but I am receiving a 200 OK with the body filled with whatever the final body is in the processing at end.

Is this how it is meant to work? Do I therefore need to manually clear the body?

Also, what happens if the processing is a long running process? I would want to terminate straight after the data have been posted, rather than wait until the complete processing inside the context.

My blueprint looks like this:

 <camelContext xmlns="http://camel.apache.org/schema/blueprint">
  <route id="timerToLog">
    <from uri="restlet:http://localhost:7070/arena?restletMethod=POST&amp;exchangePattern=inOnly"/>
    <process ref="marcformatreader"/>
    <log message="${body}" loggingLevel="INFO"/>
    <process ref="marcformatwriter"/>
    <log message="${body}" loggingLevel="INFO"/>
    <to pattern="InOnly" uri="file:C:/Camel/output?fileName=output.mrc"/>
  </route>
</camelContext>

Solution

  • One solution would be to use WireTap pattern and return response immediately like this (note! I didn't execute that code so mind the possible typos).

    <camelContext xmlns="http://camel.apache.org/schema/blueprint">
        <route id="timerToLog">
            <from uri="restlet:http://localhost:7070/arena?restletMethod=POST&amp;exchangePattern=inOnly"/>
            <wireTap uri="direct:tap" copy="true"></wireTap>
            <transform>
                <constant>OK</constant>
            </transform>
        </route>
    
        <route id="wireTapToLog">
            <from uri="direct:tap"/>
            <process ref="marcformatreader"/>
            <log message="${body}" loggingLevel="INFO"/>
            <process ref="marcformatwriter"/>
            <log message="${body}" loggingLevel="INFO"/>
            <to pattern="InOnly" uri="file:C:/Camel/output?fileName=output.mrc"/>
        </route>
    
    </camelContext>
    

    With WireTap Camel will continue processing the exchange in another thread so the POST method will return immediately just text "OK".