Skip to content

Instantly share code, notes, and snippets.

View fmbenhassine's full-sized avatar

Mahmoud Ben Hassine fmbenhassine

View GitHub Profile
package org.easybatch.jdbc;
import org.easybatch.core.api.Record;
import org.easybatch.core.api.RecordMapper;
import org.easybatch.core.api.RecordProcessor;
import org.easybatch.core.dispatcher.PoisonRecordBroadcaster;
import org.easybatch.core.dispatcher.RoundRobinRecordDispatcher;
import org.easybatch.core.filter.PoisonRecordFilter;
import org.easybatch.core.impl.Engine;
import org.easybatch.core.mapper.GenericRecordMapper;
@fmbenhassine
fmbenhassine / loop.sh
Created April 28, 2013 17:00
Read a file line by line using bash
#!/bin/bash
myFile=/data/in/input.csv
while read line
do
echo "$line"
done < $myFile
dir=`ls /data/in`
@fmbenhassine
fmbenhassine / DateFormatTests.java
Created January 11, 2018 21:03
Going back and forth between Date and String is not guaranteed to work..
package org.springframework.batch.item;
import org.junit.Test;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import static org.junit.Assert.assertEquals;
@fmbenhassine
fmbenhassine / RepeatTest.java
Created April 3, 2018 09:35
JUnit rule to repeat a test. Useful when testing multi-threaded behaviour which might succeed in one attempt but fail in another one.
public class RepeatTest implements TestRule {
private int count;
public RepeatTest(int count) {
if (count < 2 ) {
throw new IllegalArgumentException("Count must be >= 2");
}
this.count = count;
}
@fmbenhassine
fmbenhassine / RemoteChunkingJobFunctionalTests.java
Last active May 24, 2018 20:37
Spring Batch "remote" chunking sample with embedded JMS broker #SpringBatch
/*
* Copyright 2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
@fmbenhassine
fmbenhassine / ContextAwareWork.java
Last active May 24, 2018 20:39
Example of how to create an Easy Flows workflow with execution data passed between steps #EasyFlows
package org.jeasy.flows.work;
public abstract class ContextAwareWork implements Work {
private String name;
protected ExecutionContext executionContext;
public ContextAwareWork(String name, ExecutionContext executionContext) {
this.name = name;
this.executionContext = executionContext;
@fmbenhassine
fmbenhassine / GreetingTasklet.java
Last active May 24, 2018 20:41
Vanilla Spring Batch hello world job using an in-memory database, configured with XML and packaged in a standalone jar #SpringBatch
import org.springframework.batch.core.StepContribution;
import org.springframework.batch.core.scope.context.ChunkContext;
import org.springframework.batch.core.step.tasklet.Tasklet;
import org.springframework.batch.repeat.RepeatStatus;
public class GreetingTasklet implements Tasklet {
@Override
public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) {
Object name = chunkContext.getStepContext().getJobParameters().get("name");
@fmbenhassine
fmbenhassine / HelloWorldJobApplication.java
Last active May 24, 2018 20:41
Example of how to use a custom JobParametersConverter with Spring Batch #SpringBatch
package com.example.helloworldjob;
import org.springframework.batch.core.Job;
import org.springframework.batch.core.JobParameters;
import org.springframework.batch.core.JobParametersBuilder;
import org.springframework.batch.core.Step;
import org.springframework.batch.core.configuration.annotation.EnableBatchProcessing;
import org.springframework.batch.core.configuration.annotation.JobBuilderFactory;
import org.springframework.batch.core.configuration.annotation.StepBuilderFactory;
import org.springframework.batch.core.converter.JobParametersConverter;
@fmbenhassine
fmbenhassine / Main.java
Last active May 24, 2018 20:51
Java Crypto hello world #lab
package io.github.benas.labs.javase.crypto;
import javax.crypto.*;
import javax.crypto.spec.PBEKeySpec;
import javax.crypto.spec.PBEParameterSpec;
import java.io.IOException;
import java.security.InvalidAlgorithmParameterException;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.security.spec.InvalidKeySpecException;
package io.github.benas.jeelabs.ws.dictionary;
import com.google.gson.Gson;
import com.thoughtworks.xstream.XStream;
import io.github.benas.jeelabs.ws.dictionary.model.Word;
import io.github.benas.jeelabs.ws.dictionary.persistence.InMemoryDictionary;
import javax.ws.rs.*;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;