I am facing issue with Pound symbol coming in my messages to camel route ,
The pound symbol when comes in json request on my camel rest endpoint , it gets converted to "?" the same gets shown on log too.
I have tried below ways to fix this by setting convertBodyTo tag charset to utf-8 but it didn't worked.
Camel version used is 2.10.
Locale is : en_US.
Here is the route :
<from uri="jetty:http://localhost:8080/testService"/>
<camel:convertBodyTo type="String" charset="utf-8" />
<camel:log message="Message Body: ${body}" />
<to uri="jetty:http://localhost:8080/testEndpoints"/>
You need to know the encoding the client uses when POSTing the JSON. The browser should send you the encoding information in the Content-Type header field.
If the Pound sign shows as a single question mark, that indicates that the stream has a single-byte encoding. If it is multi-byte and then read with a single byte encoding it would show up as two garbage characters, not one. If the Content-Type header does not specify the encoding, then try setting the western single byte encoding ISO-8859-1 instead of UTF-8 and see if that works. As your locale is en_US the default encoding is probably US-ASCII.
Related
I'm trying to set up an sld style in Geoserver which references a column in a PostGIS view "Route Type". I'd like to have spaces in my column names as my goal is to create user friendly views for all my spatial data. With the sld below I get an error. I've tried a substituting the space for as well as <![CDATA[Property Name]]>
None of these resolve the issue.
Is it possible to have spaces in propertyName?
<?xml version="1.0" encoding="UTF-8"?>
<StyledLayerDescriptor version="1.0.0" xmlns="http://www.opengis.net/sld" xmlns:ogc="http://www.opengis.net/ogc"
xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.opengis.net/sld http://schemas.opengis.net/sld/1.0.0/StyledLayerDescriptor.xsd">
<NamedLayer>
<Name>Truck Routes and Restrictions</Name>
<UserStyle>
<Title>Truck Routes and Restrictions</Title>
<FeatureTypeStyle>
<Rule>
<Name>Designated Municipal Truck Route</Name>
<ogc:Filter>
<ogc:PropertyIsLike wildCard="*" singleChar="." escape="!">
<ogc:PropertyName>Route Type</ogc:PropertyName>
<ogc:Literal>*Designated Municipal Truck Route*</ogc:Literal>
</ogc:PropertyIsLike>
</ogc:Filter>
<LineSymbolizer>
<Stroke>
<CssParameter name="stroke">#006600</CssParameter>
<CssParameter name="stroke-width">3</CssParameter>
</Stroke>
</LineSymbolizer>
</Rule>
</FeatureTypeStyle>
</UserStyle>
</NamedLayer>
</StyledLayerDescriptor>
As I read here PropertyName should be able to be retrieved by Web Feature Service. And next I read How to request WFS propertyName containing parentheses, where I read all this kind of elements must match XML element naming, which don't allows any spaces.
So you can't use space in PropertyName. You should use "my column names" in way that will be not able to see for yours users.
I am doing a simple file read using WSO2 ESB File connection 2. I try to read a .OUT file from the given directory. It reads the first file (alphabetical order?) well but I have no idea which file is read. Is there a (transport?) property that gets populated when a file is read?
Here is my code in a proxy service
<fileconnector.read>
<source>file:///D:/temp</source>
<filePattern>.*\.OUT</filePattern>
<contentType>text/plain</contentType>
</fileconnector.read>
<log level="full"/>
I get the following response
INFO - LogMediator To: /services/SampleProxy.SampleProxyHttpSoap12Endpoint, WSAction: urn:mediate, SOAPAction: urn:mediate, MessageID: urn:uuid:f5737693-6a51-4044-9134-95cd61eaeaa4, Direction: request, Envelope: <?xml version='1.0' encoding='utf-8'?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"><soapenv:Body><text xmlns="http://ws.apache.org/commons/ns/payload">abc,123
qwe,456
</text></soapenv:Body></soapenv:Envelope>
Give it a try like this. (Just a suggestion. I didn't try.)
<log level="custom">
<property name="FileName" expression="$trp:FILE_NAME" />
</log>
If you want to read a particular file, you can pass the full path as a value in source and you can skip the file pattern value.
<fileconnector.read>
<source>file:///D:/temp/abc.OUT</source>
<filePattern></filePattern>
<contentType>text/plain</contentType>
</fileconnector.read>
This is a valid requirement. We will consider this in our future release. Please use [1] to track the progress.
[1] https://wso2.org/jira/browse/ESBCONNECT-192
In a camel route need to read values from an incoming json data through rest client. Using JsonPath to parse and get the values from it.
The expression used to fetch the json data works for one value and not for the other.
The JSON data incoming form the rest client:
[{"var1": 10,"var2": 20}]
JSONPath expression used inside the camel route:
<setHeader headerName="data1">
<jsonpath suppressExceptions="true">$[0].var1</jsonpath>
</setHeader>
<log message="value1 : ${header.data1}" />
<setHeader headerName="data2">
<jsonpath suppressExceptions="true">$[0].var2</jsonpath>
</setHeader>
<log message="valu2 : ${header.data2}" />
Can see the value getting logged in the first logger, but the second logger is 'null' and camel throws an 'NullPointerException'.
Question:
Can some one guide me if this is the right json path expression to get the values. If not do guide me to a solution.
Have checked the expressions working and returning values using various online tools available for json path.
I'm using the netty component for socket communication between two systems, request and
response.
This is the route
<from uri="netty:tcp://localhost:61616?encoder=#encoder"/>
<to uri="netty:tcp://localhost:61618?decoder=#decoder"/>
<log message="Receive ${body}">
<to uri="file://data?fileName=data2&charset=utf-8"/>
Everything, works fine, the data I send is buffer type, as well as the response received. I can see this data as String using the log ${body}, but there's nothing in the file where is suppossed to store this data.
I'm guessing that camel uses a converter (from buffer to string) for logging the body as plain text, but why is not saving something in the file, using a default converter for this????
I appreciate any comments of how to resolve this. Thank you !!!
Since your paylaod is ByteBuffer you need to explicitly convert to either String or byte[]
<from uri="netty:tcp://localhost:61616?encoder=#encoder"/>
<to uri="netty:tcp://localhost:61618?decoder=#decoder"/>
<convertBodyTo type="byte[]"/>
<log message="Receive ${body}">
<to uri="file://data?fileName=data2&charset=utf-8"/>
You can even use type="java.lang.String"
Please refer to the link http://camel.apache.org/type-converter.html
Hope it helps...
I am trying to implement a memory efficient http reverse proxy that is only working on streams. The Jetty consumer places the input stream into the exchange and I can hook it up with a http producer to forward the request. No problem there.
However, all http producers that I am aware of (Jetty, http4, netty-http) read the response stream into heap memory and place its contents into the exchange in some form or another instead of a handle to the stream. And none of them seem to offer an option to make them do so.
I found this thread which describes the same problem and also suggests a solution. But looking at the code of the http4 HttpProducer in Camel 2.13.1, it does not look like the proposed change made it into the Camel code base after all.
Is there any way to achieve the stream-only approach with Camel? So, with a minimal memory footprint I could do something along the line of this:
<route id="reverse_proxy" streamCache="false">
<from ref="jetty.http.server"/>
<bean ref="streamHolder" method="enableCaching"/>
<bean ref="streamHolder" method="parsePayloadHeaderInfoAndDoStuff"/>
<bean ref="streamHolder" method="resetStream"/>
<to ref="http.client"/> <!-- Register completion synchronization hook to close stream. -->
<bean ref="streamHolder" method="enableCaching"/>
<bean ref="streamHolder" method="parsePayloadResponseHeaderAndDoStuff"/>
<bean ref="streamHolder" method="resetStream"/>
</route>
EDIT - Additional info on where exactly the input stream ends up in memory:
http4: Everything happens in org.apache.camel.component.http4.HttpProducer::process() -> populateResponse(..) -> extractResponseBody(..) -> doExtractResponseBodyAsStream(); and here the original stream is copied into an instance of CachedOutputStream.
Jetty: org.eclipse.jetty.client.AsyncHttpConnection::handle() -> org.eclipse.jetty.http.HttpParser::parseNext() will fill a byte array in org.eclipse.jetty.client.ContentExchange which is a CachedExchange which is a HttpExchange.
netty-http: Builds a pipeline that assembles the HttpResponse content as a composite ChannelBuffer. The wrapped channel buffers make up the complete response stream.
I have debugged all three clients and did not stumble across a branch not taken that would leave me with the original input stream as the exchange body.
This is reproducible with a route as simple as this:
<camelContext id="pep-poc">
<endpoint id="jetty.http.server" uri="jetty:http://{{http.host.server}}:{{http.port.server}}/my/frontend?disableStreamCache=true"/>
<endpoint id="http.client" uri="jetty:http://{{http.host.client}}:{{http.port.client}}/large_response.html?bridgeEndpoint=true&throwExceptionOnFailure=false&disableStreamCache=true"/>
<route id="reverse_proxy" startupOrder="10" streamCache="false">
<from ref="jetty.http.server"/>
<to ref="http.client"/>
</route>
</camelContext>
I have an Apache2 return a 750MB file as large_response.html.
EDIT 2
Indeed this is a problem with all available HTTP producers. See this thread on the Camel mailing list and the corresponding JIRA ticket.
They do not read the stream into memory unless you access the message body on demand, and tell Camel to read it into memory as a String type etc.
See this cookbook example how to do a stream based proxy
http://camel.apache.org/how-to-use-camel-as-a-http-proxy-between-a-client-and-server.html