You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by "Palmer, Eric" <ep...@richmond.edu> on 2015/11/05 17:51:42 UTC

file 2 transform 2 http4 (httpd status 400)

Hello camel fans,

Been using camel for about 6 months.

I¹m having a bit of a challenge getting the following route to work

File Polling ‹> transform ‹> http4 PUT

I can get this done in two routes

#1 File Polling ‹> transform ‹> File Save


#2 File Save ‹> http4 PUT

Background
- XML file (<10k)
- Transform is custom bean for xml content enhancement (adding a root
element attribute)
- target producer is eXist-db using PUT
- camel 2.15.2
- java 1.8.0_45

I¹ve been able to inspect the http response body and it is empty on the
failing route.  The http4 PUT is providing a status of 400

I¹m setting the body in the transform this way

String contentString = cxml.getXmlString();
int contentLength = contentString.length();
String contentLengthStr = Integer.toString(contentLength);
exchange.getOut().setHeaders(exchange.getIn().getHeaders());
exchange.getOut().setHeader(Exchange.CONTENT_LENGTH, contentLengthStr);
exchange.getOut().setBody(contentString);


I know this works for saving the enhanced content to a file producer but
am baffled why it won¹t work for going to the http4 producer.


The routes that work are here

<route>
  <from 
uri="file:/Users/epalmer/IdeaProjects/camelspring3/data/f2exist_withid/even
ts/in?readLock=changed&amp;renameUsingCopy=true&amp;delete=true&amp;recursi
ve=true&amp;delay=200"/>
  <log message="FILE_ID_TRANSFORM START file:${file:name}
len:${file:length}" loggingLevel="INFO" logName="transfer"/>
  <bean ref="idAssignTransform" method="process"/>
  <to 
uri="file:/Users/epalmer/IdeaProjects/camelspring3/data/f2exist_withid/even
ts/producer"/>
  <log message="F2E_ID_TRANSFORM FINISH file:${file:name}
len:${file:length}" loggingLevel="INFO" logName="transfer"/>
</route>

<route>
  <from 
uri="file:/Users/epalmer/IdeaProjects/camelspring3/data/f2exist_withid/even
ts/producer?readLock=changed&amp;renameUsingCopy=true&amp;delete=true&amp;r
ecursive=true&amp;delay=200"/>
  <log message="F2E_ID START file:${file:name} len:${file:length}"
loggingLevel="INFO" logName="transfer"/>
  <setHeader headerName="CamelHttpMethod">
    <constant>PUT</constant>
  </setHeader>
  <setHeader headerName="Exchange.CONTENT_TYPE">
    <constant>text/xml</constant>
  </setHeader>
  <setHeader headerName="Exchange.HTTP_PATH">
    <simple>events/${file:name}</simple>
  </setHeader>
  <setHeader headerName="Exchange.CONTENT_ENCODING">
    <simple>UTF-8</simple>
  </setHeader>
  <to 
uri="http4://localhost:8080/exist/rest/db/?authUsername=admin&amp;authPassw
ord=mypassword"/>
  <log message="F2E FINISH file:${file:name} len:${file:length}"
loggingLevel="INFO" logName="transfer"/>
</route>


The route that does not work is here

<route>
  <from 
uri="file:/Users/epalmer/IdeaProjects/camelspring3/data/f2exist_withid/even
ts/in?readLock=changed&amp;renameUsingCopy=true&amp;delete=true&amp;recursi
ve=true&amp;delay=200"/>
  <log message="F2E_ID START file:${file:name} len:${file:length}"
loggingLevel="INFO" logName="transfer"/>
  <bean ref="idAssignTransform" method="process"/>
  <setHeader headerName="CamelHttpMethod">
    <constant>PUT</constant>
  </setHeader>
  <setHeader headerName="Exchange.HTTP_PATH">
    <simple>events/${file:name}</simple>
  </setHeader>
  <setHeader headerName="Exchange.CONTENT_ENCODING">
    <simple>UTF-8</simple>
  </setHeader>
  <to 
uri="http4://localhost:8080/exist/rest/db/?authUsername=admin&amp;authPassw
ord=mypassword"/>
  <log message="F2E FINISH file:${file:name}" loggingLevel="INFO"
logName="transfer"/>
</route>


Suggesting much appreciated.



--
Eric Palmer
University of Richmond

Re: file 2 transform 2 http4 (httpd status 400)

Posted by DaddyOh <ep...@richmond.edu>.
I turned on the http wire logging and see 

HTTP/1.1 400 Parsing exception: fatal error at (7,617) : Invalid byte 1 of
1-byte UTF-8 sequence.

So I have an encoding problem that does not show up with the 
File > Transform > File > Exist-db approach

I'm staying with that approach because it will work in our environment.

Thanks
Eric



--
View this message in context: http://camel.465427.n5.nabble.com/file-2-transform-2-http4-httpd-status-400-tp5773400p5773444.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: file 2 transform 2 http4 (httpd status 400)

Posted by Claus Ibsen <cl...@gmail.com>.
Status code 400 means the http server rejected your requests because
something in it is bad / it cannot handle.

Also its better yo use getIn() and set the body / header you want. See this FAQ
http://camel.apache.org/using-getin-or-getout-methods-on-exchange.html

On Thu, Nov 5, 2015 at 5:51 PM, Palmer, Eric <ep...@richmond.edu> wrote:
> Hello camel fans,
>
> Been using camel for about 6 months.
>
> I¹m having a bit of a challenge getting the following route to work
>
> File Polling ‹> transform ‹> http4 PUT
>
> I can get this done in two routes
>
> #1 File Polling ‹> transform ‹> File Save
>
>
> #2 File Save ‹> http4 PUT
>
> Background
> - XML file (<10k)
> - Transform is custom bean for xml content enhancement (adding a root
> element attribute)
> - target producer is eXist-db using PUT
> - camel 2.15.2
> - java 1.8.0_45
>
> I¹ve been able to inspect the http response body and it is empty on the
> failing route.  The http4 PUT is providing a status of 400
>
> I¹m setting the body in the transform this way
>
> String contentString = cxml.getXmlString();
> int contentLength = contentString.length();
> String contentLengthStr = Integer.toString(contentLength);
> exchange.getOut().setHeaders(exchange.getIn().getHeaders());
> exchange.getOut().setHeader(Exchange.CONTENT_LENGTH, contentLengthStr);
> exchange.getOut().setBody(contentString);
>
>
> I know this works for saving the enhanced content to a file producer but
> am baffled why it won¹t work for going to the http4 producer.
>
>
> The routes that work are here
>
> <route>
>   <from
> uri="file:/Users/epalmer/IdeaProjects/camelspring3/data/f2exist_withid/even
> ts/in?readLock=changed&amp;renameUsingCopy=true&amp;delete=true&amp;recursi
> ve=true&amp;delay=200"/>
>   <log message="FILE_ID_TRANSFORM START file:${file:name}
> len:${file:length}" loggingLevel="INFO" logName="transfer"/>
>   <bean ref="idAssignTransform" method="process"/>
>   <to
> uri="file:/Users/epalmer/IdeaProjects/camelspring3/data/f2exist_withid/even
> ts/producer"/>
>   <log message="F2E_ID_TRANSFORM FINISH file:${file:name}
> len:${file:length}" loggingLevel="INFO" logName="transfer"/>
> </route>
>
> <route>
>   <from
> uri="file:/Users/epalmer/IdeaProjects/camelspring3/data/f2exist_withid/even
> ts/producer?readLock=changed&amp;renameUsingCopy=true&amp;delete=true&amp;r
> ecursive=true&amp;delay=200"/>
>   <log message="F2E_ID START file:${file:name} len:${file:length}"
> loggingLevel="INFO" logName="transfer"/>
>   <setHeader headerName="CamelHttpMethod">
>     <constant>PUT</constant>
>   </setHeader>
>   <setHeader headerName="Exchange.CONTENT_TYPE">
>     <constant>text/xml</constant>
>   </setHeader>
>   <setHeader headerName="Exchange.HTTP_PATH">
>     <simple>events/${file:name}</simple>
>   </setHeader>
>   <setHeader headerName="Exchange.CONTENT_ENCODING">
>     <simple>UTF-8</simple>
>   </setHeader>
>   <to
> uri="http4://localhost:8080/exist/rest/db/?authUsername=admin&amp;authPassw
> ord=mypassword"/>
>   <log message="F2E FINISH file:${file:name} len:${file:length}"
> loggingLevel="INFO" logName="transfer"/>
> </route>
>
>
> The route that does not work is here
>
> <route>
>   <from
> uri="file:/Users/epalmer/IdeaProjects/camelspring3/data/f2exist_withid/even
> ts/in?readLock=changed&amp;renameUsingCopy=true&amp;delete=true&amp;recursi
> ve=true&amp;delay=200"/>
>   <log message="F2E_ID START file:${file:name} len:${file:length}"
> loggingLevel="INFO" logName="transfer"/>
>   <bean ref="idAssignTransform" method="process"/>
>   <setHeader headerName="CamelHttpMethod">
>     <constant>PUT</constant>
>   </setHeader>
>   <setHeader headerName="Exchange.HTTP_PATH">
>     <simple>events/${file:name}</simple>
>   </setHeader>
>   <setHeader headerName="Exchange.CONTENT_ENCODING">
>     <simple>UTF-8</simple>
>   </setHeader>
>   <to
> uri="http4://localhost:8080/exist/rest/db/?authUsername=admin&amp;authPassw
> ord=mypassword"/>
>   <log message="F2E FINISH file:${file:name}" loggingLevel="INFO"
> logName="transfer"/>
> </route>
>
>
> Suggesting much appreciated.
>
>
>
> --
> Eric Palmer
> University of Richmond



-- 
Claus Ibsen
-----------------
http://davsclaus.com @davsclaus
Camel in Action 2: https://www.manning.com/ibsen2