Fuse camel use bindingStyle=SimpleConsumer rsserver options and body response is empty - json

I need receiver in message response json the new header field.After the send the new header and body to rest soapUI or client . For Manage response header and body i have modify my route whit the options bindingStyle = SimpleConsumer but now in the soapUI see only header but the body is empty . First this operation ( bindingStyle = Default ) i saw the body response but do not I saw the header .
(I'm using camel 2.12)
Who can help me ?
<route id="mainid">
<from uri="cxfrs:bean:rsServer?resourceClasses=xxxx&bindingStyle=SimpleConsumer"/>
<doTry>
<routingSlip uriDelimiter=",">
<simple>direct:${header.operationName}</simple>
</routingSlip>
<doCatch>
.....
</doCatch>
</doTry>
</route>
...
<route id="routeid">
<from uri="direct:postmethod" />
<removeHeaders pattern="Camel*" />
<to uri="jetty:{{baseUrl}}{{uri}}" />
</route>
...

Related

Azure APIM - XML to JSON Conversion

I am trying to figure out how to properly use the XML to JSON conversion in the Azure APIM Policy Editor. I've seen dozens of examples where all that's identified is this:
<xml-to-json kind="direct" apply="always" consider-accept-header="false" />
However, I cannot find the appropriate place within my policy to place the code to make it do what I'm expecting. Here is my Outbound policy, which is where I am looking to use this:
<outbound>
<base />
<choose>
<when condition="#(context.Response.StatusCode < 400)">
<set-body template="liquid">
{% if body.envelope.body.GetProjectsByQueryResponse.GetProjectsByQueryResult %}"{{body.envelope.body.GetProjectsByQueryResponse.GetProjectsByQueryResult | Replace: '\r', '\r' | Replace: '\n', '\n' | Replace: '([^\\](\\\\)*)"', '$1\"'}}"{% else %} null {% endif %}
</set-body>
</when>
<otherwise>
<set-variable name="old-body" value="#(context.Response.Body.As<string>(preserveContent: true))" />
<!-- Error response as per https://github.com/Microsoft/api-guidelines/blob/master/Guidelines.md#7102-error-condition-responses -->
<set-body template="liquid">{
"error": {
"code": "{{body.envelope.body.fault.faultcode}}",
"message": "{{body.envelope.body.fault.faultstring}}"
}
}
</set-body>
<choose>
<when condition="#(string.IsNullOrEmpty(context.Response.Body.As<JObject>(preserveContent: true)["error"]["code"].ToString()) && string.IsNullOrEmpty(context.Response.Body.As<JObject>(preserveContent: true)["error"]["message"].ToString()))">
<set-body>#{
var newResponseBody = new JObject();
newResponseBody["error"] = new JObject();
newResponseBody["error"]["code"] = "InvalidErrorResponseBody";
if (string.IsNullOrEmpty((string)context.Variables["old-body"]))
{
newResponseBody["error"]["message"] = "The error response body was not a valid SOAP error response. The response body was empty.";
}
else
{
newResponseBody["error"]["message"] = "The error response body was not a valid SOAP error response. The response body was: '" + context.Variables["old-body"] + "'.";
}
return newResponseBody.ToString();
}</set-body>
</when>
</choose>
</otherwise>
</choose>
<set-header name="Content-Type" exists-action="override">
<value>application/json</value>
</set-header>
<xml-to-json kind="direct" apply="always" consider-accept-header="false" />
</outbound>
As you can see I've tried placing the conversion line at the very end of the outbound policy, but it's not doing what I expect; I still have an xml document returned.
Any help here in understanding how to revise my policy to work would be wonderful.

How to use routes starting with same string

Is there any way how to create two different pages starting with same sring - GuidePage and GuideDetailPage using react router?
My code doesn't work, after open /guide it shows GuidePage components, it's ok. But after open /guide/detail it shows GuidePage NOT GuideDetailPage.
What is wrong?
<Router history={history}>
<main>
<MenuHeader />
<Switch>
<Route path='/guide'>
<Route path='/' component={GuidePage} />
<Route path='/detail' component={GuideDetailPage} />
</Route>
<Redirect to='/home' />
</Switch>
<Footer />
</main>
</Router>
So I can use /guide-detail for GuideDetailPage but I want to use guide/detail.
In React Router 4, routes are dynamic instead of static, you don't need to declare all routes in one file, but declare nested route in component having those routes.
Here is Basic Example, You need to add two routes inside Guide Component and to make it relative use match.path.
import React from "react";
import { BrowserRouter as Router, Route, Link, Switch } from "react-router-dom";
function BasicExample() {
return (
<Router>
<div>
<ul>
<li>
<Link to="/">Home</Link>
</li>
<li>
<Link to="/guide">Guide</Link>
</li>
</ul>
<hr />
<Switch>
<Route exact path="/" component={Home} />
<Route path="/guide" component={Guide} />
</Switch>
</div>
</Router>
);
}
function Guide({ match }) {
return (
<div>
<h2>Guide</h2>
<ul>
<li>
<Link to={`${match.url}`}>guide</Link>
</li>
<li>
<Link to={`${match.url}/detail`}>Guide Detail</Link>
</li>
</ul>
<Route path={`${match.path}/detail`}
component={GuidePage} />
<Route
exact
path={match.path}
render={() => <h3>Please select a topic.</h3>}
/>
</div>
);
}
function Home() {
return (
<div>
<h2>Home</h2>
</div>
);
}
function GuidePage() {
return (
<div>
<h2>GuidePage</h2>
</div>
);
}
export default BasicExample;
Hope that helps!!!

Spring integration tcp outbound and http inbound don t work properly

Hey I am sitting in front of Spring Integration for several days without speedy progress. Hope you can help me:
My trace:
Client.Input (POJO)
-> Client.[tcp-outbound].defaultserializer
-> Server.[tcp-inbound].defaultserializer
-> Server.[http-outbound] -> transform(POJO-to-Json)
-> Spring MVC Controller : return same POJO (automatic transform to json)
-> Server -> transform(Json-to-POJO)
-> Server -> defaultserializer
-> Client -> defaultserializer
Here the configuration:
Client-Side:
<int:channel id="input" />
<int-ip:tcp-connection-factory id="client"
type="client"
host="192.168.178.28"
port="5678"
serializer="javaSerializer"
deserializer="javaDeserializer"/>
<int-ip:tcp-outbound-gateway id="outboundGateway"
request-channel="input"
connection-factory="client"
request-timeout="10000"
reply-timeout="10000"/>
Server-Side:
<int-ip:tcp-connection-factory id="connectionFactory"
type="server"
port="6000"
serializer="javaSerializer"
deserializer="javaDeserializer"/>
<int-ip:tcp-inbound-gateway id="inboundGateway"
connection-factory="connectionFactory"
request-channel="requestChannel"
reply-channel="outboundChannel"/>
<int:channel id="requestChannel" />
<int:channel id="toMvcChannel" />
<int:channel id="toTcpChannel" />
<int:channel id="outboundChannel" />
<int:object-to-json-transformer input-channel="requestChannel"
output-channel="toMvcChannel"/>
<int:header-enricher input-channel="toMvcChannel">
<int:header name="Content-Type" value="application/json" />
</int:header-enricher>
<int-http:outbound-gateway
url="http://localhost:10100/arx/dataset/receiveGateway"
request-channel="toMvcChannel"
reply-channel="toTcpChannel"/>
<int:json-to-object-transformer input-channel="toTcpChannel"
output-channel="outboundChannel"/>
SimpleGateway:
public interface SimpleGateway {
public DefinitionServer send(DefinitionServer definition);}
I cannot understand why I get the error message below on Client side ON RECEIVE (last step in the routing):
No converter found capable of converting from type [java.lang.String] to type [...DefinitionServer]
Thanks in advance!

How to skip CSV header line with camel-beanio

How to skip CSV header line when using camel-beanio from apache?
My XML file for mapping look like this:
<beanio>
<record name="myRecord" class="my.package.MyConditionClass">
<field name="myField" position="1" />
<field name="mylist" position="2" collection="list" type ="string"/>
<segment name="conditions" class="my.package.MyConditionClass" nillable="true" collection="map" key="myKey">
<field name="myKey" position="2">
<field name="myValue" position="3">
</segment>
</record>
</beanio>
But to make my code run i must delete the first line (header line) manually. How do skip the header line automatically?
To read a CSV file and ignore the first header line, you can define the first field value of the header as comments of the CSV Stream
Example of CSV :
toto;tata;titi
product1;1;18
product2;2;36
product3;5;102
The mapping file :
<beanio ...
<stream name="dataStream" format="csv" >
<parser>
<property name="delimiter" value=";" />
<!-- ignore header line -->
<property name="comments" value="toto" />
</parser>
<record name="record" minOccurs="0" maxOccurs="unbounded" class="com.stackoverflow.Product" />
</stream>
</beanio>
Source : http://beanio.org/2.0/docs/reference/index.html#CSVStreamFormat
Another way will be to use camel-bindy in place of camel-beanio and the new option skipFirstLine (see https://camel.apache.org/components/latest/bindy-dataformat.html#_1_csvrecord)
Shortcut:
As soon as define BeanReader to read/process the records, use it's skip method with count 1 to skip the header.
e.g.
// Define Reader to process records
BeanReader beanReader = factory.createReader("STREAM",inputStreamReader);
// Skip First Record
beanReader.skip(1);
// Process rest of Stream
Object record;
do {
try {
record = beanReader.read();
}
catch (BeanReaderException e) {
e.printStackTrace();
}
} while(record !=null)
Refer http://beanio.org/2.0/docs/reference/index.html#TheMappingFile.
Skip method signature:
public int skip(int count) throws BeanReaderException;

Show request in Camel route

Is there any way to log request from body in camel route?
<camel:log message="RequestType [${request.body.request}]" loggingLevel="INFO" />
Error in logs:
Caused by: org.apache.camel.language.simple.types.SimpleParserException: Unknown function: request.body.request
This is working part, but dunno how to get into field :
<camel:log message="RequestType ${in.body}" loggingLevel="INFO" />
<camel:log message="RequestType2 [${body}]" loggingLevel="INFO" />
Request field for sure it's not empty becaue later I'm checking it:
<camel:ognl>request.body.request instanceof ...
Try with
<camel:log message="RequestType [${body.request}]" loggingLevel="INFO" />
The camel:log is using the simple language which you can read more about here: http://camel.apache.org/simple