apache camel csv or excel parser

default camel csv parsing method, wont keep the header row. http://camel.apache.org/csv.html

from("direct:start").
    marshal().csv().
    to("mock:result");

it would convert the collection into list of comma separated rows, however, the header of the row is not kept.

something like

630205,1111598,1,41848.040000
630210,1111603,1,8726.240000

to keep the header, one solution is to use the camel bindy.

		DataFormat bindy = new
				 BindyCsvDataFormat("com.blk.autoTest.bindy");
	 

	    .beanRef("COMDailyProdReportService","process")//use this service class to get the result set

	    //set the body as list of map ?
	    //the header would be lost after marshal
	    .marshal(bindy)
	    //.csv()
	    .beanRef("COMDailyProdReportService","check")

and the bindy class, specify: (generateHeaderColumns=true)

@CsvRecord(separator ="," , crlf = "UNIX", skipFirstLine = false, generateHeaderColumns=true)
public class COMProdOrders {
}

then results:

orderId,transactionId,direction,amount
630205,1111598,1,41848.040000
630210,1111603,1,8726.240000

Advertisements

camel timer

somehow, camel timer dosen’t work with Spring XML application context. If using camel.spring.Main, it works.

//		new ClassPathXmlApplicationContext(
//				"COMDailyProdReportContext.xml");
		
		
		org.apache.camel.spring.Main.main("-applicationContext", "COMDailyProdReportContext.xml");
from("timer://com/blk/autoTest/COMOrderReport?delay=100&repeatCount=1")

automation project for retrieving, parsing XML and output to file and Email


	    from("timer:swiftTest?repeatCount=1")//timer, auto start, only repeat once
			.beanRef("SWIFTTestService","process")//retrieve some messages #
			.split(body())//split 4 message # into 4 runs, no parrallel processing
				    .beanRef("SWIFTTestService","retrieveMsg") //retrieve the message through org.openqa.selenium.WebDriver
				    .to("xslt:swiftTransformer.xsl") //XSLT, transform the XML		    
				    .beanRef("SWIFTTestService","aggregateMsg") //aggregate the parsed XMLs, and put those into instance variable, for passing to Email
				    .to("file:output?fileName=SwiftMessages-${header.messageId}.xml")//write the parsed XML into output folder
				    .log("gcom swift msg result: "+body().toString())				    
		    .end()	    		
			    .beanRef("SWIFTTestService","emailMsg")//Email the aggregated parsed XML as attachments
	        	.log("gcom swift msg result: "+body().toString())

Retrieve the message through org.openqa.selenium.WebDriver

   @PostConstruct
   public void webDriverInit() {
	
	   
		driver.get("https://website"); //

		// Find the text input element by its name
		WebElement username = driver.findElement(By.name("xxxxxxx_username"));
		username.clear();
		username.sendKeys(user);
		

		WebElement password = driver.findElement(By.name("xxxxx_password"));
		password.clear();
		password.sendKeys(pwd);
		
		
		driver.findElement(By.name("Logon")).click();

	   
		parsedGXML = new ArrayList<String>();
		
		
   }

 public String retrieveMsg(Exchange exchange) throws InterruptedException{

	
	  	driver.get("https://xxxxxxxxxxxx"); 
  	
		
		//publisher:clear		
		WebElement publisher = driver.findElement(By.name("xxx"));
		//publisher.clear();
		publisher.sendKeys("xxxxx");



driver.findElement(By.xpath("//input[@type='submit' and @value='Search']")).click();


		(new WebDriverWait(driver, 60)).until(new ExpectedCondition<Boolean>() {
			public Boolean apply(WebDriver d) {
				return !driver.findElements(By.xpath("//a[text()='xxxxxxxx']")).isEmpty();
			}
		});


driver.findElement(By.xpath("//a[text()='xxxxxxx']")).click();


String swiftMsg = driver.findElement(By.xpath("//form[@id='message' and @method='post']/pre")).getText();
}

Email using javax.mail package.

		Multipart multipart = new MimeMultipart();
		multipart.addBodyPart(messageBodyPart);
		
		int i=0;
		for(String transformedSwiftMsg: transformedSwiftMsgs) {
			i++;
			BodyPart attachmentBodyPart = new MimeBodyPart();
			
		    DataSource ds = new ByteArrayDataSource(transformedSwiftMsg.getBytes("UTF-8"), "application/xml");
	
		    attachmentBodyPart.setDataHandler(new DataHandler(ds));
		    attachmentBodyPart.setFileName("SwiftMsg-"+i+".xml");
		    
			multipart.addBodyPart(attachmentBodyPart);
		}

		msg.setContent(multipart,"text/html");

camel timer

http://camel.apache.org/timer.html

in camel 2.8 onwards, there is one more attribute called, repeatCount, which controls how many times this timer can repeat.

from("timer:swiftTest?repeatCount=1")

pom.xml

		<properties>
		<camel-version>2.9.0</camel-version>
	</properties>

Sybase IDENTITY

http://infocenter.sybase.com/help/index.jsp?topic=/com.sybase.help.ase_15.0.sqlug/html/sqlug/sqlug299.htm

Instead of SEQUENCE like Oracle, Sybase has something equivalent, called IDENTIY.

By default, Adaptive Server begins numbering rows with the value 1, and continues numbering rows consecutively as they are added. Some activities, such as manual insertions, deletions, or transaction rollbacks, and server shutdowns or failures, can create gaps in IDENTITY column values. Adaptive Server provides several methods of controlling identity gaps described in “Managing identity gaps in tables”.

Pasted from

update GCOMElectronicOrder set TransactionID = 30000 where TransactionID = 21503

putty for server auto log in

PuTTYgen (puttygen.exe)
Then to automate SSH login, do the following:

Run PuTTYgen.
Select SSH-2 DSA as the Type of Key to generate.
Click generate and move your mouse around to generate randomness.
Click “Save Private Key” and save it somewhere on your computer.
Copy the entire content inside the box to your clipboard (this is your generated public key).
Login to your SSH server.
Create the file ~/.ssh/authorized_keys containing the generated public key (from step 3) on a single line.
Make this file readable (chmod 755).
Then open up PuTTY and navigate to Connection->Data and fill in the auto-login username.
Navigate to Connection->SSH->Auth and under Private-key, browse to the file you had saved earlier on your computer.

http://kb.norsetech.net/use-putty-to-automatically-login-a-ssh-session/