Spring integration tcp outbound and http inbound don t work properly - json

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!

Related

Liberty Server :It is not valid to call the 'commit' method on a nontransacted session

I'm moving from WAS8 to Liberty. Following is my code:
connection = factory.createConnection();
session = connection.createSession(true, Session.AUTO_ACKNOWLEDGE);
When I run my application it gives error saying:
DetailedIllegalStateException: JMSCC0014: It is not valid to call the 'commit' method on a nontransacted session.
Server.xml
<variable name="wmqJmsClient.rar.location"
value="${server.config.dir}/wmq/wmq.jmsra.rar"/>
<jmsConnectionFactory jndiName="jms/xyz/QCF" >
<properties.wmqJms
transportType="CLIENT"
hostName="host3153.GOT.NET"
port="1414"
channel="CLIENTS.xyz"
queueManager="host141Q"/>
<connectionManager maxPoolSize="10"/>
</jmsConnectionFactory>
<jmsQueue id="jms/queue1" jndiName="jms/xyz/queue/response">
<properties.wmqJms
baseQueueName="host1533A.RESP"
baseQueueManagerName="host141Q" CCSID="1208" expiry="APP" failIfQuiesce="true" persistence="APP" priority="APP" putAsyncAllowed="ENABLED" readAheadAllowed="ENABLED" readAheadClosePolicy="ALL" receiveConversion="QMGR" targetClient="JMS" receiveCCSID="1208" />
</jmsQueue>
<jmsQueue id="jms/queue2" jndiName="jms/xyz/queue/transportAssignment/request">
<properties.wmqJms
baseQueueName="host1533A.RQST"
baseQueueManagerName="host141Q" CCSID="1208" expiry="APP" failIfQuiesce="true" persistence="APP" priority="APP" putAsyncAllowed="ENABLED" readAheadAllowed="ENABLED" readAheadClosePolicy="ALL" receiveConversion="QMGR" targetClient="JMS" receiveCCSID="1208" />
</jmsQueue>

BIML: automatic creation of OleDbDestinations for XMLSource in Dataflow

I'm having a XML file with 2 outputpaths and 2 tables in my staging DB. Tables and outputpaths do have same names.
Instead of writing 2 times OleDbDestination and changing Inputpath and ExternalTableOutput I would like to use some Bimlscript.
My current solution:
<Dataflow Name="DF_MyXml">
<Transformations>
<XmlSource Name="MyXml">
<FileInput ConnectionName="simple.xml" />
<XmlSchemaFileInput ConnectionName="simple.xsd" />
</XmlSource>
<OleDbDestination Name="Database" ConnectionName="Dest">
<InputPath OutputPathName = "MyXml.Database" />
<ExternalTableOutput Table="Database" />
</OleDbDestination>
<OleDbDestination Name="Project" ConnectionName="Dest">
<InputPath OutputPathName = "MyXml.Project" />
<ExternalTableOutput Table="Project" />
</OleDbDestination>
</Transformations>
</Dataflow>
What I would like to achive:
<Dataflow Name="DF_MyXML">
<Transformations>
<XmlSource Name="MyXml">
<FileInput ConnectionName="simple.xml" />
<XmlSchemaFileInput ConnectionName="simple.xsd" />
</XmlSource>
<#foreach (var OutP in ["myXML"].DataflowOutputs) { #>
<OleDbDestination Name="<#=OutP.Name#>" ConnectionName="Dest">
<InputPath OutputPathName = "MyXml.<#=OutP.Name#>" />
<ExternalTableOutput Table="<#=OutP.Name#>" />
</OleDbDestination>
<# } #>
</Transformations>
</Dataflow>
Sadly this isn't working. ;-)
In API-Documentation for AstXMLSourceNode I found the property "DataflowOutputs" which "Gets a collection of all dataflow output paths for this transformation" (sounds promising, uhh?) but I can't even figure out how to reference the XMLSource in Bimlscript in any way.
Starting from RootNode I was able to find my Dataflow-Task but then I got stuck and didn't manage to "find" my Transformations\XMLSource.
Any help would be much appreciated!!
BTW: if there is a solution to automatically create destination-tables based on a given XSD this would be greate too. :-)
You need to make sure your connections are declared in a separate file to be easily accessed in Biml script. You can mess with Console.WriteLine() to print out details about objects to the output window and get a glimpse of what is going on in the BimlScript.
In the second file, traditionally called Environmnet.biml,
you need (only with your xml file connection info, the data here is just a placeholder):
<Connections>
<FileConnection Name="XmlFile" FilePath="C:\test\XmlFile.xml" RelativePath="true" />
<FileConnection Name="XmlXsd" FilePath="C:\test\XmlXsd.Xsd" RelativePath="true" />
</Connections>
then you can do something to the effect of :
var fileConnection = RootNode.Connections["XmlFile"];
(sorry before I accidentally put DbConnections)
and play with it from there. I do not have any xml files at my disposal right now to play around with to help you get the exact information that you are looking for. I will update on Monday.

How to display JSON having HTML data?

I have HTML tags and entities in JSON, I don't know how to display it in my app. I tried removing new lines, I tried decoding html entities but nothing worked.
Below is an example of JSON I have:
{"Jobdesc":[{"jobid":"12281","job_title":"IOS Developer for Noida Location Job","job_desc":"<p><strong>Job Description</strong><br />
Dear Candidate&nbsp;<br />
I have an opening for IOS Developer for Noida Location for leading IT company. pli\ease find the JD below-<br />
JOB DESCRIPTION :-<br />
Industry :- IT&nbsp;<br />
Experience :- Min 1 Year<br />
Position :- IOS Developer<br />
Location :- Noida<br />
&nbsp;<br />
<strong>Job Responsibility :-&nbsp;</strong><br />
&nbsp;<br />
Design and build advanced applications for the iOS platform<br />
Collaborate with cross-functional teams to define, design, and ship new features</p>
<p>Working experience in iOS development<br />
Have published one or more iOS apps in the app store<br />
A deep familiarity with Objective-C and Cocoa Touch<br />
Experience working with iOS frameworks such as Core Data, Core Animation, Core Graphics and Core Text<br />
&nbsp;If you are interested in the above mentioned JD kindly share your resume with me and contact me on :-<br />
&nbsp;<br />
Thanks And Regards<br />
Pal Mittal<br />
Contact no :- 9200272001<br />
Email ID :- parul#india-shine.in<br />
&nbsp;<br />
&nbsp;<br />
Functional Area: Web / Mobile Technologies&nbsp;<br />
Industry: IT - Software&nbsp;<br />
Skills: IOS ipad&nbsp;<br />
Other Skills: IOS Developer Iphone Developer IOS Application Developer iphone Application Developer iphone<br />
&nbsp;<br />
Recruiter details&nbsp;<br />
Company Name: Employment Solution<br />
Email: pal#ishine.in<br />
Telephone: 9200272001</p>
","job_role":"IOS Developer","job_exp":"1-4 year","job_education":"MCA","job_location":"Delhi","job_address":"Delhi","j ob_company_name":"India Shine Employment Solution","job_company_url":"www.india- shine.in","job_company_email":"kumar178dilip#gmail.com","job_status":""}]}
Actually there are 2 approaches
Approach 1
Code
#interface NSAttributedString (HTML)
+ (instancetype)attributedStringWithHTMLString:(NSString *)htmlString;
#end
#implementation NSAttributedString (HTML)
+ (instancetype)attributedStringWithHTMLString:(NSString *)htmlString
{
NSDictionary *options = #{ NSDocumentTypeDocumentAttribute : NSHTMLTextDocumentType,
NSCharacterEncodingDocumentAttribute :#(NSUTF8StringEncoding) };
NSData *data = [htmlString dataUsingEncoding:NSUTF8StringEncoding];
return [[NSAttributedString alloc] initWithData:data options:options documentAttributes:nil error:nil];
}
#end
Usage
NSString *cleanString = [[NSAttributedString attributedStringWithHTMLString:question.title] string];
Approach 2
Check out NSString category for XMLEntities. There's methods to decode XML entities (including all HTML character references), encode XML entities, stripping tags and removing newlines and whitespace from a string:
- (NSString *)stringByStrippingTags;
- (NSString *)stringByDecodingXMLEntities; // Including all HTML character references
- (NSString *)stringByEncodingXMLEntities;
- (NSString *)stringWithNewLinesAsBRs;
- (NSString *)stringByRemovingNewLinesAndWhitespace;
You can use UIWebView and show it like this:
let htmlString = //HTML String
webView.delegate = self
webView.scalesPageToFit = true
webView.contentMode = .scaleAspectFit
webView.loadHTMLString(htmlString, baseURL: nil)

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