You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Manoranjitham G <ma...@polarisft.com> on 2013/11/13 15:44:54 UTC

Keyvaluepair to xml using Bindy&xstream

Hi,

I am consuming keyvaluepair(FIX message) from a TCP client and converting it
to xml message. I have used bindy and xstream dataformats. First I am
unmarshalling  Bindy.Keyvalue (Input
message(empId=46135|firstName=mano|lastName=Ganesh") into javaobject and
then marshall that object into xml using xstream. But the xml is not formed
properly. help me to correct this.

*Employee.class*
@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
@Message(keyValuePairSeparator = "=", pairSeparator = "|", type="FIX",
version="4.1")

public class Employee
{
	@XmlAttribute
	@KeyValuePairField(tag=11,position=1,name="empId")
	private int empId;
	
	@XmlAttribute
	@KeyValuePairField(tag=22,position=2,name="firstName")
	private String firstName;
	
	@XmlAttribute
	@KeyValuePairField(tag=33,position=3,name="lastName")
	private String lastName;
	
	
	public int getEmpId() {
		return empId;
	}
	public void setEmpId(int empId) {
		this.empId = empId;
	}
	public String getFirstName() {
		return firstName;
	}
	public void setFirstName(String firstName) {
		this.firstName = firstName;
	}
	public String getLastName() {
		return lastName;
	}
	public void setLastName(String lastName) {
		this.lastName = lastName;
	}
	

	@Override
    public String toString() {
            return "Employee [empId=" + empId + ", firstName="
                            + firstName + ", lastName=" + lastName + "]";
    }
	}

*cameldemo.class*
public class Cameldemo{

	public static void main(String args[])
	{
			CamelContext context=new DefaultCamelContext();
			try
			{
				final DataFormat bindys = new
BindyKeyValuePairDataFormat("com.polaris.mh.camel.poc.sample.test");
				context.addRoutes(new RouteBuilder() {
					public void configure() {
						from("mina:tcp://localhost:6780?textline=true&sync=true").process(new
Processor()
						{
							public void process(Exchange req)
							{
								String inMessage=(String) req.getIn().getBody();
								
								log.info("Request Message-->"+req.getIn());
							}
					
}).unmarshal().bindy(BindyType.KeyValue,Employee.class).marshal().xstream().to("file://test");
					}

				});
			}
			catch(Exception exception)
			{
				exception.printStackTrace();
			}
			
			try
			{
				context.start();
				while(true)
				{
					
				}
			}
			catch(Exception exception1)
			{
				exception1.printStackTrace();
			}
		}
	}

*Myoutput:*
<?xml version="1.0" ?>
<main.java.com.polaris.mh.camel.poc.sample.test.Employee>
	<empId>-2147483648</empId>
</main.java.com.polaris.mh.camel.poc.sample.test.Employee>





--
View this message in context: http://camel.465427.n5.nabble.com/Keyvaluepair-to-xml-using-Bindy-xstream-tp5743187.html
Sent from the Camel - Users mailing list archive at Nabble.com.