├── README.md ├── RestClient ├── .classpath ├── .project ├── .settings │ ├── org.eclipse.core.resources.prefs │ ├── org.eclipse.jdt.core.prefs │ └── org.eclipse.m2e.core.prefs ├── pom.xml └── src │ ├── main │ └── java │ │ └── com │ │ └── bahadirakin │ │ └── rest │ │ └── App.java │ └── test │ └── java │ └── com │ └── bahadirakin │ └── rest │ └── AppTest.java ├── XStreamAnnotation ├── .classpath ├── .gitignore ├── .project ├── .settings │ ├── org.eclipse.core.resources.prefs │ ├── org.eclipse.jdt.core.prefs │ └── org.eclipse.m2e.core.prefs ├── LICENSE ├── NOTICE ├── pom.xml └── src │ ├── main │ └── java │ │ └── com │ │ └── bahadirakin │ │ └── xstream │ │ ├── App.java │ │ ├── factory │ │ ├── AbstractXmlFactory.java │ │ ├── IXmlFactory.java │ │ └── UserXmlFactory.java │ │ └── model │ │ └── User.java │ └── test │ └── java │ └── com │ └── bahadirakin │ └── xstream │ └── AppTest.java ├── aws-dynamodb-tutorial ├── .gitignore ├── pom.xml └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── bahadirakin │ │ │ └── dynamodb │ │ │ ├── App.java │ │ │ ├── dao │ │ │ ├── UserRepository.java │ │ │ └── UserRepositoryImpl.java │ │ │ └── model │ │ │ └── User.java │ └── resources │ │ └── aws.properties │ └── test │ └── java │ └── com │ └── bahadirakin │ └── dynamodb │ ├── AppTest.java │ ├── dao │ └── UserRepositoryImplTest.java │ └── rules │ └── LocalDynamoDBCreationRule.java ├── camel-soap ├── pom.xml └── src │ └── main │ ├── gen │ └── com │ │ └── bahadirakin │ │ └── helloworld │ │ ├── HelloRequest.java │ │ ├── HelloWorldService.java │ │ ├── HelloWorldServiceService.java │ │ ├── ObjectFactory.java │ │ └── package-info.java │ ├── java │ └── com │ │ └── bahadirakin │ │ ├── camel │ │ └── HelloProcessor.java │ │ └── helloworld │ │ └── HelloWorldServiceImpl.java │ ├── resources │ ├── applicationContext.xml │ ├── camel-context.xml │ ├── jaxws-context.xml │ └── wsdl │ │ └── HelloWorldService.wsdl │ └── webapp │ ├── WEB-INF │ └── web.xml │ └── index.jsp ├── camel-xslt ├── pom.xml └── src │ └── main │ ├── java │ └── com │ │ └── bahadirakin │ │ └── helloworld │ │ └── v2 │ │ ├── HelloRequest.java │ │ ├── HelloResponse.java │ │ └── HelloWorldService.java │ ├── resources │ ├── applicationContext.xml │ ├── camel-context.xml │ ├── jaxws-context.xml │ ├── wsdl │ │ ├── HelloWorldService.v1.wsdl │ │ └── HelloWorldService.v2.wsdl │ └── xslt │ │ └── sayHello.v1.to.v2.xslt │ └── webapp │ ├── WEB-INF │ └── web.xml │ └── index.jsp ├── cxf-rest-client ├── .gitignore ├── pom.xml └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── bahadirakin │ │ │ └── rest │ │ │ ├── CxfRestClientApplication.java │ │ │ └── api │ │ │ ├── User.java │ │ │ └── UserService.java │ └── resources │ │ ├── application.properties │ │ └── cxf-client-context.xml │ └── test │ └── java │ └── com │ └── bahadirakin │ └── rest │ └── CxfRestClientApplicationTests.java ├── download-servlet ├── .classpath ├── .gitignore ├── .project ├── .settings │ ├── .jsdtscope │ ├── org.eclipse.jdt.core.prefs │ ├── org.eclipse.m2e.core.prefs │ ├── org.eclipse.wst.common.component │ ├── org.eclipse.wst.common.project.facet.core.xml │ ├── org.eclipse.wst.jsdt.ui.superType.container │ └── org.eclipse.wst.jsdt.ui.superType.name ├── pom.xml └── src │ └── main │ ├── java │ └── com │ │ └── bahadirakin │ │ └── web │ │ └── DownloadServlet.java │ └── webapp │ ├── WEB-INF │ └── web.xml │ └── index.jsp ├── java-optional-demo ├── .gitignore ├── pom.xml └── src │ ├── main │ └── java │ │ └── com │ │ └── bahadirakin │ │ ├── App.java │ │ ├── dao │ │ └── UserDao.java │ │ ├── model │ │ ├── Address.java │ │ ├── Country.java │ │ └── User.java │ │ └── service │ │ ├── UserNotFoundException.java │ │ ├── UserService.java │ │ └── impl │ │ ├── BadUserServiceImpl.java │ │ └── BetterUserServiceImpl.java │ └── test │ └── java │ └── com │ └── bahadirakin │ └── service │ ├── BadUserServiceImplTest.java │ └── BetterUserServiceImplTest.java ├── jce-encrypt ├── .gitignore ├── pom.xml └── src │ ├── main │ └── java │ │ └── com │ │ └── bahadirakin │ │ ├── cipher │ │ ├── CipherAlgorithm.java │ │ ├── CipherException.java │ │ ├── CipherMode.java │ │ ├── CipherPadding.java │ │ ├── ICipher.java │ │ ├── SymetricCipher.java │ │ └── SymetricCipherProvider.java │ │ ├── main │ │ └── Main.java │ │ └── utils │ │ ├── Base64.java │ │ ├── IvUtils.java │ │ └── KeyUtils.java │ └── test │ └── java │ └── com │ └── bahadirakin │ └── cipher │ └── AESTest.java ├── jdk8-async-mvc ├── .gitignore ├── Readme.md ├── pom.xml └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── bahadirakin │ │ │ ├── ClientConfiguration.java │ │ │ ├── Jdk8AsyncMvcApplication.java │ │ │ ├── controller │ │ │ └── IpController.java │ │ │ ├── model │ │ │ └── Ip.java │ │ │ └── service │ │ │ └── HttpBinService.java │ └── resources │ │ └── application.properties │ └── test │ └── java │ └── com │ └── bahadirakin │ ├── Jdk8AsyncMvcApplicationTests.java │ ├── controller │ ├── IpControllerTest.java │ └── MockMvcBuilder.java │ └── integ │ └── HelloWorldServiceIT.java ├── logback-db ├── .gitignore ├── pom.xml └── src │ └── main │ ├── java │ └── com │ │ └── bahadirakin │ │ └── App.java │ └── resources │ ├── create.sql │ └── logback.xml ├── ml-spark-service ├── .gitignore ├── pom.xml └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── bahadirakin │ │ │ └── ml │ │ │ ├── MlSparkMvcServiceApplication.java │ │ │ ├── QualitativeBankruptcyModelGenerator.java │ │ │ ├── SparkConfiguration.java │ │ │ ├── dto │ │ │ ├── CompanyInfo.java │ │ │ ├── CompanyPrediction.java │ │ │ └── RiskStatus.java │ │ │ ├── mvc │ │ │ └── QualitativeBankruptcyController.java │ │ │ └── service │ │ │ ├── QualitativeBankruptcyService.java │ │ │ └── QualitativeBankruptcyServiceImpl.java │ └── resources │ │ ├── Qualitative_Bankruptcy.data.txt │ │ └── application.properties │ └── test │ └── java │ └── com │ └── bahadirakin │ └── ml │ └── MlSparkMvcServiceApplicationTests.java ├── rest-tutorial ├── .classpath ├── .gitignore ├── .project ├── .settings │ ├── org.eclipse.core.resources.prefs │ ├── org.eclipse.jdt.core.prefs │ └── org.eclipse.m2e.core.prefs ├── pom.xml ├── rest-db │ ├── .classpath │ ├── .gitignore │ ├── .project │ ├── .settings │ │ ├── org.eclipse.core.resources.prefs │ │ ├── org.eclipse.jdt.core.prefs │ │ ├── org.eclipse.m2e.core.prefs │ │ ├── org.eclipse.wst.common.component │ │ ├── org.eclipse.wst.common.project.facet.core.xml │ │ └── org.hibernate.eclipse.console.prefs │ ├── pom.xml │ └── src │ │ ├── main │ │ ├── java │ │ │ └── com │ │ │ │ └── bahadirakin │ │ │ │ ├── dao │ │ │ │ ├── IBaseDAO.java │ │ │ │ ├── ICarDAO.java │ │ │ │ ├── IUserDAO.java │ │ │ │ └── impl │ │ │ │ │ ├── BaseHibernateDAO.java │ │ │ │ │ ├── CarDAO.java │ │ │ │ │ └── UserDAO.java │ │ │ │ ├── model │ │ │ │ ├── AbstractEntity.java │ │ │ │ ├── Car.java │ │ │ │ ├── IEntity.java │ │ │ │ └── User.java │ │ │ │ ├── rest │ │ │ │ └── App.java │ │ │ │ └── util │ │ │ │ └── HibernateUtil.java │ │ └── resources │ │ │ ├── hibernate.cfg.xml │ │ │ ├── hibernate.reveng.xml │ │ │ └── log4j.properties │ │ └── test │ │ └── java │ │ └── com │ │ └── bahadirakin │ │ └── rest │ │ └── AppTest.java └── rest-main │ ├── .classpath │ ├── .gitignore │ ├── .project │ ├── .settings │ ├── .jsdtscope │ ├── org.eclipse.core.resources.prefs │ ├── org.eclipse.jdt.core.prefs │ ├── org.eclipse.m2e.core.prefs │ ├── org.eclipse.wst.common.component │ ├── org.eclipse.wst.common.project.facet.core.xml │ ├── org.eclipse.wst.jsdt.ui.superType.container │ └── org.eclipse.wst.jsdt.ui.superType.name │ ├── pom.xml │ └── src │ └── main │ ├── java │ └── com │ │ └── bahadirakin │ │ └── services │ │ ├── HelloWorldService.java │ │ └── ParkingLotService.java │ ├── resources │ ├── hibernate.cfg.xml │ └── log4j.properties │ └── webapp │ ├── WEB-INF │ └── web.xml │ └── index.jsp ├── retrolambda-sample ├── .gitignore ├── pom.xml └── src │ └── main │ └── java │ └── com │ └── bahadirakin │ ├── App.java │ └── User.java ├── simple-smpp-routing ├── .gitignore ├── assembly.xml ├── pom.xml └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── bahadirakin │ │ │ ├── App.java │ │ │ └── entities │ │ │ └── ShortMessage.java │ └── resources │ │ ├── applicationContext.xml │ │ ├── bin │ │ ├── run.bat │ │ └── run.sh │ │ ├── camelContext.xml │ │ ├── conf │ │ ├── database.properties │ │ └── endpoint.properties │ │ ├── import.sql │ │ ├── logback.xml │ │ └── persistenceContext.xml │ └── test │ └── java │ └── com │ └── bahadirakin │ └── AppTest.java ├── spring-cxf ├── .gitignore ├── pom.xml └── src │ └── main │ ├── java │ └── com │ │ └── bahadirakin │ │ ├── model │ │ ├── HelloWorldMessage.java │ │ └── Person.java │ │ ├── producer │ │ ├── MessageProducer.java │ │ └── MessageProducerImpl.java │ │ └── service │ │ ├── HelloWorldService.java │ │ └── HelloWorldServiceImpl.java │ ├── resources │ └── applicationContext.xml │ └── webapp │ └── WEB-INF │ └── web.xml ├── spring-hazelcast ├── .gitignore ├── pom.xml └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── bahadirakin │ │ │ └── hazelcast │ │ │ ├── SpringHazelcastApplication.java │ │ │ ├── UserMapStore.java │ │ │ ├── dao │ │ │ └── UserRepository.java │ │ │ ├── domain │ │ │ └── User.java │ │ │ └── rest │ │ │ └── UserRestService.java │ └── resources │ │ ├── application.properties │ │ └── import.sql │ └── test │ └── java │ └── com │ └── bahadirakin │ └── hazelcast │ └── SpringHazelcastApplicationTests.java ├── spring-hibernate-5 ├── .gitignore ├── pom.xml └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── bahadirakin │ │ │ ├── SpringHibernate5Application.java │ │ │ └── entity │ │ │ └── User.java │ └── resources │ │ ├── application.properties │ │ └── hibernate-context.xml │ └── test │ └── java │ └── com │ └── bahadirakin │ └── SpringHibernate5ApplicationTests.java ├── spring-jpa ├── .gitignore ├── pom.xml └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── bahadirakin │ │ │ ├── App.java │ │ │ ├── dao │ │ │ ├── CarDao.java │ │ │ └── ICarDao.java │ │ │ ├── model │ │ │ └── Car.java │ │ │ └── service │ │ │ ├── CarService.java │ │ │ └── ICarService.java │ └── resources │ │ ├── applicationContext.xml │ │ ├── environment │ │ ├── persistance-dev.properties │ │ ├── persistance-prod.properties │ │ └── persistance-uat.properties │ │ └── persistenceContext.xml │ └── test │ └── java │ └── com │ └── bahadirakin │ └── AppTest.java ├── spring-prime ├── .gitignore ├── pom.xml └── src │ └── main │ ├── java │ └── com │ │ └── bahadirakin │ │ ├── model │ │ └── Car.java │ │ ├── service │ │ ├── ICarService.java │ │ └── RandomCarService.java │ │ └── webapp │ │ └── CarBean.java │ ├── resources │ └── applicationContext.xml │ └── webapp │ ├── WEB-INF │ ├── faces-config.xml │ └── web.xml │ └── index.xhtml ├── spring-quartz ├── .gitignore ├── pom.xml └── src │ └── main │ ├── java │ └── com │ │ └── bahadirakin │ │ ├── App.java │ │ ├── DatabaseJob.java │ │ ├── DatabaseMonitor.java │ │ └── SchedulerController.java │ └── resources │ ├── application-context.xml │ └── quartz-h2.sql ├── spring-rabbitmq ├── .gitignore ├── Vagrantfile ├── pom.xml ├── rabbitmq.config └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── bahadirakin │ │ │ └── amqp │ │ │ ├── SpringRabbitmqApplication.java │ │ │ ├── consumer │ │ │ └── HelloMessageConsumer.java │ │ │ └── message │ │ │ └── HelloMessage.java │ └── resources │ │ └── application.properties │ └── test │ └── java │ └── com │ └── bahadirakin │ └── amqp │ └── SpringRabbitmqApplicationTests.java ├── spring-redis ├── .gitignore ├── Vagrantfile ├── pom.xml └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── bahadirakin │ │ │ └── redis │ │ │ ├── SomeLongBusiness.java │ │ │ ├── SomeLongBusinessImpl.java │ │ │ └── SpringRedisApplication.java │ └── resources │ │ └── application.properties │ └── test │ └── java │ └── com │ └── bahadirakin │ └── redis │ └── SpringRedisApplicationTests.java ├── test-with-mockito ├── .gitignore ├── pom.xml └── src │ ├── main │ └── java │ │ └── com │ │ └── bahadirakin │ │ ├── controllers │ │ └── LoginController.java │ │ ├── entities │ │ └── User.java │ │ ├── exceptions │ │ └── UserNotFoundException.java │ │ └── services │ │ └── IUserService.java │ └── test │ └── java │ └── com │ └── bahadirakin │ └── controllers │ └── LoginControllerTest.java └── user-application ├── .gitignore ├── Procfile ├── pom.xml └── src ├── main ├── java │ └── com │ │ └── bahadirakin │ │ ├── dao │ │ └── UserRepository.java │ │ ├── model │ │ └── User.java │ │ ├── mvc │ │ └── UserController.java │ │ └── service │ │ ├── UserService.java │ │ └── UserServiceImpl.java ├── resources │ ├── applicationContext.xml │ ├── mongodb.properties │ └── springDataContext.xml └── webapp │ ├── WEB-INF │ └── web.xml │ └── index.jsp └── test ├── java └── com │ └── bahadirakin │ ├── dao │ └── UserRepositoryTest.java │ ├── mvc │ └── UserControllerTest.java │ └── service │ └── UserServiceTest.java └── resources └── springDataContext-test.xml /RestClient/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /RestClient/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | RestClient 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | org.eclipse.m2e.core.maven2Builder 15 | 16 | 17 | 18 | 19 | 20 | org.eclipse.jdt.core.javanature 21 | org.eclipse.m2e.core.maven2Nature 22 | 23 | 24 | -------------------------------------------------------------------------------- /RestClient/.settings/org.eclipse.core.resources.prefs: -------------------------------------------------------------------------------- 1 | #Mon Apr 23 16:06:32 EEST 2012 2 | eclipse.preferences.version=1 3 | encoding//src/main/java=UTF-8 4 | encoding//src/test/java=UTF-8 5 | encoding/=UTF-8 6 | -------------------------------------------------------------------------------- /RestClient/.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | #Mon Apr 23 16:06:32 EEST 2012 2 | eclipse.preferences.version=1 3 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5 4 | org.eclipse.jdt.core.compiler.compliance=1.5 5 | org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning 6 | org.eclipse.jdt.core.compiler.source=1.5 7 | -------------------------------------------------------------------------------- /RestClient/.settings/org.eclipse.m2e.core.prefs: -------------------------------------------------------------------------------- 1 | #Mon Apr 23 16:06:14 EEST 2012 2 | activeProfiles= 3 | eclipse.preferences.version=1 4 | resolveWorkspaceProjects=true 5 | version=1 6 | -------------------------------------------------------------------------------- /RestClient/pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | 5 | com.bahadirakin 6 | RestClient 7 | 1.0 8 | jar 9 | 10 | RestClient 11 | Client for Restful Web Service defined in http://wicket.bahadirakin.com/rest/test 12 | http://www.bahadirakin.com 13 | 14 | 15 | 16 | 1 17 | Bahadır AKIN 18 | info@bahadirakin.com 19 | 20 | Developer 21 | 22 | http://www.bahadirakin.com 23 | 24 | 25 | 26 | 27 | UTF-8 28 | 29 | 30 | 31 | 32 | junit 33 | junit 34 | 3.8.1 35 | test 36 | 37 | 38 | org.apache.httpcomponents 39 | httpclient 40 | 4.1.3 41 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /RestClient/src/main/java/com/bahadirakin/rest/App.java: -------------------------------------------------------------------------------- 1 | package com.bahadirakin.rest; 2 | 3 | import java.io.IOException; 4 | 5 | import org.apache.http.client.ClientProtocolException; 6 | import org.apache.http.client.HttpClient; 7 | import org.apache.http.client.ResponseHandler; 8 | import org.apache.http.client.methods.HttpGet; 9 | import org.apache.http.impl.client.BasicResponseHandler; 10 | import org.apache.http.impl.client.DefaultHttpClient; 11 | 12 | public class App { 13 | 14 | public static void main(String[] args) { 15 | App app = new App(); 16 | System.out.println("REST CLIENT APPLICATION STARTED"); 17 | System.out.println("HTTP GET REQUEST IS GOING TO SEND..."); 18 | String result = app 19 | .connectRestService("http://wicket.bahadirakin.com/rest/test"); 20 | System.out.println("RESULT: " + result); 21 | System.out.println("END OF LINE"); 22 | 23 | } 24 | 25 | public String connectRestService(String url) { 26 | String result = ""; 27 | HttpClient httpClient = new DefaultHttpClient(); 28 | HttpGet request = new HttpGet(url); 29 | ResponseHandler handler = new BasicResponseHandler(); 30 | try { 31 | result = httpClient.execute(request, handler); 32 | } catch (ClientProtocolException e) { 33 | System.err 34 | .println("An Exception occured while connection Rest web service... ClientProtocolException... M: " 35 | + e.getMessage() + " C:" + e.getCause()); 36 | } catch (IOException e) { 37 | System.err 38 | .println("An Exception occured while connection Rest web service... IOException... M: " 39 | + e.getMessage() + " C:" + e.getCause()); 40 | } finally { 41 | httpClient.getConnectionManager().shutdown(); 42 | } 43 | return result; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /RestClient/src/test/java/com/bahadirakin/rest/AppTest.java: -------------------------------------------------------------------------------- 1 | package com.bahadirakin.rest; 2 | 3 | import junit.framework.Test; 4 | import junit.framework.TestCase; 5 | import junit.framework.TestSuite; 6 | 7 | /** 8 | * Unit test for simple App. 9 | */ 10 | public class AppTest 11 | extends TestCase 12 | { 13 | /** 14 | * Create the test case 15 | * 16 | * @param testName name of the test case 17 | */ 18 | public AppTest( String testName ) 19 | { 20 | super( testName ); 21 | } 22 | 23 | /** 24 | * @return the suite of tests being tested 25 | */ 26 | public static Test suite() 27 | { 28 | return new TestSuite( AppTest.class ); 29 | } 30 | 31 | /** 32 | * Rigourous Test :-) 33 | */ 34 | public void testApp() 35 | { 36 | assertTrue( true ); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /XStreamAnnotation/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /XStreamAnnotation/.gitignore: -------------------------------------------------------------------------------- 1 | /user.xml 2 | -------------------------------------------------------------------------------- /XStreamAnnotation/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | XStreamAnnotation 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | org.eclipse.m2e.core.maven2Builder 15 | 16 | 17 | 18 | 19 | 20 | org.eclipse.jdt.core.javanature 21 | org.eclipse.m2e.core.maven2Nature 22 | 23 | 24 | -------------------------------------------------------------------------------- /XStreamAnnotation/.settings/org.eclipse.core.resources.prefs: -------------------------------------------------------------------------------- 1 | #Sun Apr 22 21:20:39 EEST 2012 2 | eclipse.preferences.version=1 3 | encoding//src/main/java=UTF-8 4 | encoding//src/test/java=UTF-8 5 | encoding/=UTF-8 6 | -------------------------------------------------------------------------------- /XStreamAnnotation/.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | #Sun Apr 22 21:20:40 EEST 2012 2 | eclipse.preferences.version=1 3 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5 4 | org.eclipse.jdt.core.compiler.compliance=1.5 5 | org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning 6 | org.eclipse.jdt.core.compiler.source=1.5 7 | -------------------------------------------------------------------------------- /XStreamAnnotation/.settings/org.eclipse.m2e.core.prefs: -------------------------------------------------------------------------------- 1 | #Sun Apr 22 21:20:15 EEST 2012 2 | activeProfiles= 3 | eclipse.preferences.version=1 4 | resolveWorkspaceProjects=true 5 | version=1 6 | -------------------------------------------------------------------------------- /XStreamAnnotation/NOTICE: -------------------------------------------------------------------------------- 1 | XStream Annotation Tutorial 2 | Copyright 2012 The Apache Software Foundation 3 | 4 | This product includes software developed at 5 | The Apache Software Foundation (http://www.apache.org/). -------------------------------------------------------------------------------- /XStreamAnnotation/pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | 5 | com.bahadirakin 6 | XStreamAnnotation 7 | 1.0 8 | jar 9 | 10 | XStreamAnnotation 11 | XStream Annotation Example 12 | 13 | 14 | 15 | 1 16 | Bahadır AKIN 17 | info@bahadirakin.com 18 | 19 | Developer 20 | 21 | http://www.bahadirakin.com 22 | 23 | 24 | 25 | 26 | UTF-8 27 | 28 | 29 | 30 | 31 | 32 | com.thoughtworks.xstream 33 | xstream 34 | 1.4.2 35 | 36 | 37 | 38 | junit 39 | junit 40 | 4.8.1 41 | test 42 | 43 | 44 | 45 | -------------------------------------------------------------------------------- /XStreamAnnotation/src/main/java/com/bahadirakin/xstream/App.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012 Bahadır AKIN 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.bahadirakin.xstream; 17 | 18 | import com.bahadirakin.xstream.factory.UserXmlFactory; 19 | import com.bahadirakin.xstream.model.User; 20 | 21 | public class App { 22 | 23 | public static void main(String[] args) { 24 | App app = new App(); 25 | System.out.println("XSTREAM TEST APP STARTED"); 26 | app.createUserXml(); 27 | System.out.println("*** USER XML FILE CREATED"); 28 | User user = app.readFromUserXml(); 29 | System.out.println("*** USER XML FILE READ: " + user.toString()); 30 | System.out.println("End Of Line"); 31 | } 32 | 33 | public void createUserXml() { 34 | User user = new User(1, "bhdrkn"); 35 | UserXmlFactory factory = new UserXmlFactory(); 36 | factory.toXmlFile(user, UserXmlFactory.USER_XML_FILE); 37 | } 38 | 39 | public User readFromUserXml() { 40 | return new UserXmlFactory().fromXmlFile(UserXmlFactory.USER_XML_FILE); 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /XStreamAnnotation/src/main/java/com/bahadirakin/xstream/factory/IXmlFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012 Bahadır AKIN 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.bahadirakin.xstream.factory; 17 | 18 | import java.io.Serializable; 19 | 20 | /** 21 | * Interface for all XML Factory instances 22 | * 23 | * @author Bahadır AKIN 24 | * 25 | * @param Model class for factoring 26 | */ 27 | public interface IXmlFactory extends Serializable{ 28 | 29 | void toXmlFile(T t, String filePath); 30 | 31 | T fromXmlFile(String filePath); 32 | 33 | T fromXmlString(String xmlString); 34 | 35 | String toXmlString(T t); 36 | } 37 | -------------------------------------------------------------------------------- /XStreamAnnotation/src/main/java/com/bahadirakin/xstream/factory/UserXmlFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012 Bahadır AKIN 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.bahadirakin.xstream.factory; 17 | 18 | import com.bahadirakin.xstream.model.User; 19 | 20 | public class UserXmlFactory extends AbstractXmlFactory { 21 | 22 | private static final long serialVersionUID = 1L; 23 | 24 | public static final String USER_XML_FILE = "user.xml"; 25 | 26 | public UserXmlFactory() { 27 | super(); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /XStreamAnnotation/src/main/java/com/bahadirakin/xstream/model/User.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012 Bahadır AKIN 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.bahadirakin.xstream.model; 17 | 18 | import com.thoughtworks.xstream.annotations.XStreamAlias; 19 | 20 | @XStreamAlias("user") 21 | public class User { 22 | 23 | @XStreamAlias("id") 24 | private int id; 25 | @XStreamAlias("userName") 26 | private String userName; 27 | 28 | public User() { 29 | id = -1; 30 | userName = ""; 31 | } 32 | 33 | public User(int id, String userName) { 34 | super(); 35 | this.id = id; 36 | this.userName = userName; 37 | } 38 | 39 | public int getId() { 40 | return id; 41 | } 42 | 43 | public void setId(int id) { 44 | this.id = id; 45 | } 46 | 47 | public String getUserName() { 48 | return userName; 49 | } 50 | 51 | public void setUserName(String userName) { 52 | this.userName = userName; 53 | } 54 | 55 | @Override 56 | public String toString() { 57 | return "UserName: " + userName + " with id: " + id; 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /XStreamAnnotation/src/test/java/com/bahadirakin/xstream/AppTest.java: -------------------------------------------------------------------------------- 1 | package com.bahadirakin.xstream; 2 | 3 | import junit.framework.Test; 4 | import junit.framework.TestCase; 5 | import junit.framework.TestSuite; 6 | 7 | /** 8 | * Unit test for simple App. 9 | */ 10 | public class AppTest 11 | extends TestCase 12 | { 13 | /** 14 | * Create the test case 15 | * 16 | * @param testName name of the test case 17 | */ 18 | public AppTest( String testName ) 19 | { 20 | super( testName ); 21 | } 22 | 23 | /** 24 | * @return the suite of tests being tested 25 | */ 26 | public static Test suite() 27 | { 28 | return new TestSuite( AppTest.class ); 29 | } 30 | 31 | /** 32 | * Rigourous Test :-) 33 | */ 34 | public void testApp() 35 | { 36 | assertTrue( true ); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /aws-dynamodb-tutorial/src/main/java/com/bahadirakin/dynamodb/dao/UserRepository.java: -------------------------------------------------------------------------------- 1 | package com.bahadirakin.dynamodb.dao; 2 | 3 | import com.bahadirakin.dynamodb.model.User; 4 | 5 | import java.util.List; 6 | 7 | public interface UserRepository { 8 | 9 | void put(User user); 10 | 11 | void delete(String username); 12 | 13 | User get(String username) throws Exception; 14 | 15 | List findAll(); 16 | 17 | List findByEmail(final String email); 18 | } 19 | -------------------------------------------------------------------------------- /aws-dynamodb-tutorial/src/main/java/com/bahadirakin/dynamodb/dao/UserRepositoryImpl.java: -------------------------------------------------------------------------------- 1 | package com.bahadirakin.dynamodb.dao; 2 | 3 | import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBMapper; 4 | import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBScanExpression; 5 | import com.amazonaws.services.dynamodbv2.model.AttributeValue; 6 | import com.amazonaws.services.dynamodbv2.model.ComparisonOperator; 7 | import com.amazonaws.services.dynamodbv2.model.Condition; 8 | import com.bahadirakin.dynamodb.model.User; 9 | 10 | import java.util.Collections; 11 | import java.util.List; 12 | import java.util.Optional; 13 | 14 | //CHECKSTYLE.OFF: AbbreviationAsWordInName 15 | public class UserRepositoryImpl implements UserRepository { 16 | 17 | private final DynamoDBMapper dynamoDBMapper; 18 | 19 | public UserRepositoryImpl(DynamoDBMapper dynamoDBMapper) { 20 | this.dynamoDBMapper = dynamoDBMapper; 21 | } 22 | 23 | @Override 24 | public void put(User user) { 25 | this.dynamoDBMapper.save(user); 26 | } 27 | 28 | @Override 29 | public void delete(String username) { 30 | final User user = new User(); 31 | user.setUsername(username); 32 | this.dynamoDBMapper.delete(user); 33 | } 34 | 35 | @Override 36 | public User get(String username) throws Exception { 37 | return Optional.ofNullable(dynamoDBMapper.load(User.class, username)) 38 | .orElseThrow(() -> new Exception(String.format("User for username %s was not found", username))); 39 | } 40 | 41 | @Override 42 | public List findAll() { 43 | return dynamoDBMapper.scan(User.class, new DynamoDBScanExpression()); 44 | } 45 | 46 | @Override 47 | public List findByEmail(String email) { 48 | final List users = dynamoDBMapper.scan(User.class, 49 | new DynamoDBScanExpression().withFilterConditionEntry("email", 50 | new Condition().withComparisonOperator(ComparisonOperator.EQ) 51 | .withAttributeValueList(Collections.singletonList(new AttributeValue(email))))); 52 | if (users == null) { 53 | return Collections.emptyList(); 54 | } else { 55 | return users; 56 | } 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /aws-dynamodb-tutorial/src/main/java/com/bahadirakin/dynamodb/model/User.java: -------------------------------------------------------------------------------- 1 | package com.bahadirakin.dynamodb.model; 2 | 3 | import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBAttribute; 4 | import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBHashKey; 5 | import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBTable; 6 | 7 | import java.util.Objects; 8 | 9 | @DynamoDBTable(tableName = "Users") 10 | public class User { 11 | 12 | @DynamoDBHashKey(attributeName = "username") 13 | private String username; 14 | 15 | @DynamoDBAttribute(attributeName = "password") 16 | private String password; 17 | 18 | @DynamoDBAttribute(attributeName = "email") 19 | private String email; 20 | 21 | public String getUsername() { 22 | return username; 23 | } 24 | 25 | public void setUsername(String username) { 26 | this.username = username; 27 | } 28 | 29 | public String getPassword() { 30 | return password; 31 | } 32 | 33 | public void setPassword(String password) { 34 | this.password = password; 35 | } 36 | 37 | public String getEmail() { 38 | return email; 39 | } 40 | 41 | public void setEmail(String email) { 42 | this.email = email; 43 | } 44 | 45 | @Override 46 | public boolean equals(Object object) { 47 | if (this == object) { 48 | return true; 49 | } 50 | 51 | if (object == null || getClass() != object.getClass()) { 52 | return false; 53 | } 54 | 55 | User that = (User) object; 56 | return Objects.equals(this.username, that.username) 57 | && Objects.equals(this.email, that.email) 58 | && Objects.equals(this.password, that.password); 59 | 60 | } 61 | 62 | @Override 63 | public int hashCode() { 64 | return Objects.hash(username, email, password); 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /aws-dynamodb-tutorial/src/main/resources/aws.properties: -------------------------------------------------------------------------------- 1 | accessKey= 2 | secretKey= 3 | -------------------------------------------------------------------------------- /aws-dynamodb-tutorial/src/test/java/com/bahadirakin/dynamodb/AppTest.java: -------------------------------------------------------------------------------- 1 | package com.bahadirakin.dynamodb; 2 | 3 | import org.junit.Assert; 4 | import org.junit.Test; 5 | 6 | public class AppTest { 7 | 8 | @Test 9 | public void testMain() throws Exception { 10 | 11 | final String[] noArg = new String[]{}; 12 | 13 | try { 14 | App.main(noArg); 15 | } catch (Exception e) { 16 | Assert.fail("Main method fails!"); 17 | } 18 | } 19 | } -------------------------------------------------------------------------------- /camel-soap/src/main/gen/com/bahadirakin/helloworld/HelloWorldService.java: -------------------------------------------------------------------------------- 1 | package com.bahadirakin.helloworld; 2 | 3 | import javax.jws.WebMethod; 4 | import javax.jws.WebParam; 5 | import javax.jws.WebResult; 6 | import javax.jws.WebService; 7 | import javax.jws.soap.SOAPBinding; 8 | import javax.xml.bind.annotation.XmlSeeAlso; 9 | 10 | /** 11 | * This class was generated by Apache CXF 2.7.7 12 | * 2013-10-26T21:47:31.455+03:00 13 | * Generated source version: 2.7.7 14 | * 15 | */ 16 | @WebService(targetNamespace = "http://helloworld.bahadirakin.com/", name = "HelloWorldService") 17 | @XmlSeeAlso({ObjectFactory.class}) 18 | @SOAPBinding(parameterStyle = SOAPBinding.ParameterStyle.BARE) 19 | public interface HelloWorldService { 20 | 21 | @WebResult(name = "sayHelloResponse", targetNamespace = "http://helloworld.bahadirakin.com/", partName = "sayHelloResponse") 22 | @WebMethod 23 | public java.lang.String sayHello( 24 | @WebParam(partName = "helloRequest", name = "helloRequest", targetNamespace = "http://helloworld.bahadirakin.com/") 25 | HelloRequest helloRequest 26 | ); 27 | } 28 | -------------------------------------------------------------------------------- /camel-soap/src/main/gen/com/bahadirakin/helloworld/package-info.java: -------------------------------------------------------------------------------- 1 | @javax.xml.bind.annotation.XmlSchema(namespace = "http://helloworld.bahadirakin.com/") 2 | package com.bahadirakin.helloworld; 3 | -------------------------------------------------------------------------------- /camel-soap/src/main/java/com/bahadirakin/camel/HelloProcessor.java: -------------------------------------------------------------------------------- 1 | package com.bahadirakin.camel; 2 | 3 | import org.apache.camel.Exchange; 4 | import org.apache.camel.Processor; 5 | import org.slf4j.Logger; 6 | import org.slf4j.LoggerFactory; 7 | 8 | import com.bahadirakin.helloworld.HelloRequest; 9 | 10 | public class HelloProcessor implements Processor { 11 | 12 | private static final Logger logger = LoggerFactory 13 | .getLogger(HelloProcessor.class); 14 | 15 | @Override 16 | public void process(Exchange exchange) throws Exception { 17 | final HelloRequest helloRequest = (HelloRequest) exchange.getIn() 18 | .getBody(); 19 | logger.info("process"); 20 | logger.info("FirstName: " + helloRequest.getFirstName()); 21 | logger.info("LastName: " + helloRequest.getLastName()); 22 | 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /camel-soap/src/main/java/com/bahadirakin/helloworld/HelloWorldServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.bahadirakin.helloworld; 2 | 3 | import javax.jws.WebMethod; 4 | import javax.jws.WebParam; 5 | import javax.jws.WebResult; 6 | import javax.jws.WebService; 7 | 8 | @WebService(endpointInterface = "com.bahadirakin.helloworld.HelloWorldService", name = "HelloWorldService", portName = "HelloWorldServicePort", serviceName = "HelloWorldServiceService", targetNamespace = "http://helloworld.bahadirakin.com/", wsdlLocation = "wsdl/HelloWorldService.wsdl") 9 | public class HelloWorldServiceImpl implements HelloWorldService { 10 | 11 | @Override 12 | @WebMethod 13 | @WebResult(name = "sayHelloResponse", targetNamespace = "http://helloworld.bahadirakin.com/", partName = "sayHelloResponse") 14 | public String sayHello( 15 | @WebParam(name = "helloRequest", targetNamespace = "http://helloworld.bahadirakin.com/", partName = "helloRequest") HelloRequest helloRequest) { 16 | return "Hello, " + helloRequest.getFirstName() + " " 17 | + helloRequest.getLastName(); 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /camel-soap/src/main/resources/applicationContext.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /camel-soap/src/main/resources/camel-context.xml: -------------------------------------------------------------------------------- 1 | 2 | 10 | 11 | 12 | 13 | 14 | 17 | 18 | 19 | 20 | 21 | 22 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | -------------------------------------------------------------------------------- /camel-soap/src/main/resources/jaxws-context.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 9 | 11 | 12 | -------------------------------------------------------------------------------- /camel-soap/src/main/webapp/WEB-INF/web.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | camel-soap 7 | 8 | index.jsp 9 | 10 | 11 | 12 | contextConfigLocation 13 | classpath*:applicationContext.xml 14 | 15 | 16 | 17 | org.springframework.web.context.ContextLoaderListener 18 | 19 | 20 | 21 | CXFServlet 22 | org.apache.cxf.transport.servlet.CXFServlet 23 | 1 24 | 25 | 26 | 27 | CXFServlet 28 | /* 29 | 30 | -------------------------------------------------------------------------------- /camel-soap/src/main/webapp/index.jsp: -------------------------------------------------------------------------------- 1 | 2 | 3 |

Hello World!

4 | 5 | 6 | -------------------------------------------------------------------------------- /camel-xslt/src/main/java/com/bahadirakin/helloworld/v2/HelloRequest.java: -------------------------------------------------------------------------------- 1 | package com.bahadirakin.helloworld.v2; 2 | 3 | import javax.xml.bind.annotation.XmlRootElement; 4 | 5 | @XmlRootElement 6 | public class HelloRequest { 7 | 8 | private String firstName; 9 | private String lastName; 10 | 11 | public String getFirstName() { 12 | return firstName; 13 | } 14 | 15 | public void setFirstName(String firstName) { 16 | this.firstName = firstName; 17 | } 18 | 19 | public String getLastName() { 20 | return lastName; 21 | } 22 | 23 | public void setLastName(String lastName) { 24 | this.lastName = lastName; 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /camel-xslt/src/main/java/com/bahadirakin/helloworld/v2/HelloResponse.java: -------------------------------------------------------------------------------- 1 | package com.bahadirakin.helloworld.v2; 2 | 3 | import javax.xml.bind.annotation.XmlRootElement; 4 | 5 | @XmlRootElement 6 | public class HelloResponse { 7 | 8 | private String message; 9 | 10 | public String getMessage() { 11 | return message; 12 | } 13 | 14 | public void setMessage(String message) { 15 | this.message = message; 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /camel-xslt/src/main/java/com/bahadirakin/helloworld/v2/HelloWorldService.java: -------------------------------------------------------------------------------- 1 | package com.bahadirakin.helloworld.v2; 2 | 3 | import javax.jws.WebMethod; 4 | import javax.jws.WebParam; 5 | import javax.jws.WebService; 6 | 7 | @WebService 8 | public class HelloWorldService { 9 | 10 | @WebMethod 11 | public String sayHello(@WebParam(name = "request") HelloRequest request) { 12 | return "Hello, " + request.getFirstName() + " " + request.getLastName(); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /camel-xslt/src/main/resources/applicationContext.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /camel-xslt/src/main/resources/camel-context.xml: -------------------------------------------------------------------------------- 1 | 2 | 10 | 11 | 12 | 16 | 17 | 18 | 19 | 20 | 21 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /camel-xslt/src/main/resources/jaxws-context.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 9 | 10 | 11 | 12 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /camel-xslt/src/main/resources/xslt/sayHello.v1.to.v2.xslt: -------------------------------------------------------------------------------- 1 | 5 | 6 | 7 | 9 | 10 | 11 | 13 | 15 | 16 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /camel-xslt/src/main/webapp/WEB-INF/web.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | camel-xslt 7 | 8 | index.jsp 9 | 10 | 11 | 12 | contextConfigLocation 13 | classpath*:applicationContext.xml 14 | 15 | 16 | 17 | org.springframework.web.context.ContextLoaderListener 18 | 19 | 20 | 21 | CXFServlet 22 | org.apache.cxf.transport.servlet.CXFServlet 23 | 1 24 | 25 | 26 | 27 | CXFServlet 28 | /* 29 | 30 | -------------------------------------------------------------------------------- /camel-xslt/src/main/webapp/index.jsp: -------------------------------------------------------------------------------- 1 | 2 | 3 |

Hello World!

4 | 5 | 6 | -------------------------------------------------------------------------------- /cxf-rest-client/src/main/java/com/bahadirakin/rest/CxfRestClientApplication.java: -------------------------------------------------------------------------------- 1 | package com.bahadirakin.rest; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.context.annotation.Bean; 6 | import org.springframework.context.annotation.Import; 7 | import org.springframework.context.annotation.ImportResource; 8 | 9 | @SpringBootApplication 10 | @ImportResource(value = {"classpath*:cxf-client-context.xml"}) 11 | public class CxfRestClientApplication { 12 | 13 | public static void main(String[] args) { 14 | SpringApplication.run(CxfRestClientApplication.class, args); 15 | } 16 | 17 | } 18 | -------------------------------------------------------------------------------- /cxf-rest-client/src/main/java/com/bahadirakin/rest/api/User.java: -------------------------------------------------------------------------------- 1 | package com.bahadirakin.rest.api; 2 | 3 | import javax.xml.bind.annotation.*; 4 | 5 | @XmlRootElement(name = "user") 6 | @XmlType(name = "user", propOrder = { 7 | "id", 8 | "username", 9 | "email", 10 | "password" 11 | }) 12 | @XmlAccessorType(XmlAccessType.FIELD) 13 | public class User { 14 | 15 | @XmlElement(name = "id", required = false, nillable = false) 16 | private String id; 17 | @XmlElement(name = "username", required = true, nillable = false) 18 | private String username; 19 | @XmlElement(name = "email", required = true, nillable = false) 20 | private String email; 21 | @XmlElement(name = "password", required = false, nillable = false) 22 | private String password; 23 | 24 | public String getId() { 25 | return id; 26 | } 27 | 28 | public void setId(String id) { 29 | this.id = id; 30 | } 31 | 32 | public String getUsername() { 33 | return username; 34 | } 35 | 36 | public void setUsername(String username) { 37 | this.username = username; 38 | } 39 | 40 | public String getEmail() { 41 | return email; 42 | } 43 | 44 | public void setEmail(String email) { 45 | this.email = email; 46 | } 47 | 48 | public String getPassword() { 49 | return password; 50 | } 51 | 52 | public void setPassword(String password) { 53 | this.password = password; 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /cxf-rest-client/src/main/java/com/bahadirakin/rest/api/UserService.java: -------------------------------------------------------------------------------- 1 | package com.bahadirakin.rest.api; 2 | 3 | import javax.ws.rs.*; 4 | import java.util.List; 5 | 6 | @Path("/users") 7 | public interface UserService { 8 | 9 | @GET 10 | List findAllUsers(); 11 | 12 | @GET 13 | @Path("/{id}") 14 | User findUser(@PathParam("id") String userId); 15 | 16 | @POST 17 | User createUser(User user); 18 | } 19 | -------------------------------------------------------------------------------- /cxf-rest-client/src/main/resources/application.properties: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bhdrkn/Java-Examples/3b3cc50211e3313a0dbbeb7d342220fbd0f7cf80/cxf-rest-client/src/main/resources/application.properties -------------------------------------------------------------------------------- /cxf-rest-client/src/main/resources/cxf-client-context.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | 9 | 10 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /cxf-rest-client/src/test/java/com/bahadirakin/rest/CxfRestClientApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.bahadirakin.rest; 2 | 3 | import com.bahadirakin.rest.api.User; 4 | import com.bahadirakin.rest.api.UserService; 5 | import org.junit.Assert; 6 | import org.junit.Test; 7 | import org.junit.runner.RunWith; 8 | import org.springframework.beans.factory.annotation.Autowired; 9 | import org.springframework.boot.test.SpringApplicationConfiguration; 10 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 11 | import org.springframework.test.context.web.WebAppConfiguration; 12 | 13 | import java.util.List; 14 | 15 | @RunWith(SpringJUnit4ClassRunner.class) 16 | @SpringApplicationConfiguration(classes = CxfRestClientApplication.class) 17 | @WebAppConfiguration 18 | public class CxfRestClientApplicationTests { 19 | 20 | @Autowired 21 | private UserService userService; 22 | 23 | @Test 24 | public void testGetUsers() { 25 | final List users = userService.findAllUsers(); 26 | Assert.assertNotNull(users); 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /download-servlet/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /download-servlet/.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | -------------------------------------------------------------------------------- /download-servlet/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | download-servlet 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.wst.jsdt.core.javascriptValidator 10 | 11 | 12 | 13 | 14 | org.eclipse.jdt.core.javabuilder 15 | 16 | 17 | 18 | 19 | org.eclipse.wst.common.project.facet.core.builder 20 | 21 | 22 | 23 | 24 | org.eclipse.m2e.core.maven2Builder 25 | 26 | 27 | 28 | 29 | org.eclipse.wst.validation.validationbuilder 30 | 31 | 32 | 33 | 34 | 35 | org.eclipse.jem.workbench.JavaEMFNature 36 | org.eclipse.wst.common.modulecore.ModuleCoreNature 37 | org.eclipse.jdt.core.javanature 38 | org.eclipse.m2e.core.maven2Nature 39 | org.eclipse.wst.common.project.facet.core.nature 40 | org.eclipse.wst.jsdt.core.jsNature 41 | 42 | 43 | -------------------------------------------------------------------------------- /download-servlet/.settings/.jsdtscope: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /download-servlet/.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled 3 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5 4 | org.eclipse.jdt.core.compiler.compliance=1.5 5 | org.eclipse.jdt.core.compiler.problem.assertIdentifier=error 6 | org.eclipse.jdt.core.compiler.problem.enumIdentifier=error 7 | org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning 8 | org.eclipse.jdt.core.compiler.source=1.5 9 | -------------------------------------------------------------------------------- /download-servlet/.settings/org.eclipse.m2e.core.prefs: -------------------------------------------------------------------------------- 1 | activeProfiles= 2 | eclipse.preferences.version=1 3 | resolveWorkspaceProjects=true 4 | version=1 5 | -------------------------------------------------------------------------------- /download-servlet/.settings/org.eclipse.wst.common.component: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /download-servlet/.settings/org.eclipse.wst.common.project.facet.core.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /download-servlet/.settings/org.eclipse.wst.jsdt.ui.superType.container: -------------------------------------------------------------------------------- 1 | org.eclipse.wst.jsdt.launching.baseBrowserLibrary -------------------------------------------------------------------------------- /download-servlet/.settings/org.eclipse.wst.jsdt.ui.superType.name: -------------------------------------------------------------------------------- 1 | Window -------------------------------------------------------------------------------- /download-servlet/pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | com.bahadirakin 5 | download-servlet 6 | 7 | war 8 | 0.0.1-SNAPSHOT 9 | 10 | Download Servlet 11 | http://maven.apache.org 12 | 13 | 14 | 15 | javax.servlet 16 | servlet-api 17 | 2.5 18 | provided 19 | 20 | 21 | 22 | 23 | download-servlet 24 | 25 | 26 | -------------------------------------------------------------------------------- /download-servlet/src/main/java/com/bahadirakin/web/DownloadServlet.java: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bhdrkn/Java-Examples/3b3cc50211e3313a0dbbeb7d342220fbd0f7cf80/download-servlet/src/main/java/com/bahadirakin/web/DownloadServlet.java -------------------------------------------------------------------------------- /download-servlet/src/main/webapp/WEB-INF/web.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | Download Servlet Application 7 | 8 | 9 | download 10 | com.bahadirakin.web.DownloadServlet 11 | 1 12 | 13 | 14 | download 15 | /download 16 | 17 | 18 | -------------------------------------------------------------------------------- /download-servlet/src/main/webapp/index.jsp: -------------------------------------------------------------------------------- 1 | 2 | 3 |

Hello World!

4 | Download 5 | 6 | 7 | -------------------------------------------------------------------------------- /java-optional-demo/pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | 5 | com.bahadirakin 6 | java-optional-example 7 | 1.0-SNAPSHOT 8 | jar 9 | 10 | java-optional-example 11 | http://maven.apache.org 12 | 13 | 14 | UTF-8 15 | 16 | 17 | 18 | 19 | 20 | org.apache.maven.plugins 21 | maven-compiler-plugin 22 | 23 | 1.8 24 | 1.8 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | junit 33 | junit 34 | 4.12 35 | test 36 | 37 | 38 | org.mockito 39 | mockito-core 40 | 1.10.19 41 | test 42 | 43 | 44 | 45 | -------------------------------------------------------------------------------- /java-optional-demo/src/main/java/com/bahadirakin/App.java: -------------------------------------------------------------------------------- 1 | package com.bahadirakin; 2 | 3 | /** 4 | * Hello world! 5 | * 6 | */ 7 | public class App 8 | { 9 | public static void main( String[] args ) 10 | { 11 | System.out.println( "Hello World!" ); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /java-optional-demo/src/main/java/com/bahadirakin/dao/UserDao.java: -------------------------------------------------------------------------------- 1 | package com.bahadirakin.dao; 2 | 3 | import com.bahadirakin.model.User; 4 | 5 | import java.util.Optional; 6 | 7 | public interface UserDao { 8 | 9 | Optional findUser(final String username); 10 | 11 | @Deprecated 12 | User getUser(final String username); 13 | } 14 | -------------------------------------------------------------------------------- /java-optional-demo/src/main/java/com/bahadirakin/model/Address.java: -------------------------------------------------------------------------------- 1 | package com.bahadirakin.model; 2 | 3 | public class Address { 4 | 5 | private String street; 6 | private String city; 7 | private Country country; 8 | 9 | public String getStreet() { 10 | return street; 11 | } 12 | 13 | public void setStreet(String street) { 14 | this.street = street; 15 | } 16 | 17 | public String getCity() { 18 | return city; 19 | } 20 | 21 | public void setCity(String city) { 22 | this.city = city; 23 | } 24 | 25 | public Country getCountry() { 26 | return country; 27 | } 28 | 29 | public void setCountry(Country country) { 30 | this.country = country; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /java-optional-demo/src/main/java/com/bahadirakin/model/Country.java: -------------------------------------------------------------------------------- 1 | package com.bahadirakin.model; 2 | 3 | public class Country { 4 | 5 | private String name; 6 | private String code; 7 | 8 | public String getName() { 9 | return name; 10 | } 11 | 12 | public void setName(String name) { 13 | this.name = name; 14 | } 15 | 16 | public String getCode() { 17 | return code; 18 | } 19 | 20 | public void setCode(String code) { 21 | this.code = code; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /java-optional-demo/src/main/java/com/bahadirakin/model/User.java: -------------------------------------------------------------------------------- 1 | package com.bahadirakin.model; 2 | 3 | public class User { 4 | 5 | private String username; 6 | private String password; 7 | private String email; 8 | private Address address; 9 | 10 | public String getUsername() { 11 | return username; 12 | } 13 | 14 | public void setUsername(String username) { 15 | this.username = username; 16 | } 17 | 18 | public String getPassword() { 19 | return password; 20 | } 21 | 22 | public void setPassword(String password) { 23 | this.password = password; 24 | } 25 | 26 | public String getEmail() { 27 | return email; 28 | } 29 | 30 | public void setEmail(String email) { 31 | this.email = email; 32 | } 33 | 34 | public Address getAddress() { 35 | return address; 36 | } 37 | 38 | public void setAddress(Address address) { 39 | this.address = address; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /java-optional-demo/src/main/java/com/bahadirakin/service/UserNotFoundException.java: -------------------------------------------------------------------------------- 1 | package com.bahadirakin.service; 2 | 3 | public class UserNotFoundException extends Exception { 4 | 5 | private final String username; 6 | 7 | public UserNotFoundException(final String username) { 8 | super(String.format("User for %s username was not found", username)); 9 | this.username = username; 10 | } 11 | 12 | public UserNotFoundException(String username, Throwable cause) { 13 | super(String.format("User for %s username was not found", username), cause); 14 | this.username = username; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /java-optional-demo/src/main/java/com/bahadirakin/service/UserService.java: -------------------------------------------------------------------------------- 1 | package com.bahadirakin.service; 2 | 3 | import com.bahadirakin.model.User; 4 | 5 | public interface UserService { 6 | 7 | String DEFAULT_COUNTRY_CODE = "TR"; 8 | 9 | User getUser(final String username) throws UserNotFoundException; 10 | 11 | String getUserCountryCode(final String username); 12 | } 13 | -------------------------------------------------------------------------------- /java-optional-demo/src/main/java/com/bahadirakin/service/impl/BadUserServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.bahadirakin.service.impl; 2 | 3 | import com.bahadirakin.dao.UserDao; 4 | import com.bahadirakin.model.User; 5 | import com.bahadirakin.service.UserNotFoundException; 6 | import com.bahadirakin.service.UserService; 7 | 8 | import static java.util.Objects.requireNonNull; 9 | 10 | public class BadUserServiceImpl implements UserService { 11 | 12 | private final UserDao userDao; 13 | 14 | public BadUserServiceImpl(UserDao userDao) { 15 | this.userDao = requireNonNull(userDao); 16 | } 17 | 18 | 19 | @Override 20 | public User getUser(String username) throws UserNotFoundException { 21 | 22 | final User user = userDao.getUser(username); 23 | 24 | if (user == null) { 25 | throw new UserNotFoundException(username); 26 | } 27 | 28 | return user; 29 | } 30 | 31 | @Override 32 | public String getUserCountryCode(String username) { 33 | 34 | final User user = userDao.getUser(username); 35 | 36 | // WTF?? 37 | if (user == null 38 | || user.getAddress() == null 39 | || user.getAddress().getCountry() == null 40 | || user.getAddress().getCountry().getCode() == null) { 41 | return DEFAULT_COUNTRY_CODE; 42 | } 43 | 44 | return user.getAddress().getCountry().getCode(); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /java-optional-demo/src/main/java/com/bahadirakin/service/impl/BetterUserServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.bahadirakin.service.impl; 2 | 3 | import com.bahadirakin.dao.UserDao; 4 | import com.bahadirakin.model.Address; 5 | import com.bahadirakin.model.Country; 6 | import com.bahadirakin.model.User; 7 | import com.bahadirakin.service.UserNotFoundException; 8 | import com.bahadirakin.service.UserService; 9 | 10 | import static java.util.Objects.requireNonNull; 11 | 12 | public class BetterUserServiceImpl implements UserService { 13 | 14 | private final UserDao userDao; 15 | 16 | public BetterUserServiceImpl(UserDao userDao) { 17 | this.userDao = requireNonNull(userDao); 18 | } 19 | 20 | 21 | @Override 22 | public User getUser(String username) throws UserNotFoundException { 23 | return userDao.findUser(username) 24 | .orElseThrow(() -> new UserNotFoundException(username)); 25 | } 26 | 27 | @Override 28 | public String getUserCountryCode(String username) { 29 | // Just like Groovy's "?." 30 | return userDao.findUser(username) 31 | .map(User::getAddress) 32 | .map(Address::getCountry) 33 | .map(Country::getCode) 34 | .orElse(DEFAULT_COUNTRY_CODE); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /java-optional-demo/src/test/java/com/bahadirakin/service/BadUserServiceImplTest.java: -------------------------------------------------------------------------------- 1 | package com.bahadirakin.service; 2 | 3 | import com.bahadirakin.dao.UserDao; 4 | import org.junit.Rule; 5 | import org.junit.Test; 6 | import org.junit.rules.ExpectedException; 7 | import org.junit.runner.RunWith; 8 | import org.mockito.InjectMocks; 9 | import org.mockito.Mock; 10 | import org.mockito.runners.MockitoJUnitRunner; 11 | 12 | import static org.hamcrest.CoreMatchers.is; 13 | import static org.junit.Assert.assertThat; 14 | import static org.mockito.Mockito.verify; 15 | import static org.mockito.Mockito.when; 16 | 17 | @RunWith(MockitoJUnitRunner.class) 18 | public class BadUserServiceImplTest { 19 | 20 | @Rule 21 | public ExpectedException expectedException = ExpectedException.none(); 22 | 23 | @Mock 24 | private UserDao userDao; 25 | 26 | @InjectMocks 27 | private BadUserServiceImpl userService; 28 | 29 | @Test 30 | public void testGetUser() throws Exception { 31 | // given 32 | final String testUsername = "bahadirakin"; 33 | when(userDao.getUser(testUsername)).thenReturn(null); 34 | 35 | // then - Exception excepted 36 | expectedException.expect(UserNotFoundException.class); 37 | expectedException.expectMessage("User for bahadirakin username was not found"); 38 | 39 | // when 40 | userService.getUser(testUsername); 41 | } 42 | 43 | @Test 44 | public void testGetUserCountryCode() throws Exception { 45 | // given 46 | final String testUsername = "bahadirakin"; 47 | when(userDao.getUser(testUsername)).thenReturn(null); 48 | 49 | // when 50 | final String userCountryCode = userService.getUserCountryCode(testUsername); 51 | 52 | // then 53 | verify(userDao).getUser(testUsername); 54 | assertThat(userCountryCode, is(UserService.DEFAULT_COUNTRY_CODE)); 55 | } 56 | } -------------------------------------------------------------------------------- /java-optional-demo/src/test/java/com/bahadirakin/service/BetterUserServiceImplTest.java: -------------------------------------------------------------------------------- 1 | package com.bahadirakin.service; 2 | 3 | import com.bahadirakin.dao.UserDao; 4 | import com.bahadirakin.service.impl.BetterUserServiceImpl; 5 | import org.junit.Rule; 6 | import org.junit.Test; 7 | import org.junit.rules.ExpectedException; 8 | import org.junit.runner.RunWith; 9 | import org.mockito.InjectMocks; 10 | import org.mockito.Mock; 11 | import org.mockito.runners.MockitoJUnitRunner; 12 | 13 | import java.util.Optional; 14 | 15 | import static org.hamcrest.CoreMatchers.is; 16 | import static org.junit.Assert.assertThat; 17 | import static org.mockito.Mockito.verify; 18 | import static org.mockito.Mockito.when; 19 | 20 | @RunWith(MockitoJUnitRunner.class) 21 | public class BetterUserServiceImplTest { 22 | 23 | @Rule 24 | public ExpectedException expectedException = ExpectedException.none(); 25 | 26 | @Mock 27 | private UserDao userDao; 28 | 29 | @InjectMocks 30 | private BetterUserServiceImpl userService; 31 | 32 | @Test 33 | public void testGetUser() throws Exception { 34 | // given 35 | final String testUsername = "bahadirakin"; 36 | when(userDao.findUser(testUsername)).thenReturn(Optional.empty()); 37 | 38 | // then - Exception excepted 39 | expectedException.expect(UserNotFoundException.class); 40 | expectedException.expectMessage("User for bahadirakin username was not found"); 41 | 42 | // when 43 | userService.getUser(testUsername); 44 | } 45 | 46 | @Test 47 | public void testGetUserCountryCode() throws Exception { 48 | // given 49 | final String testUsername = "bahadirakin"; 50 | when(userDao.findUser(testUsername)).thenReturn(Optional.empty()); 51 | 52 | // when 53 | final String userCountryCode = userService.getUserCountryCode(testUsername); 54 | 55 | // then 56 | verify(userDao).findUser(testUsername); 57 | assertThat(userCountryCode, is(UserService.DEFAULT_COUNTRY_CODE)); 58 | } 59 | } -------------------------------------------------------------------------------- /jce-encrypt/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | com.bahadirakin 8 | aes-test 9 | 1.0-SNAPSHOT 10 | 11 | 12 | 13 | 14 | junit 15 | junit 16 | 4.12 17 | 18 | 19 | -------------------------------------------------------------------------------- /jce-encrypt/src/main/java/com/bahadirakin/cipher/CipherAlgorithm.java: -------------------------------------------------------------------------------- 1 | package com.bahadirakin.cipher; 2 | 3 | /** 4 | * Created by bhdrkn on 21/12/14. 5 | *

6 | * For more information please check 7 | * http://docs.oracle.com/javase/7/docs/technotes/guides/security/StandardNames.html#Cipher 8 | */ 9 | public enum CipherAlgorithm { 10 | AES("AES"), 11 | DES("DES"); 12 | 13 | private final String algorithm; 14 | 15 | private CipherAlgorithm(String algorithm) { 16 | this.algorithm = algorithm; 17 | } 18 | 19 | public String getAlgorithm() { 20 | return algorithm; 21 | } 22 | } -------------------------------------------------------------------------------- /jce-encrypt/src/main/java/com/bahadirakin/cipher/CipherException.java: -------------------------------------------------------------------------------- 1 | package com.bahadirakin.cipher; 2 | 3 | /** 4 | * Created by bhdrkn on 21/12/14. 5 | */ 6 | public class CipherException extends Exception { 7 | public CipherException() { 8 | } 9 | 10 | public CipherException(String message) { 11 | super(message); 12 | } 13 | 14 | public CipherException(String message, Throwable cause) { 15 | super(message, cause); 16 | } 17 | 18 | public CipherException(Exception e) { 19 | super(e); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /jce-encrypt/src/main/java/com/bahadirakin/cipher/CipherMode.java: -------------------------------------------------------------------------------- 1 | package com.bahadirakin.cipher; 2 | 3 | /** 4 | * Created by bhdrkn on 21/12/14. 5 | *

6 | * For more information please check 7 | * http://docs.oracle.com/javase/7/docs/technotes/guides/security/StandardNames.html#Cipher 8 | */ 9 | public enum CipherMode { 10 | CBC("CBC"), 11 | CFB("CFB"), 12 | CTR("CTR"); 13 | 14 | private final String mode; 15 | 16 | private CipherMode(String mode) { 17 | this.mode = mode; 18 | } 19 | 20 | public String getMode() { 21 | return mode; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /jce-encrypt/src/main/java/com/bahadirakin/cipher/CipherPadding.java: -------------------------------------------------------------------------------- 1 | package com.bahadirakin.cipher; 2 | 3 | /** 4 | * Created by bhdrkn on 21/12/14. 5 | *

6 | * For more information please check 7 | * http://docs.oracle.com/javase/7/docs/technotes/guides/security/StandardNames.html#Cipher 8 | */ 9 | public enum CipherPadding { 10 | NoPadding("NoPadding"), 11 | ISO10126Padding("ISO10126Padding"), 12 | PKCS5Padding("PKCS5Padding"); 13 | 14 | private final String padding; 15 | 16 | private CipherPadding(String padding) { 17 | this.padding = padding; 18 | } 19 | 20 | public String getPadding() { 21 | return padding; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /jce-encrypt/src/main/java/com/bahadirakin/cipher/ICipher.java: -------------------------------------------------------------------------------- 1 | package com.bahadirakin.cipher; 2 | 3 | /** 4 | * Created by bhdrkn on 21/12/14. 5 | */ 6 | public interface ICipher { 7 | 8 | public byte[] encrypt(final byte[] input) throws CipherException; 9 | 10 | public byte[] decrypt(final byte[] input) throws CipherException; 11 | } 12 | -------------------------------------------------------------------------------- /jce-encrypt/src/main/java/com/bahadirakin/cipher/SymetricCipher.java: -------------------------------------------------------------------------------- 1 | package com.bahadirakin.cipher; 2 | 3 | import javax.crypto.Cipher; 4 | import javax.crypto.spec.IvParameterSpec; 5 | import java.security.Key; 6 | 7 | /** 8 | * Created by bhdrkn on 21/12/14. 9 | */ 10 | public class SymetricCipher implements ICipher { 11 | private final Cipher cipher; 12 | private final Key key; 13 | private final IvParameterSpec initializationVector; 14 | 15 | 16 | public SymetricCipher(Cipher cipher, Key key, IvParameterSpec initializationVector) { 17 | this.cipher = cipher; 18 | this.key = key; 19 | this.initializationVector = initializationVector; 20 | } 21 | 22 | public SymetricCipher(Cipher cipher, Key key) { 23 | this(cipher, key, null); 24 | } 25 | 26 | @Override 27 | public byte[] encrypt(byte[] input) throws CipherException { 28 | initCipher(Cipher.ENCRYPT_MODE); 29 | try { 30 | return this.cipher.doFinal(input); 31 | } catch (Exception e) { 32 | throw new CipherException(e); 33 | } 34 | } 35 | 36 | @Override 37 | public byte[] decrypt(byte[] input) throws CipherException { 38 | initCipher(Cipher.DECRYPT_MODE); 39 | try { 40 | return this.cipher.doFinal(input); 41 | } catch (Exception e) { 42 | throw new CipherException(e); 43 | } 44 | } 45 | 46 | private void initCipher(final int opcode) { 47 | try { 48 | if (initializationVector == null) { 49 | cipher.init(opcode, key); 50 | } else { 51 | cipher.init(opcode, key, initializationVector); 52 | } 53 | } catch (Exception e) { 54 | throw new RuntimeException("Cipher initialization exception", e); 55 | } 56 | 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /jce-encrypt/src/main/java/com/bahadirakin/utils/IvUtils.java: -------------------------------------------------------------------------------- 1 | package com.bahadirakin.utils; 2 | 3 | import javax.crypto.spec.IvParameterSpec; 4 | 5 | /** 6 | * Created by bhdrkn on 21/12/14. 7 | */ 8 | public final class IvUtils { 9 | 10 | public static final IvParameterSpec generateDefaultVector() { 11 | // build the initialization vector. All zeros will be used as default 12 | byte[] iv = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; 13 | return IvUtils.generateVector(iv); 14 | } 15 | 16 | public static final IvParameterSpec generateVector(final byte[] bytes) { 17 | return new IvParameterSpec(bytes); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /jdk8-async-mvc/Readme.md: -------------------------------------------------------------------------------- 1 | Async Spring MVC example. 2 | 3 | Includes: 4 | * Spring Boot 5 | * Spring MVC 6 | * Automated Integration Tests 7 | * Unit tests for Spring MVC -------------------------------------------------------------------------------- /jdk8-async-mvc/src/main/java/com/bahadirakin/ClientConfiguration.java: -------------------------------------------------------------------------------- 1 | package com.bahadirakin; 2 | 3 | import com.bahadirakin.service.HttpBinService; 4 | import com.fasterxml.jackson.databind.ObjectMapper; 5 | import okhttp3.ConnectionPool; 6 | import okhttp3.OkHttpClient; 7 | import org.springframework.beans.factory.annotation.Value; 8 | import org.springframework.context.annotation.Bean; 9 | import org.springframework.context.annotation.Configuration; 10 | import retrofit2.Retrofit; 11 | import retrofit2.adapter.java8.Java8CallAdapterFactory; 12 | import retrofit2.converter.jackson.JacksonConverterFactory; 13 | 14 | import java.util.concurrent.Executor; 15 | import java.util.concurrent.Executors; 16 | import java.util.concurrent.TimeUnit; 17 | 18 | /** 19 | * Contains rest client configurations. 20 | */ 21 | @Configuration 22 | public class ClientConfiguration { 23 | 24 | @Bean 25 | HttpBinService httpBinServiceClient(Retrofit retrofit) { 26 | return retrofit.create(HttpBinService.class); 27 | } 28 | 29 | @Bean 30 | Retrofit retrofit(OkHttpClient okHttpClient, 31 | ObjectMapper objectMapper, 32 | Executor clientCallbackExecutor, 33 | @Value("${client.hostaddress}") String hostaddress) { 34 | return new Retrofit.Builder() 35 | .client(okHttpClient) 36 | .addConverterFactory(JacksonConverterFactory.create(objectMapper)) 37 | .addCallAdapterFactory(Java8CallAdapterFactory.create()) 38 | .baseUrl(hostaddress) 39 | .callbackExecutor(clientCallbackExecutor) 40 | .build(); 41 | } 42 | 43 | @Bean 44 | OkHttpClient okHttpClient(@Value("${client.connection.pool.size}") int connectionPoolSize) { 45 | return new OkHttpClient.Builder() 46 | .connectionPool(new ConnectionPool(connectionPoolSize, 5, TimeUnit.MINUTES)) 47 | .build(); 48 | } 49 | 50 | @Bean 51 | Executor clientCallbackExecutor(@Value("${client.executor.pool.size}") int executorPoolSize) { 52 | return Executors.newFixedThreadPool(executorPoolSize); 53 | } 54 | 55 | } 56 | -------------------------------------------------------------------------------- /jdk8-async-mvc/src/main/java/com/bahadirakin/Jdk8AsyncMvcApplication.java: -------------------------------------------------------------------------------- 1 | package com.bahadirakin; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class Jdk8AsyncMvcApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(Jdk8AsyncMvcApplication.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /jdk8-async-mvc/src/main/java/com/bahadirakin/controller/IpController.java: -------------------------------------------------------------------------------- 1 | package com.bahadirakin.controller; 2 | 3 | import com.bahadirakin.model.Ip; 4 | import com.bahadirakin.service.HttpBinService; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.http.ResponseEntity; 7 | import org.springframework.stereotype.Controller; 8 | import org.springframework.web.bind.annotation.RequestMapping; 9 | import org.springframework.web.bind.annotation.RequestMethod; 10 | 11 | import java.util.concurrent.CompletableFuture; 12 | 13 | @Controller 14 | @RequestMapping(path = "/ip") 15 | public class IpController { 16 | 17 | @Autowired 18 | HttpBinService httpBinService; 19 | 20 | @RequestMapping(method = RequestMethod.GET) 21 | public CompletableFuture> ip() { 22 | return httpBinService.ip() 23 | .thenApply(ResponseEntity::ok); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /jdk8-async-mvc/src/main/java/com/bahadirakin/model/Ip.java: -------------------------------------------------------------------------------- 1 | package com.bahadirakin.model; 2 | 3 | import com.fasterxml.jackson.annotation.JsonCreator; 4 | import com.fasterxml.jackson.annotation.JsonProperty; 5 | import com.google.common.base.MoreObjects; 6 | 7 | import java.util.Objects; 8 | 9 | public class Ip { 10 | 11 | @JsonProperty("origin") 12 | private final String origin; 13 | 14 | @JsonCreator 15 | public Ip(@JsonProperty("origin") String origin) { 16 | this.origin = origin; 17 | } 18 | 19 | public String getOrigin() { 20 | return origin; 21 | } 22 | 23 | @Override 24 | public boolean equals(Object o) { 25 | if (this == o) return true; 26 | if (o == null || getClass() != o.getClass()) return false; 27 | Ip ip = (Ip) o; 28 | return Objects.equals(origin, ip.origin); 29 | } 30 | 31 | @Override 32 | public int hashCode() { 33 | return Objects.hashCode(origin); 34 | } 35 | 36 | @Override 37 | public String toString() { 38 | return MoreObjects.toStringHelper(this) 39 | .add("origin", origin) 40 | .toString(); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /jdk8-async-mvc/src/main/java/com/bahadirakin/service/HttpBinService.java: -------------------------------------------------------------------------------- 1 | package com.bahadirakin.service; 2 | 3 | import com.bahadirakin.model.Ip; 4 | import retrofit2.http.GET; 5 | 6 | import java.util.concurrent.CompletableFuture; 7 | 8 | /** 9 | * A proxy interface for HttpBinService client. 10 | */ 11 | public interface HttpBinService { 12 | 13 | /** 14 | * Reads Ip object from HttpBin service. 15 | * 16 | * @return Ip object that contains client Ip. 17 | */ 18 | @GET("/ip") 19 | CompletableFuture ip(); 20 | } 21 | -------------------------------------------------------------------------------- /jdk8-async-mvc/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | client.connection.pool.size=9 2 | client.executor.pool.size=9 3 | client.hostaddress=http://httpbin.org -------------------------------------------------------------------------------- /jdk8-async-mvc/src/test/java/com/bahadirakin/Jdk8AsyncMvcApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.bahadirakin; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | import org.springframework.test.context.junit4.SpringRunner; 7 | 8 | @RunWith(SpringRunner.class) 9 | @SpringBootTest 10 | public class Jdk8AsyncMvcApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /jdk8-async-mvc/src/test/java/com/bahadirakin/controller/IpControllerTest.java: -------------------------------------------------------------------------------- 1 | package com.bahadirakin.controller; 2 | 3 | import com.bahadirakin.model.Ip; 4 | import com.bahadirakin.service.HttpBinService; 5 | import org.junit.Before; 6 | import org.junit.Test; 7 | import org.junit.runner.RunWith; 8 | import org.mockito.InjectMocks; 9 | import org.mockito.Mock; 10 | import org.mockito.runners.MockitoJUnitRunner; 11 | import org.springframework.http.HttpStatus; 12 | import org.springframework.http.ResponseEntity; 13 | import org.springframework.test.web.servlet.MockMvc; 14 | 15 | import java.util.concurrent.CompletableFuture; 16 | 17 | import static org.hamcrest.MatcherAssert.assertThat; 18 | import static org.hamcrest.Matchers.is; 19 | import static org.mockito.BDDMockito.given; 20 | import static org.mockito.BDDMockito.then; 21 | import static org.mockito.Mockito.verifyZeroInteractions; 22 | 23 | @RunWith(MockitoJUnitRunner.class) 24 | public class IpControllerTest { 25 | 26 | MockMvc mockMvc; 27 | 28 | @Mock 29 | HttpBinService httpBinService; 30 | 31 | @InjectMocks 32 | IpController ipController; 33 | 34 | @Before 35 | public void setUp() throws Exception { 36 | mockMvc = new MockMvcBuilder().withService(ipController).build(); 37 | } 38 | 39 | @Test 40 | public void ip() throws Exception { 41 | // Given 42 | final Ip ip = new Ip("127.0.0.1"); 43 | given(httpBinService.ip()).willReturn(CompletableFuture.completedFuture(ip)); 44 | 45 | // When 46 | ResponseEntity responseEntity = ipController.ip().get(); 47 | 48 | // Then 49 | then(httpBinService).should().ip(); 50 | assertThat(responseEntity.getStatusCode(), is(HttpStatus.OK)); 51 | assertThat(responseEntity.getBody(), is(ip)); 52 | } 53 | 54 | } -------------------------------------------------------------------------------- /jdk8-async-mvc/src/test/java/com/bahadirakin/integ/HelloWorldServiceIT.java: -------------------------------------------------------------------------------- 1 | package com.bahadirakin.integ; 2 | 3 | import com.bahadirakin.model.Ip; 4 | import com.fasterxml.jackson.databind.ObjectMapper; 5 | import okhttp3.OkHttpClient; 6 | import org.junit.Test; 7 | import retrofit2.Retrofit; 8 | import retrofit2.adapter.java8.Java8CallAdapterFactory; 9 | import retrofit2.converter.jackson.JacksonConverterFactory; 10 | import retrofit2.http.GET; 11 | 12 | import java.io.BufferedReader; 13 | import java.io.InputStreamReader; 14 | import java.net.URL; 15 | import java.util.concurrent.CompletableFuture; 16 | 17 | import static org.hamcrest.MatcherAssert.assertThat; 18 | import static org.hamcrest.Matchers.is; 19 | 20 | public class HelloWorldServiceIT { 21 | 22 | Retrofit retrofit = new Retrofit.Builder() 23 | .baseUrl("http://localhost:" + System.getProperty("test.server.port", "8080") + "/") 24 | .client(new OkHttpClient.Builder().build()) 25 | .addConverterFactory(JacksonConverterFactory.create(new ObjectMapper())) 26 | .addCallAdapterFactory(Java8CallAdapterFactory.create()) 27 | .build(); 28 | 29 | HelloWorldService helloWorldService = retrofit.create(HelloWorldService.class); 30 | 31 | @Test 32 | public void testIp() throws Exception { 33 | // Given 34 | 35 | // When 36 | Ip ip = helloWorldService.ip().get(); 37 | 38 | // Then 39 | assertThat(ip, is(new Ip(getPublicIp()))); 40 | } 41 | 42 | 43 | interface HelloWorldService { 44 | 45 | @GET("/ip") 46 | CompletableFuture ip(); 47 | } 48 | 49 | public static String getPublicIp() throws Exception { 50 | URL ipRequest = new URL("http://checkip.amazonaws.com"); 51 | 52 | try (final BufferedReader in = new BufferedReader(new InputStreamReader(ipRequest.openStream()))) { 53 | return in.readLine(); 54 | } 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /logback-db/pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | 5 | com.bahadirakin 6 | logback-db 7 | 1.0-SNAPSHOT 8 | jar 9 | 10 | logback-db 11 | http://maven.apache.org 12 | 13 | 14 | UTF-8 15 | 16 | 17 | 18 | 19 | org.slf4j 20 | slf4j-api 21 | 1.7.7 22 | 23 | 24 | ch.qos.logback 25 | logback-classic 26 | 1.0.13 27 | 28 | 29 | org.postgresql 30 | postgresql 31 | 9.3-1101-jdbc4 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /logback-db/src/main/java/com/bahadirakin/App.java: -------------------------------------------------------------------------------- 1 | package com.bahadirakin; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | 6 | /** 7 | * Hello world! 8 | */ 9 | public class App { 10 | 11 | private static final Logger logger = LoggerFactory.getLogger(App.class); 12 | 13 | public static void main(String[] args) { 14 | logger.info("Hello World!"); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /logback-db/src/main/resources/create.sql: -------------------------------------------------------------------------------- 1 | -- Logback: the reliable, generic, fast and flexible logging framework. 2 | -- Copyright (C) 1999-2010, QOS.ch. All rights reserved. 3 | -- 4 | -- See http://logback.qos.ch/license.html for the applicable licensing 5 | -- conditions. 6 | 7 | -- This SQL script creates the required tables by ch.qos.logback.classic.db.DBAppender 8 | -- 9 | -- It is intended for PostgreSQL databases. 10 | 11 | DROP TABLE logging_event_property; 12 | DROP TABLE logging_event_exception; 13 | DROP TABLE logging_event; 14 | DROP SEQUENCE logging_event_id_seq; 15 | 16 | 17 | CREATE SEQUENCE logging_event_id_seq MINVALUE 1 START 1; 18 | 19 | 20 | CREATE TABLE logging_event 21 | ( 22 | timestmp BIGINT NOT NULL, 23 | formatted_message TEXT NOT NULL, 24 | logger_name VARCHAR(254) NOT NULL, 25 | level_string VARCHAR(254) NOT NULL, 26 | thread_name VARCHAR(254), 27 | reference_flag SMALLINT, 28 | arg0 VARCHAR(254), 29 | arg1 VARCHAR(254), 30 | arg2 VARCHAR(254), 31 | arg3 VARCHAR(254), 32 | caller_filename VARCHAR(254) NOT NULL, 33 | caller_class VARCHAR(254) NOT NULL, 34 | caller_method VARCHAR(254) NOT NULL, 35 | caller_line CHAR(4) NOT NULL, 36 | event_id BIGINT DEFAULT nextval('logging_event_id_seq') PRIMARY KEY 37 | ); 38 | 39 | CREATE TABLE logging_event_property 40 | ( 41 | event_id BIGINT NOT NULL, 42 | mapped_key VARCHAR(254) NOT NULL, 43 | mapped_value VARCHAR(1024), 44 | PRIMARY KEY(event_id, mapped_key), 45 | FOREIGN KEY (event_id) REFERENCES logging_event(event_id) 46 | ); 47 | 48 | CREATE TABLE logging_event_exception 49 | ( 50 | event_id BIGINT NOT NULL, 51 | i SMALLINT NOT NULL, 52 | trace_line VARCHAR(254) NOT NULL, 53 | PRIMARY KEY(event_id, i), 54 | FOREIGN KEY (event_id) REFERENCES logging_event(event_id) 55 | ); -------------------------------------------------------------------------------- /logback-db/src/main/resources/logback.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n 7 | 8 | 9 | 10 | 11 | 12 | org.postgresql.Driver 13 | jdbc:postgresql://localhost:5432/DB4Logback 14 | postgres 15 | 1q2w3e 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /ml-spark-service/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | com.bahadirakin 7 | ml-spark-mvc-service 8 | 0.0.1-SNAPSHOT 9 | jar 10 | 11 | ml-spark-mvc-service 12 | Demo project 13 | 14 | 15 | org.springframework.boot 16 | spring-boot-starter-parent 17 | 1.4.0.RELEASE 18 | 19 | 20 | 21 | 22 | UTF-8 23 | UTF-8 24 | 2.6.2 25 | 1.8 26 | 27 | 28 | 29 | 30 | org.springframework.boot 31 | spring-boot-starter-web 32 | 33 | 34 | 35 | org.springframework.boot 36 | spring-boot-starter-test 37 | test 38 | 39 | 40 | 41 | org.apache.spark 42 | spark-mllib_2.11 43 | 2.0.0 44 | 45 | 46 | 47 | 48 | 49 | 50 | org.springframework.boot 51 | spring-boot-maven-plugin 52 | 53 | 54 | 55 | 56 | 57 | 58 | -------------------------------------------------------------------------------- /ml-spark-service/src/main/java/com/bahadirakin/ml/MlSparkMvcServiceApplication.java: -------------------------------------------------------------------------------- 1 | package com.bahadirakin.ml; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class MlSparkMvcServiceApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(MlSparkMvcServiceApplication.class, args); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /ml-spark-service/src/main/java/com/bahadirakin/ml/SparkConfiguration.java: -------------------------------------------------------------------------------- 1 | package com.bahadirakin.ml; 2 | 3 | import org.apache.spark.SparkConf; 4 | import org.apache.spark.SparkContext; 5 | import org.apache.spark.api.java.JavaSparkContext; 6 | import org.apache.spark.mllib.classification.LogisticRegressionModel; 7 | import org.springframework.beans.factory.annotation.Value; 8 | import org.springframework.context.annotation.Bean; 9 | import org.springframework.context.annotation.Configuration; 10 | 11 | @Configuration 12 | public class SparkConfiguration { 13 | 14 | @Value("${spark.ml.model.path}") 15 | private String modelPath; 16 | 17 | @Bean(destroyMethod = "stop") 18 | public SparkContext sparkContext() { 19 | final SparkConf conf = new SparkConf() 20 | .setAppName("MLSparkService") 21 | .setMaster("local"); 22 | return new SparkContext(conf); 23 | } 24 | 25 | @Bean(destroyMethod = "stop") 26 | public JavaSparkContext javaSparkContext(SparkContext sparkContext) { 27 | return new JavaSparkContext(sparkContext); 28 | } 29 | 30 | @Bean 31 | public LogisticRegressionModel logisticRegressionModel(SparkContext sparkContext) { 32 | return LogisticRegressionModel.load(sparkContext, modelPath); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /ml-spark-service/src/main/java/com/bahadirakin/ml/dto/CompanyPrediction.java: -------------------------------------------------------------------------------- 1 | package com.bahadirakin.ml.dto; 2 | 3 | public enum CompanyPrediction { 4 | BANKRUPTCY, 5 | NON_BANKRUPTCY; 6 | } 7 | -------------------------------------------------------------------------------- /ml-spark-service/src/main/java/com/bahadirakin/ml/dto/RiskStatus.java: -------------------------------------------------------------------------------- 1 | package com.bahadirakin.ml.dto; 2 | 3 | public enum RiskStatus { 4 | POSITIVE, 5 | AVERAGE, 6 | NEGATIVE; 7 | } 8 | -------------------------------------------------------------------------------- /ml-spark-service/src/main/java/com/bahadirakin/ml/mvc/QualitativeBankruptcyController.java: -------------------------------------------------------------------------------- 1 | package com.bahadirakin.ml.mvc; 2 | 3 | 4 | import com.bahadirakin.ml.dto.CompanyInfo; 5 | import com.bahadirakin.ml.dto.CompanyPrediction; 6 | import com.bahadirakin.ml.service.QualitativeBankruptcyService; 7 | import org.slf4j.Logger; 8 | import org.slf4j.LoggerFactory; 9 | import org.springframework.beans.factory.annotation.Autowired; 10 | import org.springframework.http.HttpStatus; 11 | import org.springframework.http.MediaType; 12 | import org.springframework.http.ResponseEntity; 13 | import org.springframework.stereotype.Controller; 14 | import org.springframework.web.bind.annotation.RequestBody; 15 | import org.springframework.web.bind.annotation.RequestMapping; 16 | import org.springframework.web.bind.annotation.RequestMethod; 17 | 18 | @Controller 19 | @RequestMapping("/rest") 20 | public class QualitativeBankruptcyController { 21 | 22 | private static final Logger logger = LoggerFactory.getLogger(QualitativeBankruptcyController.class); 23 | 24 | @Autowired 25 | private QualitativeBankruptcyService qualitativeBankruptcyService; 26 | 27 | @RequestMapping(path = "/predict", method = RequestMethod.POST, 28 | consumes = {MediaType.APPLICATION_JSON_VALUE}, produces = {MediaType.APPLICATION_JSON_VALUE}) 29 | public ResponseEntity createUser(@RequestBody CompanyInfo companyInfo) { 30 | try { 31 | final CompanyPrediction prediction = qualitativeBankruptcyService.predict(companyInfo); 32 | return new ResponseEntity<>(prediction, HttpStatus.CREATED); 33 | } catch (Exception e) { 34 | logger.error("Cannot predict result for {}", companyInfo, e); 35 | return new ResponseEntity<>(HttpStatus.BAD_REQUEST); 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /ml-spark-service/src/main/java/com/bahadirakin/ml/service/QualitativeBankruptcyService.java: -------------------------------------------------------------------------------- 1 | package com.bahadirakin.ml.service; 2 | 3 | import com.bahadirakin.ml.dto.CompanyInfo; 4 | import com.bahadirakin.ml.dto.CompanyPrediction; 5 | 6 | public interface QualitativeBankruptcyService { 7 | 8 | CompanyPrediction predict(CompanyInfo companyInfo); 9 | } 10 | -------------------------------------------------------------------------------- /ml-spark-service/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | spark.ml.model.path=/Users/bhdrkn/GitHub/ml-spark-service/target/model/Qualitative_Bankruptcy_Model -------------------------------------------------------------------------------- /ml-spark-service/src/test/java/com/bahadirakin/ml/MlSparkMvcServiceApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.bahadirakin.ml; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | import org.springframework.test.context.junit4.SpringRunner; 7 | 8 | @RunWith(SpringRunner.class) 9 | @SpringBootTest 10 | public class MlSparkMvcServiceApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /rest-tutorial/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /rest-tutorial/.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | -------------------------------------------------------------------------------- /rest-tutorial/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | rest-tutorial 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | org.eclipse.m2e.core.maven2Builder 15 | 16 | 17 | 18 | 19 | 20 | org.eclipse.jdt.core.javanature 21 | org.eclipse.m2e.core.maven2Nature 22 | 23 | 24 | -------------------------------------------------------------------------------- /rest-tutorial/.settings/org.eclipse.core.resources.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | encoding//src/main/java=UTF-8 3 | encoding//src/test/java=UTF-8 4 | encoding/=UTF-8 5 | -------------------------------------------------------------------------------- /rest-tutorial/.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5 3 | org.eclipse.jdt.core.compiler.compliance=1.5 4 | org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning 5 | org.eclipse.jdt.core.compiler.source=1.5 6 | -------------------------------------------------------------------------------- /rest-tutorial/.settings/org.eclipse.m2e.core.prefs: -------------------------------------------------------------------------------- 1 | activeProfiles= 2 | eclipse.preferences.version=1 3 | resolveWorkspaceProjects=true 4 | version=1 5 | -------------------------------------------------------------------------------- /rest-tutorial/pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | 5 | bahadirakin-tutorial 6 | rest-tutorial 7 | 1.0.0.1-SNAPSHOT 8 | pom 9 | 10 | rest-tutorial 11 | http://maven.apache.org 12 | 13 | 14 | 1.5 15 | UTF-8 16 | 17 | 18 | 19 | 20 | 21 | org.apache.maven.plugins 22 | maven-compiler-plugin 23 | 2.5.1 24 | 25 | ${target.java.version} 26 | ${target.java.version} 27 | 28 | 29 | 30 | maven-eclipse-plugin 31 | 2.9 32 | 33 | true 34 | true 35 | 36 | 37 | 38 | org.apache.maven.plugins 39 | maven-surefire-plugin 40 | 41 | true 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | org.slf4j 51 | slf4j-log4j12 52 | 1.6.2 53 | 54 | 55 | log4j 56 | log4j 57 | 1.2.16 58 | 59 | 60 | 61 | 62 | junit 63 | junit 64 | 4.8.1 65 | test 66 | 67 | 68 | 69 | rest-main 70 | rest-db 71 | 72 | 73 | -------------------------------------------------------------------------------- /rest-tutorial/rest-db/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /rest-tutorial/rest-db/.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | -------------------------------------------------------------------------------- /rest-tutorial/rest-db/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | rest-db 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.wst.common.project.facet.core.builder 10 | 11 | 12 | 13 | 14 | org.eclipse.jdt.core.javabuilder 15 | 16 | 17 | 18 | 19 | org.eclipse.m2e.core.maven2Builder 20 | 21 | 22 | 23 | 24 | org.hibernate.eclipse.console.hibernateBuilder 25 | 26 | 27 | 28 | 29 | org.eclipse.wst.validation.validationbuilder 30 | 31 | 32 | 33 | 34 | 35 | org.eclipse.jem.workbench.JavaEMFNature 36 | org.eclipse.wst.common.modulecore.ModuleCoreNature 37 | org.eclipse.jdt.core.javanature 38 | org.eclipse.m2e.core.maven2Nature 39 | org.hibernate.eclipse.console.hibernateNature 40 | org.eclipse.wst.common.project.facet.core.nature 41 | 42 | 43 | -------------------------------------------------------------------------------- /rest-tutorial/rest-db/.settings/org.eclipse.core.resources.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | encoding//src/main/java=UTF-8 3 | encoding//src/test/java=UTF-8 4 | encoding/=UTF-8 5 | -------------------------------------------------------------------------------- /rest-tutorial/rest-db/.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled 3 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5 4 | org.eclipse.jdt.core.compiler.compliance=1.5 5 | org.eclipse.jdt.core.compiler.problem.assertIdentifier=error 6 | org.eclipse.jdt.core.compiler.problem.enumIdentifier=error 7 | org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning 8 | org.eclipse.jdt.core.compiler.source=1.5 9 | -------------------------------------------------------------------------------- /rest-tutorial/rest-db/.settings/org.eclipse.m2e.core.prefs: -------------------------------------------------------------------------------- 1 | activeProfiles= 2 | eclipse.preferences.version=1 3 | resolveWorkspaceProjects=true 4 | version=1 5 | -------------------------------------------------------------------------------- /rest-tutorial/rest-db/.settings/org.eclipse.wst.common.component: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /rest-tutorial/rest-db/.settings/org.eclipse.wst.common.project.facet.core.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /rest-tutorial/rest-db/.settings/org.hibernate.eclipse.console.prefs: -------------------------------------------------------------------------------- 1 | default.configuration= 2 | eclipse.preferences.version=1 3 | hibernate3.enabled=true 4 | -------------------------------------------------------------------------------- /rest-tutorial/rest-db/src/main/java/com/bahadirakin/dao/ICarDAO.java: -------------------------------------------------------------------------------- 1 | package com.bahadirakin.dao; 2 | 3 | import com.bahadirakin.model.Car; 4 | 5 | public interface ICarDAO extends IBaseDAO { 6 | boolean isExist(String liecencePlate); 7 | } 8 | -------------------------------------------------------------------------------- /rest-tutorial/rest-db/src/main/java/com/bahadirakin/dao/IUserDAO.java: -------------------------------------------------------------------------------- 1 | package com.bahadirakin.dao; 2 | 3 | import com.bahadirakin.model.User; 4 | 5 | public interface IUserDAO extends IBaseDAO{ 6 | 7 | } 8 | -------------------------------------------------------------------------------- /rest-tutorial/rest-db/src/main/java/com/bahadirakin/dao/impl/CarDAO.java: -------------------------------------------------------------------------------- 1 | package com.bahadirakin.dao.impl; 2 | 3 | import java.util.List; 4 | 5 | import org.hibernate.criterion.Restrictions; 6 | 7 | import com.bahadirakin.dao.ICarDAO; 8 | import com.bahadirakin.model.Car; 9 | 10 | public class CarDAO extends BaseHibernateDAO implements ICarDAO { 11 | 12 | private static final long serialVersionUID = 1L; 13 | 14 | public boolean isExist(String liecencePlate) { 15 | List cars = this.findAllByCriteria(Restrictions.eq( 16 | "liecencePlate", liecencePlate)); 17 | if (cars == null) { 18 | return false; 19 | } 20 | 21 | if (cars.size() < 1) { 22 | return false; 23 | } else { 24 | return true; 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /rest-tutorial/rest-db/src/main/java/com/bahadirakin/dao/impl/UserDAO.java: -------------------------------------------------------------------------------- 1 | package com.bahadirakin.dao.impl; 2 | 3 | import com.bahadirakin.dao.IUserDAO; 4 | import com.bahadirakin.model.User; 5 | 6 | public class UserDAO extends BaseHibernateDAO implements IUserDAO{ 7 | 8 | private static final long serialVersionUID = 1L; 9 | 10 | } 11 | -------------------------------------------------------------------------------- /rest-tutorial/rest-db/src/main/java/com/bahadirakin/model/Car.java: -------------------------------------------------------------------------------- 1 | package com.bahadirakin.model; 2 | 3 | // Generated 06.Eki.2012 16:08:28 by Hibernate Tools 3.4.0.CR1 4 | 5 | import javax.persistence.Column; 6 | import javax.persistence.Entity; 7 | import javax.persistence.FetchType; 8 | import javax.persistence.GeneratedValue; 9 | import static javax.persistence.GenerationType.IDENTITY; 10 | import javax.persistence.Id; 11 | import javax.persistence.JoinColumn; 12 | import javax.persistence.ManyToOne; 13 | import javax.persistence.Table; 14 | import javax.xml.bind.annotation.XmlRootElement; 15 | import javax.xml.bind.annotation.XmlTransient; 16 | 17 | /** 18 | * Car generated by hbm2java 19 | */ 20 | @Entity 21 | @Table(name = "car") 22 | @XmlRootElement 23 | public class Car extends AbstractEntity { 24 | 25 | private static final long serialVersionUID = 1L; 26 | private Integer id; 27 | private User user; 28 | private String liecencePlate; 29 | private String model; 30 | 31 | public Car() { 32 | } 33 | 34 | public Car(User user, String liecencePlate) { 35 | this.user = user; 36 | this.liecencePlate = liecencePlate; 37 | } 38 | 39 | public Car(User user, String liecencePlate, String model) { 40 | this.user = user; 41 | this.liecencePlate = liecencePlate; 42 | this.model = model; 43 | } 44 | 45 | @Id 46 | @GeneratedValue(strategy = IDENTITY) 47 | @Column(name = "id", unique = true, nullable = false) 48 | public Integer getId() { 49 | return this.id; 50 | } 51 | 52 | public void setId(Integer id) { 53 | this.id = id; 54 | } 55 | 56 | @ManyToOne(fetch = FetchType.LAZY) 57 | @JoinColumn(name = "userId", nullable = false) 58 | @XmlTransient 59 | public User getUser() { 60 | return this.user; 61 | } 62 | 63 | public void setUser(User user) { 64 | this.user = user; 65 | } 66 | 67 | @Column(name = "liecencePlate", nullable = false, length = 50) 68 | public String getLiecencePlate() { 69 | return this.liecencePlate; 70 | } 71 | 72 | public void setLiecencePlate(String liecencePlate) { 73 | this.liecencePlate = liecencePlate; 74 | } 75 | 76 | @Column(name = "model", length = 50) 77 | public String getModel() { 78 | return this.model; 79 | } 80 | 81 | public void setModel(String model) { 82 | this.model = model; 83 | } 84 | 85 | } 86 | -------------------------------------------------------------------------------- /rest-tutorial/rest-db/src/main/java/com/bahadirakin/model/IEntity.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012 Bahadır AKIN 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.bahadirakin.model; 17 | 18 | import java.io.Serializable; 19 | 20 | /** 21 | * All database entities must implements this interface, which represents the 22 | * minimum requirements to meet. 23 | * 24 | *

25 | * A database entity always has Integer surrogate key (system ID). 26 | * It must also be {@link Serializable}, {@link Cloneable} and 27 | * {@link Comparable} 28 | *

29 | * 30 | * @author Bahadır AKIN 31 | * 32 | */ 33 | public interface IEntity extends Serializable, Cloneable, Comparable { 34 | 35 | public Integer getId(); 36 | 37 | public void setId(Integer id); 38 | 39 | boolean isNew(); 40 | } 41 | -------------------------------------------------------------------------------- /rest-tutorial/rest-db/src/main/java/com/bahadirakin/rest/App.java: -------------------------------------------------------------------------------- 1 | package com.bahadirakin.rest; 2 | 3 | /** 4 | * Hello world! 5 | * 6 | */ 7 | public class App 8 | { 9 | public static void main( String[] args ) 10 | { 11 | System.out.println( "Hello World!" ); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /rest-tutorial/rest-db/src/main/resources/hibernate.cfg.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | com.mysql.jdbc.Driver 7 | jdbc:mysql://localhost:3306/dbrest?useUnicode=true&characterEncoding=UTF-8 8 | dbrest 9 | root 10 | 11 | org.hibernate.dialect.MySQLDialect 12 | org.hibernate.context.ThreadLocalSessionContext 13 | 14 | 15 | 2 16 | 17 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /rest-tutorial/rest-db/src/main/resources/hibernate.reveng.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /rest-tutorial/rest-db/src/main/resources/log4j.properties: -------------------------------------------------------------------------------- 1 | log4j.rootLogger=INFO,Stdout 2 | 3 | log4j.appender.Stdout=org.apache.log4j.ConsoleAppender 4 | log4j.appender.Stdout.layout=org.apache.log4j.PatternLayout 5 | log4j.appender.Stdout.layout.conversionPattern=%-5p (%d{dd.MMM.yyyy - HH:mm:ss}) [%-26.26c{1}] - %m%n 6 | -------------------------------------------------------------------------------- /rest-tutorial/rest-db/src/test/java/com/bahadirakin/rest/AppTest.java: -------------------------------------------------------------------------------- 1 | package com.bahadirakin.rest; 2 | 3 | import junit.framework.Test; 4 | import junit.framework.TestCase; 5 | import junit.framework.TestSuite; 6 | 7 | /** 8 | * Unit test for simple App. 9 | */ 10 | public class AppTest 11 | extends TestCase 12 | { 13 | /** 14 | * Create the test case 15 | * 16 | * @param testName name of the test case 17 | */ 18 | public AppTest( String testName ) 19 | { 20 | super( testName ); 21 | } 22 | 23 | /** 24 | * @return the suite of tests being tested 25 | */ 26 | public static Test suite() 27 | { 28 | return new TestSuite( AppTest.class ); 29 | } 30 | 31 | /** 32 | * Rigourous Test :-) 33 | */ 34 | public void testApp() 35 | { 36 | assertTrue( true ); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /rest-tutorial/rest-main/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /rest-tutorial/rest-main/.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | -------------------------------------------------------------------------------- /rest-tutorial/rest-main/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | rest-main 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.wst.jsdt.core.javascriptValidator 10 | 11 | 12 | 13 | 14 | org.eclipse.jdt.core.javabuilder 15 | 16 | 17 | 18 | 19 | org.eclipse.wst.common.project.facet.core.builder 20 | 21 | 22 | 23 | 24 | org.eclipse.wst.validation.validationbuilder 25 | 26 | 27 | 28 | 29 | org.eclipse.m2e.core.maven2Builder 30 | 31 | 32 | 33 | 34 | 35 | org.eclipse.jem.workbench.JavaEMFNature 36 | org.eclipse.wst.common.modulecore.ModuleCoreNature 37 | org.eclipse.jdt.core.javanature 38 | org.eclipse.m2e.core.maven2Nature 39 | org.eclipse.wst.common.project.facet.core.nature 40 | org.eclipse.wst.jsdt.core.jsNature 41 | 42 | 43 | -------------------------------------------------------------------------------- /rest-tutorial/rest-main/.settings/.jsdtscope: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /rest-tutorial/rest-main/.settings/org.eclipse.core.resources.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | encoding//src/main/resources=UTF-8 3 | encoding/=UTF-8 4 | -------------------------------------------------------------------------------- /rest-tutorial/rest-main/.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled 3 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5 4 | org.eclipse.jdt.core.compiler.compliance=1.5 5 | org.eclipse.jdt.core.compiler.problem.assertIdentifier=error 6 | org.eclipse.jdt.core.compiler.problem.enumIdentifier=error 7 | org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning 8 | org.eclipse.jdt.core.compiler.source=1.5 9 | -------------------------------------------------------------------------------- /rest-tutorial/rest-main/.settings/org.eclipse.m2e.core.prefs: -------------------------------------------------------------------------------- 1 | activeProfiles= 2 | eclipse.preferences.version=1 3 | resolveWorkspaceProjects=true 4 | version=1 5 | -------------------------------------------------------------------------------- /rest-tutorial/rest-main/.settings/org.eclipse.wst.common.component: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | uses 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /rest-tutorial/rest-main/.settings/org.eclipse.wst.common.project.facet.core.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /rest-tutorial/rest-main/.settings/org.eclipse.wst.jsdt.ui.superType.container: -------------------------------------------------------------------------------- 1 | org.eclipse.wst.jsdt.launching.baseBrowserLibrary -------------------------------------------------------------------------------- /rest-tutorial/rest-main/.settings/org.eclipse.wst.jsdt.ui.superType.name: -------------------------------------------------------------------------------- 1 | Window -------------------------------------------------------------------------------- /rest-tutorial/rest-main/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | rest-tutorial 8 | bahadirakin-tutorial 9 | 1.0.0.1-SNAPSHOT 10 | 11 | 12 | rest-main 13 | war 14 | 15 | rest-main Maven Webapp 16 | http://maven.apache.org 17 | 18 | 19 | 20 | 21 | bahadirakin-tutorial 22 | rest-db 23 | ${project.version} 24 | 25 | 26 | 27 | com.sun.jersey 28 | jersey-server 29 | 1.14 30 | 31 | 32 | com.sun.jersey 33 | jersey-servlet 34 | 1.14 35 | 36 | 37 | 38 | rest-main 39 | 40 | 41 | -------------------------------------------------------------------------------- /rest-tutorial/rest-main/src/main/java/com/bahadirakin/services/HelloWorldService.java: -------------------------------------------------------------------------------- 1 | package com.bahadirakin.services; 2 | 3 | import javax.ws.rs.GET; 4 | import javax.ws.rs.Path; 5 | import javax.ws.rs.PathParam; 6 | import javax.ws.rs.Produces; 7 | import javax.ws.rs.QueryParam; 8 | import javax.ws.rs.core.MediaType; 9 | import javax.ws.rs.core.Response; 10 | 11 | @Path("hello") 12 | public class HelloWorldService { 13 | 14 | @GET 15 | @Produces(MediaType.TEXT_PLAIN) 16 | public String saySimpleHello() { 17 | return "Hello, World!"; 18 | } 19 | 20 | @GET 21 | @Produces(MediaType.TEXT_XML) 22 | @Path("/{to}") 23 | public String sayXmlHello(@PathParam("to") String to) { 24 | return "Hello, " + to + "!"; 25 | } 26 | 27 | @GET 28 | @Produces(MediaType.TEXT_HTML) 29 | @Path("/query") 30 | public Response sayHelloAgain(@QueryParam("to") String to) { 31 | return Response.ok("Hello, " + to + "!", MediaType.TEXT_HTML).build(); 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /rest-tutorial/rest-main/src/main/resources/hibernate.cfg.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | com.mysql.jdbc.Driver 7 | jdbc:mysql://localhost:3306/dbrest?useUnicode=true&characterEncoding=UTF-8 8 | dbrest 9 | root 10 | 11 | org.hibernate.dialect.MySQLDialect 12 | org.hibernate.context.ThreadLocalSessionContext 13 | 14 | 15 | 2 16 | 17 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /rest-tutorial/rest-main/src/main/resources/log4j.properties: -------------------------------------------------------------------------------- 1 | log4j.rootLogger=INFO,Stdout 2 | 3 | log4j.appender.Stdout=org.apache.log4j.ConsoleAppender 4 | log4j.appender.Stdout.layout=org.apache.log4j.PatternLayout 5 | log4j.appender.Stdout.layout.conversionPattern=%-5p (%d{dd.MMM.yyyy - HH:mm:ss}) [%-26.26c{1}] - %m%n 6 | -------------------------------------------------------------------------------- /rest-tutorial/rest-main/src/main/webapp/WEB-INF/web.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | RESTful Web Services - Tutorial 7 | 8 | Jersey Servlet 9 | com.sun.jersey.spi.container.servlet.ServletContainer 10 | 11 | com.sun.jersey.config.property.packages 12 | com.bahadirakin.services 13 | 14 | 1 15 | 16 | 17 | Jersey Servlet 18 | /rest/* 19 | 20 | 21 | -------------------------------------------------------------------------------- /rest-tutorial/rest-main/src/main/webapp/index.jsp: -------------------------------------------------------------------------------- 1 | 2 | 3 |

Hello World!

4 | 5 | 6 | -------------------------------------------------------------------------------- /retrolambda-sample/src/main/java/com/bahadirakin/User.java: -------------------------------------------------------------------------------- 1 | package com.bahadirakin; 2 | 3 | /** 4 | * Created by bhdrkn on 11/06/15. 5 | */ 6 | public class User { 7 | 8 | private final String username; 9 | private final String email; 10 | private final String password; 11 | 12 | 13 | public User(String username, String email, String password) { 14 | this.username = username; 15 | this.email = email; 16 | this.password = password; 17 | } 18 | 19 | public String getUsername() { 20 | return username; 21 | } 22 | 23 | public String getEmail() { 24 | return email; 25 | } 26 | 27 | public String getPassword() { 28 | return password; 29 | } 30 | 31 | @Override 32 | public String toString() { 33 | return "User{" + 34 | "username='" + username + '\'' + 35 | ", email='" + email + '\'' + 36 | ", password='" + password + '\'' + 37 | '}'; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /simple-smpp-routing/assembly.xml: -------------------------------------------------------------------------------- 1 | 5 | bin 6 | 7 | zip 8 | 9 | 10 | 11 | ${project.basedir}/src/main/resources/conf 12 | /conf 13 | 14 | *.properties 15 | *.xml 16 | 17 | 18 | 19 | ${project.basedir}/src/main/resources/bin 20 | / 21 | 22 | *.sh 23 | *.bat 24 | 25 | 26 | 27 | ${project.basedir}/src/main/resources 28 | / 29 | 30 | logback.xml 31 | import.sql 32 | 33 | 34 | 35 | 36 | 37 | /lib 38 | 39 | ${project.groupId}:${project.artifactId} 40 | 41 | 42 | 43 | / 44 | 45 | ${project.groupId}:${project.artifactId} 46 | 47 | 48 | 49 | false 50 | -------------------------------------------------------------------------------- /simple-smpp-routing/src/main/java/com/bahadirakin/App.java: -------------------------------------------------------------------------------- 1 | package com.bahadirakin; 2 | 3 | import org.springframework.context.support.AbstractApplicationContext; 4 | import org.springframework.context.support.ClassPathXmlApplicationContext; 5 | 6 | import java.io.IOException; 7 | 8 | public class App { 9 | public static void main(String[] args) throws IOException { 10 | System.out.println("Application is going to be started"); 11 | final AbstractApplicationContext applContext = new ClassPathXmlApplicationContext("classpath:applicationContext.xml"); 12 | applContext.registerShutdownHook(); 13 | System.out.println("Application is started"); 14 | 15 | System.in.read(); 16 | 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /simple-smpp-routing/src/main/resources/applicationContext.xml: -------------------------------------------------------------------------------- 1 | 2 | 10 | 11 | 12 | 13 | 14 | 16 | 17 | 18 | 19 | classpath*:conf/database.properties 20 | classpath*:conf/endpoint.properties 21 | 22 | 23 | 24 | 25 | 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /simple-smpp-routing/src/main/resources/bin/run.bat: -------------------------------------------------------------------------------- 1 | java -cp .;conf/*;lib/*;../* com.bahadirakin.App -------------------------------------------------------------------------------- /simple-smpp-routing/src/main/resources/bin/run.sh: -------------------------------------------------------------------------------- 1 | java -cp .:conf/*:lib/*:../* com.bahadirakin.App -------------------------------------------------------------------------------- /simple-smpp-routing/src/main/resources/conf/database.properties: -------------------------------------------------------------------------------- 1 | # Database Connection Properties 2 | 3 | # H2 4 | database.jdbc.driverClassName=org.h2.Driver 5 | database.jdbc.url=jdbc:h2:~/h2SpringJpaTutorialDb;AUTO_SERVER=TRUE 6 | database.jdbc.username=bhdrkn 7 | database.jdbc.password=1q2w3e 8 | hibernate.default_schema=H2SPRINGJPATUTORIALDB.PUBLIC 9 | 10 | # Postgresql 11 | # database.jdbc.driverClassName=org.postgresql.Driver 12 | # database.jdbc.url=jdbc:postgresql://localhost:5432/bulksmsdb?characterEncoding=UTF-8 13 | # database.jdbc.username=bhdrkn 14 | # database.jdbc.password=1q2w3e 15 | # hibernate.default_schema=public 16 | 17 | # MySql 18 | # database.jdbc.driverClassName=com.mysql.jdbc.Driver 19 | # database.jdbc.url=jdbc:mysql://localhost:3306/bulksmsdb?characterEncoding=UTF-8 20 | # database.jdbc.username=bhdrkn 21 | # database.jdbc.password=1q2w3e 22 | # hibernate.default_schema=bulksmsdb 23 | 24 | # Connection Pool properties 25 | database.c3p0.maxPoolSize=5 26 | database.c3p0.acquireIncrement=1 27 | database.c3p0.maxStatements=0 28 | database.c3p0.maxStatementsPerConnection=0 29 | database.c3p0.initialPoolSize=1 30 | database.c3p0.idleConnectionTestPeriod=1000 31 | database.c3p0.maxIdleTime=21600 32 | database.c3p0.unreturnedConnectionTimeout=1000 33 | database.c3p0.debugUnreturnedConnectionStackTraces=true 34 | 35 | # Hibernate Properties 36 | # https://docs.jboss.org/hibernate/core/4.2/manual/en-US/html/ch03.html#configuration-optional-properties 37 | hibernate.ejb.naming_strategy=org.hibernate.cfg.DefaultComponentSafeNamingStrategy 38 | hibernate.hbm2ddl.auto=create-drop 39 | hibernate.showSql=true 40 | hibernate.formatSql=true 41 | hibernate.generate_statistics=true 42 | hibernate.max_fetch_depth=3 43 | hibernate.default_batch_fetch_size=16 44 | hibernate.jdbc.batch_size=20 45 | hibernate.cache.region.factory_class=org.hibernate.cache.ehcache.EhCacheRegionFactory 46 | hibernate.cache.use_query_cache=true 47 | hibernate.cache.use_second_level_cache=false -------------------------------------------------------------------------------- /simple-smpp-routing/src/main/resources/import.sql: -------------------------------------------------------------------------------- 1 | INSERT INTO SHORTMESSAGE(DESTINATIONADDRESS, DESTINATIONNPI, DESTINATIONTON, MESSAGE, PRIORITYFLAG, SOURCEADDRESS, SOURCENPI, SOURCETON, VERSION) VALUES('05551234567',1,1,'HELLO, WORLD!',1,'05321234567',1,1,1); -------------------------------------------------------------------------------- /simple-smpp-routing/src/main/resources/logback.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | %d{HH:mm:ss.SSS} %-5level [%thread] %logger - %msg%n 8 | UTF-8 9 | 10 | 11 | 12 | 14 | 15 | 16 | 17 | ${logPath}/BulkSms-.%d{yyyy-MM-dd}.log.zip 18 | 19 | 20 | 21 | 30 22 | 23 | 24 | 25 | %d{HH:mm:ss.SSS} [%thread] %-5level %logger - %msg%n 26 | 27 | UTF-8 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /simple-smpp-routing/src/test/java/com/bahadirakin/AppTest.java: -------------------------------------------------------------------------------- 1 | package com.bahadirakin; 2 | 3 | import junit.framework.Test; 4 | import junit.framework.TestCase; 5 | import junit.framework.TestSuite; 6 | 7 | /** 8 | * Unit test for simple App. 9 | */ 10 | public class AppTest 11 | extends TestCase 12 | { 13 | /** 14 | * Create the test case 15 | * 16 | * @param testName name of the test case 17 | */ 18 | public AppTest( String testName ) 19 | { 20 | super( testName ); 21 | } 22 | 23 | /** 24 | * @return the suite of tests being tested 25 | */ 26 | public static Test suite() 27 | { 28 | return new TestSuite( AppTest.class ); 29 | } 30 | 31 | /** 32 | * Rigourous Test :-) 33 | */ 34 | public void testApp() 35 | { 36 | assertTrue( true ); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /spring-cxf/.gitignore: -------------------------------------------------------------------------------- 1 | 2 | # Eclipse # 3 | ########### 4 | .classpath 5 | /.settings 6 | .project 7 | /target 8 | 9 | # Compiled source # 10 | ################### 11 | *.com 12 | *.class 13 | *.dll 14 | *.exe 15 | *.o 16 | *.so 17 | 18 | # Packages # 19 | ############ 20 | # it's better to unpack these files and commit the raw source 21 | # git has its own built in compression methods 22 | *.7z 23 | *.dmg 24 | *.gz 25 | *.iso 26 | *.jar 27 | *.rar 28 | *.tar 29 | *.zip 30 | 31 | # Logs and databases # 32 | ###################### 33 | *.log 34 | *.sql 35 | *.sqlite 36 | 37 | # OS generated files # 38 | ###################### 39 | .DS_Store 40 | .DS_Store? 41 | ._* 42 | .Spotlight-V100 43 | .Trashes 44 | ehthumbs.db 45 | Thumbs.db 46 | 47 | -------------------------------------------------------------------------------- /spring-cxf/src/main/java/com/bahadirakin/model/HelloWorldMessage.java: -------------------------------------------------------------------------------- 1 | package com.bahadirakin.model; 2 | 3 | import java.io.Serializable; 4 | 5 | import javax.xml.bind.annotation.XmlAccessType; 6 | import javax.xml.bind.annotation.XmlAccessorType; 7 | import javax.xml.bind.annotation.XmlElement; 8 | import javax.xml.bind.annotation.XmlType; 9 | 10 | @XmlType(name = "helloWorldMessage", namespace = "http://model.bahadirakin.com") 11 | @XmlAccessorType(XmlAccessType.FIELD) 12 | public class HelloWorldMessage implements Serializable { 13 | 14 | private static final long serialVersionUID = 1L; 15 | 16 | @XmlElement(name = "message", namespace = "http://model.bahadirakin.com", nillable = false, required = true, type = String.class) 17 | private String message; 18 | 19 | public HelloWorldMessage() { 20 | super(); 21 | } 22 | 23 | public HelloWorldMessage(String message) { 24 | super(); 25 | this.message = message; 26 | } 27 | 28 | public String getMessage() { 29 | return message; 30 | } 31 | 32 | public void setMessage(String message) { 33 | this.message = message; 34 | } 35 | 36 | @Override 37 | public int hashCode() { 38 | final int prime = 31; 39 | int result = 1; 40 | result = prime * result + ((message == null) ? 0 : message.hashCode()); 41 | return result; 42 | } 43 | 44 | @Override 45 | public boolean equals(Object obj) { 46 | if (this == obj) 47 | return true; 48 | if (obj == null) 49 | return false; 50 | if (getClass() != obj.getClass()) 51 | return false; 52 | HelloWorldMessage other = (HelloWorldMessage) obj; 53 | if (message == null) { 54 | if (other.message != null) 55 | return false; 56 | } else if (!message.equals(other.message)) 57 | return false; 58 | return true; 59 | } 60 | 61 | @Override 62 | public String toString() { 63 | return "HelloWorldMessage [message=" + message + "]"; 64 | } 65 | 66 | } 67 | -------------------------------------------------------------------------------- /spring-cxf/src/main/java/com/bahadirakin/producer/MessageProducer.java: -------------------------------------------------------------------------------- 1 | package com.bahadirakin.producer; 2 | 3 | import java.io.Serializable; 4 | 5 | import com.bahadirakin.model.HelloWorldMessage; 6 | import com.bahadirakin.model.Person; 7 | 8 | /** 9 | * 10 | * @author bhdrkn 11 | * 12 | */ 13 | public interface MessageProducer extends Serializable{ 14 | 15 | HelloWorldMessage produceHelloWorldMessage(final Person person); 16 | } 17 | -------------------------------------------------------------------------------- /spring-cxf/src/main/java/com/bahadirakin/producer/MessageProducerImpl.java: -------------------------------------------------------------------------------- 1 | package com.bahadirakin.producer; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | 6 | import com.bahadirakin.model.HelloWorldMessage; 7 | import com.bahadirakin.model.Person; 8 | 9 | /** 10 | * 11 | * @author bhdrkn 12 | * 13 | */ 14 | public class MessageProducerImpl implements MessageProducer { 15 | 16 | /** 17 | * 18 | */ 19 | private static final long serialVersionUID = 1L; 20 | private static final Logger logger = LoggerFactory 21 | .getLogger(MessageProducerImpl.class); 22 | 23 | private static final String DEFAULT_HELLOWORLD_MESSAGE_FORMAT = "Hello to %s,%s"; 24 | 25 | @Override 26 | public HelloWorldMessage produceHelloWorldMessage(Person person) { 27 | if (person == null) { 28 | logger.info("Person is null"); 29 | return new HelloWorldMessage("Hello to everyone"); 30 | } 31 | 32 | logger.info("Saying hello to person: {}", person); 33 | return new HelloWorldMessage(String.format( 34 | DEFAULT_HELLOWORLD_MESSAGE_FORMAT, person.getSurname(), 35 | person.getName())); 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /spring-cxf/src/main/java/com/bahadirakin/service/HelloWorldService.java: -------------------------------------------------------------------------------- 1 | package com.bahadirakin.service; 2 | 3 | import java.io.Serializable; 4 | 5 | import javax.jws.WebMethod; 6 | import javax.jws.WebParam; 7 | import javax.jws.WebResult; 8 | import javax.jws.WebService; 9 | import javax.jws.soap.SOAPBinding; 10 | import javax.jws.soap.SOAPBinding.ParameterStyle; 11 | 12 | import com.bahadirakin.model.HelloWorldMessage; 13 | import com.bahadirakin.model.Person; 14 | 15 | @WebService(name="HelloWorldService", targetNamespace="http://service.bahadirakin.com") 16 | @SOAPBinding(parameterStyle=ParameterStyle.BARE) 17 | public interface HelloWorldService extends Serializable{ 18 | 19 | @WebMethod(operationName="sayHelloWorldTo", action="sayHelloWorldTo") 20 | @WebResult(name="helloWorldMessage", partName="helloWorldMessage", targetNamespace="http://model.bahadirakin.com") 21 | HelloWorldMessage sayHelloWorldTo(@WebParam(partName = "person", name = "person", targetNamespace = "http://model.bahadirakin.com/" ) Person person); 22 | } 23 | -------------------------------------------------------------------------------- /spring-cxf/src/main/java/com/bahadirakin/service/HelloWorldServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.bahadirakin.service; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | 6 | import com.bahadirakin.model.HelloWorldMessage; 7 | import com.bahadirakin.model.Person; 8 | import com.bahadirakin.producer.MessageProducer; 9 | 10 | public class HelloWorldServiceImpl implements HelloWorldService { 11 | 12 | private static final long serialVersionUID = 1L; 13 | private static final Logger logger = LoggerFactory 14 | .getLogger(HelloWorldMessage.class); 15 | 16 | private MessageProducer messageProducer; 17 | 18 | public HelloWorldServiceImpl(MessageProducer messageProducer) { 19 | super(); 20 | logger.info("Hello world service is created"); 21 | this.messageProducer = messageProducer; 22 | } 23 | 24 | @Override 25 | public HelloWorldMessage sayHelloWorldTo(Person person) { 26 | logger.info("Saying hello world to {}", person); 27 | return messageProducer.produceHelloWorldMessage(person); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /spring-cxf/src/main/resources/applicationContext.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 9 | 10 | 11 | 12 | 14 | 15 | 16 | 17 | 18 | 19 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /spring-cxf/src/main/webapp/WEB-INF/web.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | spring-cxf 7 | 8 | 9 | contextConfigLocation 10 | classpath*:applicationContext.xml 11 | 12 | 13 | 14 | org.springframework.web.context.ContextLoaderListener 15 | 16 | 17 | 18 | CXFServlet 19 | org.apache.cxf.transport.servlet.CXFServlet 20 | 1 21 | 22 | 23 | 24 | CXFServlet 25 | /* 26 | 27 | 28 | -------------------------------------------------------------------------------- /spring-hazelcast/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | com.bahadirakin 7 | spring-hazelcast 8 | 0.0.1-SNAPSHOT 9 | jar 10 | 11 | spring-hazelcast 12 | Demo project for Hazelcast and Spring Boot 13 | 14 | 15 | org.springframework.boot 16 | spring-boot-starter-parent 17 | 1.2.3.RELEASE 18 | 19 | 20 | 21 | 22 | UTF-8 23 | com.bahadirakin.hazelcast.SpringHazelcastApplication 24 | 1.7 25 | 26 | 27 | 28 | 29 | org.springframework.boot 30 | spring-boot-starter-data-jpa 31 | 32 | 33 | org.springframework.boot 34 | spring-boot-starter-web 35 | 36 | 37 | 38 | 39 | com.hazelcast 40 | hazelcast 41 | 3.4.1 42 | 43 | 44 | 45 | com.h2database 46 | h2 47 | runtime 48 | 49 | 50 | org.springframework.boot 51 | spring-boot-starter-test 52 | test 53 | 54 | 55 | 56 | 57 | 58 | 59 | org.springframework.boot 60 | spring-boot-maven-plugin 61 | 62 | 63 | 64 | 65 | 66 | -------------------------------------------------------------------------------- /spring-hazelcast/src/main/java/com/bahadirakin/hazelcast/UserMapStore.java: -------------------------------------------------------------------------------- 1 | package com.bahadirakin.hazelcast; 2 | 3 | import com.bahadirakin.hazelcast.dao.UserRepository; 4 | import com.bahadirakin.hazelcast.domain.User; 5 | import com.hazelcast.core.MapStore; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.stereotype.Service; 8 | import org.springframework.transaction.annotation.Transactional; 9 | 10 | import java.util.Collection; 11 | import java.util.HashMap; 12 | import java.util.Map; 13 | import java.util.Set; 14 | 15 | @Service 16 | @Transactional 17 | public class UserMapStore implements MapStore { 18 | 19 | @Autowired 20 | private UserRepository userRepository; 21 | 22 | @Override 23 | public void store(String key, User value) { 24 | userRepository.save(value); 25 | } 26 | 27 | @Override 28 | public void storeAll(Map map) { 29 | for (Map.Entry userEntry : map.entrySet()) { 30 | this.store(userEntry.getKey(), userEntry.getValue()); 31 | } 32 | } 33 | 34 | @Override 35 | public void delete(String key) { 36 | userRepository.deleteByUsername(key); 37 | } 38 | 39 | @Override 40 | public void deleteAll(Collection keys) { 41 | for (String key : keys) { 42 | this.delete(key); 43 | } 44 | } 45 | 46 | @Override 47 | public User load(String key) { 48 | return userRepository.findByUsername(key); 49 | } 50 | 51 | @Override 52 | public Map loadAll(Collection keys) { 53 | final Map users = new HashMap<>(); 54 | for (String key : keys) { 55 | users.put(key, load(key)); 56 | } 57 | 58 | return users; 59 | } 60 | 61 | @Override 62 | public Set loadAllKeys() { 63 | return userRepository.findAllUsernames(); 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /spring-hazelcast/src/main/java/com/bahadirakin/hazelcast/dao/UserRepository.java: -------------------------------------------------------------------------------- 1 | package com.bahadirakin.hazelcast.dao; 2 | 3 | import com.bahadirakin.hazelcast.domain.User; 4 | import org.springframework.data.jpa.repository.JpaRepository; 5 | import org.springframework.data.jpa.repository.Query; 6 | 7 | import java.util.Set; 8 | 9 | public interface UserRepository extends JpaRepository { 10 | 11 | User findByUsername(final String username); 12 | 13 | void deleteByUsername(String key); 14 | 15 | @Query("SELECT user.username FROM User user") 16 | Set findAllUsernames(); 17 | } 18 | -------------------------------------------------------------------------------- /spring-hazelcast/src/main/java/com/bahadirakin/hazelcast/domain/User.java: -------------------------------------------------------------------------------- 1 | package com.bahadirakin.hazelcast.domain; 2 | 3 | import javax.persistence.*; 4 | import java.io.Serializable; 5 | 6 | @Entity 7 | @Access(AccessType.FIELD) 8 | public class User implements Serializable{ 9 | 10 | @Id 11 | @GeneratedValue(strategy = GenerationType.AUTO) 12 | private Long id; 13 | 14 | @Column 15 | private String username; 16 | 17 | @Column 18 | private String password; 19 | 20 | @Column 21 | private String email; 22 | 23 | public Long getId() { 24 | return id; 25 | } 26 | 27 | public void setId(Long id) { 28 | this.id = id; 29 | } 30 | 31 | public String getUsername() { 32 | return username; 33 | } 34 | 35 | public void setUsername(String username) { 36 | this.username = username; 37 | } 38 | 39 | public String getPassword() { 40 | return password; 41 | } 42 | 43 | public void setPassword(String password) { 44 | this.password = password; 45 | } 46 | 47 | public String getEmail() { 48 | return email; 49 | } 50 | 51 | public void setEmail(String email) { 52 | this.email = email; 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /spring-hazelcast/src/main/java/com/bahadirakin/hazelcast/rest/UserRestService.java: -------------------------------------------------------------------------------- 1 | package com.bahadirakin.hazelcast.rest; 2 | 3 | import com.bahadirakin.hazelcast.domain.User; 4 | import com.hazelcast.core.HazelcastInstance; 5 | import com.hazelcast.core.IMap; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.web.bind.annotation.PathVariable; 8 | import org.springframework.web.bind.annotation.RequestMapping; 9 | import org.springframework.web.bind.annotation.RequestMethod; 10 | import org.springframework.web.bind.annotation.RestController; 11 | 12 | @RestController 13 | public class UserRestService { 14 | 15 | private IMap userMap; 16 | 17 | @Autowired 18 | public UserRestService(HazelcastInstance hazelcastInstance){ 19 | this.userMap = hazelcastInstance.getMap("userMap"); 20 | } 21 | 22 | @RequestMapping(method = RequestMethod.GET, value = "/user/{username}") 23 | public User getUserWithUsername(@PathVariable(value = "username") final String username) { 24 | return userMap.get(username); 25 | } 26 | 27 | @RequestMapping(method = RequestMethod.PUT, value = "/user/{username}") 28 | public void updateUserWithUsername(@PathVariable(value = "username") final String username, final User user) { 29 | assert username.equals(user.getUsername()); 30 | userMap.put(username, user); 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /spring-hazelcast/src/main/resources/application.properties: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bhdrkn/Java-Examples/3b3cc50211e3313a0dbbeb7d342220fbd0f7cf80/spring-hazelcast/src/main/resources/application.properties -------------------------------------------------------------------------------- /spring-hazelcast/src/main/resources/import.sql: -------------------------------------------------------------------------------- 1 | INSERT INTO user (id, username, password, email) VALUES (1, 'bhdrkn', '1q2w3e', 'bhdrkn[at]gmail.com'); -------------------------------------------------------------------------------- /spring-hazelcast/src/test/java/com/bahadirakin/hazelcast/SpringHazelcastApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.bahadirakin.hazelcast; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.test.context.web.WebAppConfiguration; 6 | import org.springframework.boot.test.SpringApplicationConfiguration; 7 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 8 | 9 | @RunWith(SpringJUnit4ClassRunner.class) 10 | @SpringApplicationConfiguration(classes = SpringHazelcastApplication.class) 11 | @WebAppConfiguration 12 | public class SpringHazelcastApplicationTests { 13 | 14 | @Test 15 | public void contextLoads() { 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /spring-hibernate-5/src/main/java/com/bahadirakin/SpringHibernate5Application.java: -------------------------------------------------------------------------------- 1 | package com.bahadirakin; 2 | 3 | import org.springframework.boot.CommandLineRunner; 4 | import org.springframework.boot.SpringApplication; 5 | import org.springframework.boot.autoconfigure.SpringBootApplication; 6 | 7 | @SpringBootApplication 8 | public class SpringHibernate5Application implements CommandLineRunner { 9 | 10 | public static void main(String[] args) { 11 | SpringApplication.run(SpringHibernate5Application.class, args); 12 | } 13 | 14 | @Override 15 | public void run(String... strings) throws Exception { 16 | System.out.println("Hello, World!"); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /spring-hibernate-5/src/main/java/com/bahadirakin/entity/User.java: -------------------------------------------------------------------------------- 1 | package com.bahadirakin.entity; 2 | 3 | import org.hibernate.envers.Audited; 4 | 5 | import javax.persistence.*; 6 | 7 | @Entity 8 | @Table(name = "T_USER") 9 | @Access(AccessType.FIELD) 10 | @Audited 11 | public class User { 12 | 13 | @Id 14 | @GeneratedValue(strategy = GenerationType.AUTO) 15 | private Long id; 16 | 17 | @Column(name = "C_USERNAME", unique = true) 18 | private String username; 19 | 20 | @Column(name = "C_PASSWORD") 21 | private String password; 22 | 23 | @Column(name = "C_EMAIL") 24 | private String email; 25 | 26 | public Long getId() { 27 | return id; 28 | } 29 | 30 | public void setId(Long id) { 31 | this.id = id; 32 | } 33 | 34 | public String getUsername() { 35 | return username; 36 | } 37 | 38 | public void setUsername(String username) { 39 | this.username = username; 40 | } 41 | 42 | public String getPassword() { 43 | return password; 44 | } 45 | 46 | public void setPassword(String password) { 47 | this.password = password; 48 | } 49 | 50 | public String getEmail() { 51 | return email; 52 | } 53 | 54 | public void setEmail(String email) { 55 | this.email = email; 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /spring-hibernate-5/src/main/resources/application.properties: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bhdrkn/Java-Examples/3b3cc50211e3313a0dbbeb7d342220fbd0f7cf80/spring-hibernate-5/src/main/resources/application.properties -------------------------------------------------------------------------------- /spring-hibernate-5/src/test/java/com/bahadirakin/SpringHibernate5ApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.bahadirakin; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.SpringApplicationConfiguration; 6 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 7 | 8 | @RunWith(SpringJUnit4ClassRunner.class) 9 | @SpringApplicationConfiguration(classes = SpringHibernate5Application.class) 10 | public class SpringHibernate5ApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /spring-jpa/.gitignore: -------------------------------------------------------------------------------- 1 | 2 | # Eclipse # 3 | ########### 4 | .classpath 5 | /.settings 6 | .project 7 | /target 8 | 9 | # Compiled source # 10 | ################### 11 | *.com 12 | *.class 13 | *.dll 14 | *.exe 15 | *.o 16 | *.so 17 | 18 | # Packages # 19 | ############ 20 | # it's better to unpack these files and commit the raw source 21 | # git has its own built in compression methods 22 | *.7z 23 | *.dmg 24 | *.gz 25 | *.iso 26 | *.jar 27 | *.rar 28 | *.tar 29 | *.zip 30 | 31 | # Logs and databases # 32 | ###################### 33 | *.log 34 | *.sql 35 | *.sqlite 36 | 37 | # OS generated files # 38 | ###################### 39 | .DS_Store 40 | .DS_Store? 41 | ._* 42 | .Spotlight-V100 43 | .Trashes 44 | ehthumbs.db 45 | Thumbs.db 46 | 47 | -------------------------------------------------------------------------------- /spring-jpa/src/main/java/com/bahadirakin/App.java: -------------------------------------------------------------------------------- 1 | package com.bahadirakin; 2 | 3 | import java.util.List; 4 | 5 | import org.springframework.context.support.AbstractApplicationContext; 6 | import org.springframework.context.support.ClassPathXmlApplicationContext; 7 | 8 | import com.bahadirakin.model.Car; 9 | import com.bahadirakin.service.CarService; 10 | import com.bahadirakin.service.ICarService; 11 | 12 | 13 | /** 14 | * Hello world! 15 | * 16 | */ 17 | public class App { 18 | public static void main(String[] args) throws InterruptedException { 19 | System.out.println("Application is going to be started"); 20 | final AbstractApplicationContext applContext = new ClassPathXmlApplicationContext("classpath:applicationContext.xml"); 21 | applContext.registerShutdownHook(); 22 | System.out.println("Application is started"); 23 | 24 | final ICarService carService = (ICarService) applContext.getBean("carService"); 25 | final List cars = carService.getAllCars(); 26 | 27 | if(cars == null || cars.isEmpty()){ 28 | System.out.println("Cars is empty."); 29 | 30 | }else{ 31 | System.out.println("Cars: " + cars); 32 | } 33 | 34 | Thread.sleep(10000); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /spring-jpa/src/main/java/com/bahadirakin/dao/CarDao.java: -------------------------------------------------------------------------------- 1 | package com.bahadirakin.dao; 2 | 3 | import java.util.List; 4 | 5 | import javax.persistence.EntityManager; 6 | import javax.persistence.PersistenceContext; 7 | 8 | import org.springframework.transaction.annotation.Propagation; 9 | import org.springframework.transaction.annotation.Transactional; 10 | 11 | import com.bahadirakin.model.Car; 12 | 13 | @Transactional(propagation = Propagation.MANDATORY, rollbackFor = Exception.class, value = "transactionManager") 14 | public class CarDao implements ICarDao { 15 | 16 | private static final long serialVersionUID = 1L; 17 | 18 | @PersistenceContext(unitName = "entityManagerFactory") 19 | private EntityManager entityManager; 20 | 21 | public EntityManager getEntityManager() { 22 | return entityManager; 23 | } 24 | 25 | public void setEntityManager(EntityManager entityManager) { 26 | this.entityManager = entityManager; 27 | } 28 | 29 | /* (non-Javadoc) 30 | * @see com.bahadirakin.dao.ICarDao#detach(java.lang.Object) 31 | */ 32 | @Override 33 | public void detach(Object arg0) { 34 | entityManager.detach(arg0); 35 | } 36 | 37 | /* (non-Javadoc) 38 | * @see com.bahadirakin.dao.ICarDao#findAll() 39 | */ 40 | @Override 41 | public List findAll() { 42 | System.out.println(entityManager); 43 | return entityManager.createQuery("SELECT car FROM Car car").getResultList(); 44 | } 45 | 46 | /* (non-Javadoc) 47 | * @see com.bahadirakin.dao.ICarDao#merge(com.bahadirakin.model.Car) 48 | */ 49 | @Override 50 | public Car merge(Car arg0) { 51 | return entityManager.merge(arg0); 52 | } 53 | 54 | /* (non-Javadoc) 55 | * @see com.bahadirakin.dao.ICarDao#persist(com.bahadirakin.model.Car) 56 | */ 57 | @Override 58 | public void persist(Car arg0) { 59 | entityManager.persist(arg0); 60 | } 61 | 62 | } 63 | -------------------------------------------------------------------------------- /spring-jpa/src/main/java/com/bahadirakin/dao/ICarDao.java: -------------------------------------------------------------------------------- 1 | package com.bahadirakin.dao; 2 | 3 | import java.io.Serializable; 4 | import java.util.List; 5 | 6 | import com.bahadirakin.model.Car; 7 | 8 | public interface ICarDao extends Serializable{ 9 | 10 | void detach(Object arg0); 11 | 12 | List findAll(); 13 | 14 | Car merge(Car arg0); 15 | 16 | void persist(Car arg0); 17 | 18 | } -------------------------------------------------------------------------------- /spring-jpa/src/main/java/com/bahadirakin/model/Car.java: -------------------------------------------------------------------------------- 1 | package com.bahadirakin.model; 2 | 3 | import java.io.Serializable; 4 | 5 | import javax.persistence.Column; 6 | import javax.persistence.Entity; 7 | import javax.persistence.GeneratedValue; 8 | import javax.persistence.Id; 9 | import javax.persistence.Table; 10 | 11 | @Entity 12 | @Table(name = "car") 13 | public class Car implements Serializable { 14 | 15 | private static final long serialVersionUID = 1L; 16 | 17 | @Id 18 | @GeneratedValue 19 | private Long id; 20 | 21 | @Column(name = "brand") 22 | private String brand; 23 | 24 | @Column(name = "year") 25 | private int year; 26 | 27 | @Column(name = "color") 28 | private String color; 29 | 30 | @Column(name = "price") 31 | private Double price; 32 | 33 | public Car() { 34 | } 35 | 36 | public Long getId() { 37 | return id; 38 | } 39 | 40 | public void setId(Long id) { 41 | this.id = id; 42 | } 43 | 44 | public String getBrand() { 45 | return brand; 46 | } 47 | 48 | public void setBrand(String brand) { 49 | this.brand = brand; 50 | } 51 | 52 | public int getYear() { 53 | return year; 54 | } 55 | 56 | public void setYear(int year) { 57 | this.year = year; 58 | } 59 | 60 | public String getColor() { 61 | return color; 62 | } 63 | 64 | public void setColor(String color) { 65 | this.color = color; 66 | } 67 | 68 | public Double getPrice() { 69 | return price; 70 | } 71 | 72 | public void setPrice(Double price) { 73 | this.price = price; 74 | } 75 | 76 | @Override 77 | public String toString() { 78 | return "Car [id=" + id + ", brand=" + brand + ", year=" + year 79 | + ", color=" + color + ", price=" + price + "]"; 80 | } 81 | 82 | } 83 | -------------------------------------------------------------------------------- /spring-jpa/src/main/java/com/bahadirakin/service/CarService.java: -------------------------------------------------------------------------------- 1 | package com.bahadirakin.service; 2 | 3 | import java.util.List; 4 | 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.beans.factory.annotation.Qualifier; 7 | import org.springframework.stereotype.Component; 8 | import org.springframework.stereotype.Service; 9 | import org.springframework.transaction.annotation.Propagation; 10 | import org.springframework.transaction.annotation.Transactional; 11 | 12 | import com.bahadirakin.dao.ICarDao; 13 | import com.bahadirakin.model.Car; 14 | 15 | @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class, value = "transactionManager") 16 | public class CarService implements ICarService { 17 | 18 | private static final long serialVersionUID = 1L; 19 | 20 | private ICarDao carDao; 21 | 22 | /* 23 | * (non-Javadoc) 24 | * 25 | * @see com.bahadirakin.service.ICarService#delete(java.lang.Object) 26 | */ 27 | @Override 28 | public void delete(Object arg0) { 29 | carDao.detach(arg0); 30 | } 31 | 32 | /* 33 | * (non-Javadoc) 34 | * 35 | * @see com.bahadirakin.service.ICarService#getAllCars() 36 | */ 37 | @Override 38 | public List getAllCars() { 39 | return carDao.findAll(); 40 | } 41 | 42 | /* 43 | * (non-Javadoc) 44 | * 45 | * @see 46 | * com.bahadirakin.service.ICarService#updateCar(com.bahadirakin.model.Car) 47 | */ 48 | @Override 49 | public Car updateCar(Car arg0) { 50 | return carDao.merge(arg0); 51 | } 52 | 53 | /* 54 | * (non-Javadoc) 55 | * 56 | * @see 57 | * com.bahadirakin.service.ICarService#createNewCar(com.bahadirakin.model 58 | * .Car) 59 | */ 60 | @Override 61 | public void createNewCar(Car arg0) { 62 | carDao.persist(arg0); 63 | } 64 | 65 | public ICarDao getCarDao() { 66 | return carDao; 67 | } 68 | 69 | public void setCarDao(ICarDao carDao) { 70 | this.carDao = carDao; 71 | } 72 | 73 | } 74 | -------------------------------------------------------------------------------- /spring-jpa/src/main/java/com/bahadirakin/service/ICarService.java: -------------------------------------------------------------------------------- 1 | package com.bahadirakin.service; 2 | 3 | import java.io.Serializable; 4 | import java.util.List; 5 | 6 | import org.springframework.stereotype.Service; 7 | 8 | import com.bahadirakin.model.Car; 9 | 10 | public interface ICarService extends Serializable{ 11 | 12 | void delete(Object arg0); 13 | 14 | List getAllCars(); 15 | 16 | Car updateCar(Car arg0); 17 | 18 | void createNewCar(Car arg0); 19 | 20 | } -------------------------------------------------------------------------------- /spring-jpa/src/main/resources/applicationContext.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /spring-jpa/src/main/resources/environment/persistance-dev.properties: -------------------------------------------------------------------------------- 1 | # JDBC Bilgileri 2 | jdbc.driverClassName=org.h2.Driver 3 | jdbc.url=jdbc\:h2\:~/h2SpringJpaTutorialDb;AUTO_SERVER\=TRUE 4 | jdbc.username=bhdrkn 5 | jdbc.password=1q2w3e 6 | 7 | hibernate.default_schema=H2SPRINGJPATUTORIALDB.PUBLIC 8 | 9 | # https://docs.jboss.org/hibernate/core/4.2/manual/en-US/html/ch03.html#configuration-optional-properties 10 | hibernate.ejb.naming_strategy=org.hibernate.cfg.DefaultComponentSafeNamingStrategy 11 | hibernate.hbm2ddl.auto=create 12 | hibernate.showSql=true 13 | hibernate.formatSql=true 14 | hibernate.generate_statistics=true 15 | hibernate.max_fetch_depth=3 16 | hibernate.default_batch_fetch_size=16 17 | hibernate.jdbc.batch_size=20 18 | hibernate.cache.region.factory_class=org.hibernate.cache.ehcache.EhCacheRegionFactory 19 | hibernate.cache.use_query_cache=true 20 | hibernate.cache.use_second_level_cache=false -------------------------------------------------------------------------------- /spring-jpa/src/main/resources/environment/persistance-prod.properties: -------------------------------------------------------------------------------- 1 | # JDBC Bilgileri 2 | jdbc.driverClassName=org.postgresql.Driver 3 | jdbc.url=jdbc\:postgresql\://localhost\:5432/SpringJpaTutorialDb?characterEncoding\=UTF-8 4 | jdbc.username=bhdrkn 5 | jdbc.password=1q2w3e 6 | 7 | hibernate.default_schema=SpringJpaTutorialDb 8 | 9 | # https://docs.jboss.org/hibernate/core/4.2/manual/en-US/html/ch03.html#configuration-optional-properties 10 | hibernate.ejb.naming_strategy=org.hibernate.cfg.DefaultComponentSafeNamingStrategy 11 | hibernate.hbm2ddl.auto=update 12 | hibernate.showSql=false 13 | hibernate.formatSql=false 14 | hibernate.generate_statistics=false 15 | hibernate.max_fetch_depth=3 16 | hibernate.default_batch_fetch_size=16 17 | hibernate.jdbc.batch_size=20 18 | hibernate.cache.region.factory_class=org.hibernate.cache.ehcache.EhCacheRegionFactory 19 | hibernate.cache.use_query_cache=true 20 | hibernate.cache.use_second_level_cache=true -------------------------------------------------------------------------------- /spring-jpa/src/main/resources/environment/persistance-uat.properties: -------------------------------------------------------------------------------- 1 | # JDBC Bilgileri 2 | jdbc.driverClassName=com.mysql.jdbc.Driver 3 | jdbc.url=jdbc\:mysql\://localhost\:3306/SpringJpaTutorialDb?characterEncoding\=UTF-8 4 | jdbc.username=bhdrkn 5 | jdbc.password=1q2w3e 6 | 7 | hibernate.default_schema=SpringJpaTutorialDb 8 | 9 | # https://docs.jboss.org/hibernate/core/4.2/manual/en-US/html/ch03.html#configuration-optional-properties 10 | hibernate.ejb.naming_strategy=org.hibernate.cfg.DefaultComponentSafeNamingStrategy 11 | hibernate.hbm2ddl.auto=update 12 | hibernate.showSql=true 13 | hibernate.formatSql=true 14 | hibernate.generate_statistics=false 15 | hibernate.max_fetch_depth=3 16 | hibernate.default_batch_fetch_size=16 17 | hibernate.jdbc.batch_size=20 18 | hibernate.cache.region.factory_class=org.hibernate.cache.ehcache.EhCacheRegionFactory 19 | hibernate.cache.use_query_cache=true 20 | hibernate.cache.use_second_level_cache=false 21 | -------------------------------------------------------------------------------- /spring-jpa/src/test/java/com/bahadirakin/AppTest.java: -------------------------------------------------------------------------------- 1 | package com.bahadirakin; 2 | 3 | import junit.framework.Test; 4 | import junit.framework.TestCase; 5 | import junit.framework.TestSuite; 6 | 7 | /** 8 | * Unit test for simple App. 9 | */ 10 | public class AppTest 11 | extends TestCase 12 | { 13 | /** 14 | * Create the test case 15 | * 16 | * @param testName name of the test case 17 | */ 18 | public AppTest( String testName ) 19 | { 20 | super( testName ); 21 | } 22 | 23 | /** 24 | * @return the suite of tests being tested 25 | */ 26 | public static Test suite() 27 | { 28 | return new TestSuite( AppTest.class ); 29 | } 30 | 31 | /** 32 | * Rigourous Test :-) 33 | */ 34 | public void testApp() 35 | { 36 | assertTrue( true ); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /spring-prime/.gitignore: -------------------------------------------------------------------------------- 1 | 2 | # Eclipse # 3 | ########### 4 | .classpath 5 | /.settings 6 | .project 7 | /target 8 | 9 | # Compiled source # 10 | ################### 11 | *.com 12 | *.class 13 | *.dll 14 | *.exe 15 | *.o 16 | *.so 17 | 18 | # Packages # 19 | ############ 20 | # it's better to unpack these files and commit the raw source 21 | # git has its own built in compression methods 22 | *.7z 23 | *.dmg 24 | *.gz 25 | *.iso 26 | *.jar 27 | *.rar 28 | *.tar 29 | *.zip 30 | 31 | # Logs and databases # 32 | ###################### 33 | *.log 34 | *.sql 35 | *.sqlite 36 | 37 | # OS generated files # 38 | ###################### 39 | .DS_Store 40 | .DS_Store? 41 | ._* 42 | .Spotlight-V100 43 | .Trashes 44 | ehthumbs.db 45 | Thumbs.db 46 | 47 | -------------------------------------------------------------------------------- /spring-prime/src/main/java/com/bahadirakin/service/ICarService.java: -------------------------------------------------------------------------------- 1 | package com.bahadirakin.service; 2 | 3 | import java.util.List; 4 | 5 | import com.bahadirakin.model.Car; 6 | 7 | public interface ICarService { 8 | 9 | List getAllCars(); 10 | 11 | void saveCar(final Car car); 12 | } 13 | -------------------------------------------------------------------------------- /spring-prime/src/main/java/com/bahadirakin/service/RandomCarService.java: -------------------------------------------------------------------------------- 1 | package com.bahadirakin.service; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | import java.util.UUID; 6 | 7 | import org.slf4j.Logger; 8 | import org.slf4j.LoggerFactory; 9 | 10 | import com.bahadirakin.model.Car; 11 | 12 | public class RandomCarService implements ICarService { 13 | 14 | private static final Logger logger = LoggerFactory 15 | .getLogger(RandomCarService.class); 16 | 17 | private static final int RANDOM_LIST_SIZE = 25; 18 | 19 | private static final String[] COLORS = new String[] { "Black", "White", 20 | "Green", "Red", "Blue", "Orange", "Silver", "Yellow", "Brown", 21 | "Maroon" }; 22 | 23 | private static final String[] BRANDS = new String[] { "BMW", "Mercedes", 24 | "Volvo", "Audi", "Renault", "Fiat", "Volkswagen", "Honda", 25 | "Jaguar", "Ford" }; 26 | 27 | private List savedCars; 28 | 29 | public RandomCarService() { 30 | savedCars = new ArrayList<>(); 31 | } 32 | 33 | @Override 34 | public List getAllCars() { 35 | final List list = new ArrayList(); 36 | list.addAll(savedCars); 37 | 38 | for (int i = 0; i < RANDOM_LIST_SIZE; i++) { 39 | list.add(new Car(getRandomId(), getRandomBrand(), getRandomYear(), 40 | getRandomColor(), getRandomPrice())); 41 | } 42 | 43 | logger.info("Returning all the cars with size {}", list.size()); 44 | return list; 45 | } 46 | 47 | @Override 48 | public void saveCar(Car car) { 49 | car.setId(getRandomId()); 50 | savedCars.add(car); 51 | logger.info("Car is saved: {}", car); 52 | } 53 | 54 | private String getRandomId() { 55 | return UUID.randomUUID().toString().substring(0, 8); 56 | } 57 | 58 | private int getRandomYear() { 59 | return (int) (Math.random() * 50 + 1960); 60 | } 61 | 62 | private String getRandomColor() { 63 | return COLORS[(int) (Math.random() * COLORS.length)]; 64 | } 65 | 66 | private String getRandomBrand() { 67 | return BRANDS[(int) (Math.random() * BRANDS.length)]; 68 | } 69 | 70 | private int getRandomPrice() { 71 | return (int) (Math.random() * 100000); 72 | } 73 | 74 | } 75 | -------------------------------------------------------------------------------- /spring-prime/src/main/java/com/bahadirakin/webapp/CarBean.java: -------------------------------------------------------------------------------- 1 | package com.bahadirakin.webapp; 2 | 3 | import java.io.Serializable; 4 | import java.util.List; 5 | 6 | import javax.annotation.PostConstruct; 7 | 8 | import org.slf4j.Logger; 9 | import org.slf4j.LoggerFactory; 10 | import org.springframework.beans.factory.annotation.Autowired; 11 | import org.springframework.context.annotation.Scope; 12 | import org.springframework.stereotype.Component; 13 | 14 | import com.bahadirakin.model.Car; 15 | import com.bahadirakin.service.ICarService; 16 | 17 | @Component 18 | @Scope("request") 19 | public class CarBean implements Serializable { 20 | 21 | private static final long serialVersionUID = 1L; 22 | private static final Logger logger = LoggerFactory.getLogger(CarBean.class); 23 | 24 | @Autowired 25 | private ICarService carService; 26 | private Car car; 27 | 28 | private List cars; 29 | 30 | public CarBean() { 31 | super(); 32 | } 33 | 34 | @PostConstruct 35 | public void init() { 36 | this.car = new Car(); 37 | this.cars = carService.getAllCars(); 38 | } 39 | 40 | public void save() { 41 | logger.info("new car is going to be saved: {} ", this.car); 42 | this.carService.saveCar(car); 43 | this.init(); 44 | } 45 | 46 | public Car getCar() { 47 | return car; 48 | } 49 | 50 | public void setCar(Car car) { 51 | this.car = car; 52 | } 53 | 54 | public ICarService getCarService() { 55 | return carService; 56 | } 57 | 58 | public void setCarService(ICarService carService) { 59 | this.carService = carService; 60 | } 61 | 62 | public List getCars() { 63 | return cars; 64 | } 65 | 66 | public void setCars(List cars) { 67 | this.cars = cars; 68 | } 69 | 70 | } 71 | -------------------------------------------------------------------------------- /spring-prime/src/main/resources/applicationContext.xml: -------------------------------------------------------------------------------- 1 | 2 | 10 | 11 | 12 | 13 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /spring-prime/src/main/webapp/WEB-INF/faces-config.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 8 | 9 | 10 | org.springframework.web.jsf.el.SpringBeanFacesELResolver 11 | 12 | 13 | tr 14 | tr 15 | 16 | 17 | org.primefaces.application.DialogActionListener 18 | org.primefaces.application.DialogNavigationHandler 19 | org.primefaces.application.DialogViewHandler 20 | 21 | 22 | 23 | 24 | org.primefaces.application.exceptionhandler.PrimeExceptionHandlerFactory 25 | 26 | 27 | -------------------------------------------------------------------------------- /spring-prime/src/main/webapp/WEB-INF/web.xml: -------------------------------------------------------------------------------- 1 | 5 | spring-prime 6 | 7 | 8 | 9 | 10 | contextConfigLocation 11 | classpath*:applicationContext.xml 12 | 13 | 14 | 15 | javax.faces.PROJECT_STAGE 16 | Development 17 | 18 | 19 | 20 | javax.faces.DEFAULT_SUFFIX 21 | .xhtml 22 | 23 | 24 | 25 | 26 | 27 | org.springframework.web.context.ContextLoaderListener 28 | 29 | 30 | 31 | org.springframework.web.context.request.RequestContextListener 32 | 33 | 34 | 35 | com.sun.faces.config.ConfigureListener 36 | 37 | 38 | 39 | 40 | 41 | Faces Servlet 42 | javax.faces.webapp.FacesServlet 43 | 1 44 | 45 | 46 | 47 | Faces Servlet 48 | /faces/* 49 | 50 | 51 | Faces Servlet 52 | *.jsf 53 | 54 | 55 | Faces Servlet 56 | *.faces 57 | 58 | 59 | Faces Servlet 60 | *.xhtml 61 | 62 | 63 | 64 | index.xhtml 65 | 66 | 67 | -------------------------------------------------------------------------------- /spring-prime/src/main/webapp/index.xhtml: -------------------------------------------------------------------------------- 1 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | -------------------------------------------------------------------------------- /spring-quartz/src/main/java/com/bahadirakin/App.java: -------------------------------------------------------------------------------- 1 | package com.bahadirakin; 2 | 3 | import org.springframework.context.ApplicationContext; 4 | import org.springframework.context.ConfigurableApplicationContext; 5 | import org.springframework.context.support.ClassPathXmlApplicationContext; 6 | 7 | import java.util.Date; 8 | 9 | /** 10 | * Hello world! 11 | */ 12 | public class App { 13 | public static void main(String[] args) { 14 | final ApplicationContext applicationContext = new ClassPathXmlApplicationContext 15 | ("classpath*:application-context.xml"); 16 | 17 | Thread shutdownThread = new Thread() { 18 | 19 | public void run() { 20 | if (applicationContext instanceof ConfigurableApplicationContext) { 21 | ((ConfigurableApplicationContext) applicationContext).close(); 22 | } 23 | } 24 | }; 25 | Runtime.getRuntime().addShutdownHook(shutdownThread); 26 | 27 | final SchedulerController schedulerController = applicationContext.getBean(SchedulerController.class); 28 | schedulerController.addJob(new DatabaseMonitor(new Date().toString(), "sql query")); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /spring-quartz/src/main/java/com/bahadirakin/DatabaseJob.java: -------------------------------------------------------------------------------- 1 | package com.bahadirakin; 2 | 3 | import org.quartz.Job; 4 | import org.quartz.JobDataMap; 5 | import org.quartz.JobExecutionContext; 6 | import org.quartz.JobExecutionException; 7 | 8 | import java.io.Serializable; 9 | 10 | public class DatabaseJob implements Job, Serializable { 11 | @Override 12 | public void execute(JobExecutionContext context) throws JobExecutionException { 13 | final JobDataMap jobDataMap = context.getMergedJobDataMap(); 14 | final String sqlQuery = jobDataMap.getString("sqlQuery"); 15 | System.out.println("SqlQuery: " + sqlQuery); 16 | } 17 | } -------------------------------------------------------------------------------- /spring-quartz/src/main/java/com/bahadirakin/DatabaseMonitor.java: -------------------------------------------------------------------------------- 1 | package com.bahadirakin; 2 | 3 | public class DatabaseMonitor { 4 | 5 | private Integer id; 6 | private String name; 7 | private String sqlQuery; 8 | 9 | public DatabaseMonitor() { 10 | } 11 | 12 | public DatabaseMonitor(String name, String sqlQuery) { 13 | this.name = name; 14 | this.sqlQuery = sqlQuery; 15 | } 16 | 17 | public Integer getId() { 18 | return id; 19 | } 20 | 21 | public void setId(Integer id) { 22 | this.id = id; 23 | } 24 | 25 | public String getName() { 26 | return name; 27 | } 28 | 29 | public void setName(String name) { 30 | this.name = name; 31 | } 32 | 33 | public String getSqlQuery() { 34 | return sqlQuery; 35 | } 36 | 37 | public void setSqlQuery(String sqlQuery) { 38 | this.sqlQuery = sqlQuery; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /spring-quartz/src/main/java/com/bahadirakin/SchedulerController.java: -------------------------------------------------------------------------------- 1 | package com.bahadirakin; 2 | 3 | import org.quartz.JobDataMap; 4 | import org.quartz.Scheduler; 5 | import org.quartz.SchedulerException; 6 | import org.quartz.impl.JobDetailImpl; 7 | import org.quartz.impl.triggers.CronTriggerImpl; 8 | import org.springframework.beans.factory.annotation.Autowired; 9 | import org.springframework.stereotype.Component; 10 | 11 | import java.text.ParseException; 12 | 13 | @Component 14 | public class SchedulerController { 15 | 16 | @Autowired 17 | Scheduler scheduler; 18 | 19 | public void addJob(DatabaseMonitor databaseMonitor) { 20 | 21 | final JobDataMap jobDataMap = new JobDataMap(); 22 | jobDataMap.put("sqlQuery", databaseMonitor.getSqlQuery()); 23 | final JobDetailImpl jobDetail = new JobDetailImpl(); 24 | jobDetail.setName(databaseMonitor.getName()); 25 | jobDetail.setDurability(true); 26 | jobDetail.setJobDataMap(jobDataMap); 27 | jobDetail.setJobClass(DatabaseJob.class); 28 | 29 | try { 30 | final CronTriggerImpl trigger = new CronTriggerImpl(); 31 | trigger.setCronExpression("0/2 * * * * ?"); 32 | trigger.setName(databaseMonitor.getName()); 33 | scheduler.scheduleJob(jobDetail, trigger); 34 | } catch (ParseException | SchedulerException e) { 35 | e.printStackTrace(); 36 | } 37 | } 38 | } 39 | 40 | -------------------------------------------------------------------------------- /spring-rabbitmq/Vagrantfile: -------------------------------------------------------------------------------- 1 | 2 | Vagrant.configure(2) do |config| 3 | config.vm.box = "ubuntu/trusty64" 4 | config.vm.network "private_network", ip: "192.168.33.10" 5 | config.vm.provision "shell", inline: <<-SHELL 6 | echo 'deb http://www.rabbitmq.com/debian/ testing main' >/etc/apt/sources.list.d/rabbitmq.list 7 | wget http://www.rabbitmq.com/rabbitmq-signing-key-public.asc 8 | apt-key add rabbitmq-signing-key-public.asc 9 | apt-get update 10 | 11 | apt-get install -q -y rabbitmq-server 12 | 13 | # RabbitMQ Plugins 14 | service rabbitmq-server stop 15 | rabbitmq-plugins enable rabbitmq_management 16 | SHELL 17 | config.vm.provision "file", source:"./rabbitmq.config", destination:"~/rabbitmq.config" 18 | config.vm.provision "shell", inline: <<-SHELL 19 | cp /home/vagrant/rabbitmq.config /etc/rabbitmq/rabbitmq.config 20 | # Start service 21 | service rabbitmq-server start 22 | rabbitmq-plugins list 23 | SHELL 24 | end 25 | -------------------------------------------------------------------------------- /spring-rabbitmq/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | com.bahadirakin.amqp 7 | spring-rabbitmq 8 | 0.0.1-SNAPSHOT 9 | jar 10 | 11 | spring-rabbitmq 12 | Demo project for Spring amqp 13 | 14 | 15 | org.springframework.boot 16 | spring-boot-starter-parent 17 | 1.2.4.RELEASE 18 | 19 | 20 | 21 | 22 | 23 | UTF-8 24 | 1.8 25 | 26 | 27 | 28 | 29 | org.springframework.boot 30 | spring-boot-starter-amqp 31 | 32 | 33 | 34 | org.springframework.boot 35 | spring-boot-starter-test 36 | test 37 | 38 | 39 | 40 | 41 | 42 | 43 | org.springframework.boot 44 | spring-boot-maven-plugin 45 | 46 | 47 | 48 | 49 | 50 | -------------------------------------------------------------------------------- /spring-rabbitmq/rabbitmq.config: -------------------------------------------------------------------------------- 1 | %% -*- mode: erlang -*- 2 | [ 3 | {rabbit, 4 | [ 5 | {tcp_listeners, [5672]}, 6 | {log_levels, [{connection, info}, {channel, info}]}, 7 | {loopback_users, []}, 8 | {auth_mechanisms, ['PLAIN', 'AMQPLAIN']}, 9 | {default_vhost, <<"/">>}, 10 | {default_user, <<"guest">>}, 11 | {default_pass, <<"guest">>}, 12 | {default_permissions, [<<".*">>, <<".*">>, <<".*">>]}, 13 | {default_user_tags, [administrator]} 14 | ]} 15 | ]. 16 | -------------------------------------------------------------------------------- /spring-rabbitmq/src/main/java/com/bahadirakin/amqp/consumer/HelloMessageConsumer.java: -------------------------------------------------------------------------------- 1 | package com.bahadirakin.amqp.consumer; 2 | 3 | import com.bahadirakin.amqp.message.HelloMessage; 4 | import org.slf4j.Logger; 5 | import org.slf4j.LoggerFactory; 6 | 7 | public class HelloMessageConsumer { 8 | 9 | private static final Logger logger = LoggerFactory.getLogger(HelloMessageConsumer.class); 10 | 11 | public void onHelloMessage(final HelloMessage message) { 12 | logger.info("{} from {}", message.getMessage(), message.getFrom()); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /spring-rabbitmq/src/main/java/com/bahadirakin/amqp/message/HelloMessage.java: -------------------------------------------------------------------------------- 1 | package com.bahadirakin.amqp.message; 2 | 3 | import java.io.Serializable; 4 | 5 | public class HelloMessage implements Serializable { 6 | 7 | private String message; 8 | private String from; 9 | 10 | public String getMessage() { 11 | return message; 12 | } 13 | 14 | public void setMessage(String message) { 15 | this.message = message; 16 | } 17 | 18 | public String getFrom() { 19 | return from; 20 | } 21 | 22 | public void setFrom(String from) { 23 | this.from = from; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /spring-rabbitmq/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | spring.rabbitmq.host=192.168.33.10 2 | spring.rabbitmq.port=5672 3 | spring.rabbitmq.username=guest 4 | spring.rabbitmq.password=guest -------------------------------------------------------------------------------- /spring-rabbitmq/src/test/java/com/bahadirakin/amqp/SpringRabbitmqApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.bahadirakin.amqp; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.SpringApplicationConfiguration; 6 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 7 | 8 | @RunWith(SpringJUnit4ClassRunner.class) 9 | @SpringApplicationConfiguration(classes = SpringRabbitmqApplication.class) 10 | public class SpringRabbitmqApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /spring-redis/Vagrantfile: -------------------------------------------------------------------------------- 1 | # -*- mode: ruby -*- 2 | # vi: set ft=ruby ts=2 sw=2 expandtab: 3 | 4 | Vagrant.configure(2) do |config| 5 | config.vm.box = "ubuntu/trusty64" 6 | config.vm.network "private_network", ip: "192.168.33.10" 7 | config.vm.provision "shell", inline: <<-SHELL 8 | apt-get update 9 | apt-get install build-essential 10 | apt-get install tcl8.5 11 | 12 | wget http://download.redis.io/releases/redis-stable.tar.gz 13 | tar xzf redis-stable.tar.gz 14 | cd redis-stable 15 | make 16 | make test 17 | make install 18 | cd utils 19 | ./install_server.sh 20 | 21 | update-rc.d redis_6379 defaults 22 | SHELL 23 | end 24 | -------------------------------------------------------------------------------- /spring-redis/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | com.bahadirakin 7 | spring-redis 8 | 0.0.1-SNAPSHOT 9 | jar 10 | 11 | spring-redis 12 | Demo project for Redis 13 | 14 | 15 | org.springframework.boot 16 | spring-boot-starter-parent 17 | 1.2.5.RELEASE 18 | 19 | 20 | 21 | 22 | UTF-8 23 | 1.8 24 | 25 | 26 | 27 | 28 | org.springframework.boot 29 | spring-boot-starter-redis 30 | 31 | 32 | 33 | org.springframework.boot 34 | spring-boot-starter-test 35 | test 36 | 37 | 38 | 39 | 40 | 41 | 42 | org.springframework.boot 43 | spring-boot-maven-plugin 44 | 45 | 46 | 47 | 48 | 49 | -------------------------------------------------------------------------------- /spring-redis/src/main/java/com/bahadirakin/redis/SomeLongBusiness.java: -------------------------------------------------------------------------------- 1 | package com.bahadirakin.redis; 2 | 3 | public interface SomeLongBusiness { 4 | 5 | String doSomeHeavyWork(String input); 6 | } 7 | -------------------------------------------------------------------------------- /spring-redis/src/main/java/com/bahadirakin/redis/SomeLongBusinessImpl.java: -------------------------------------------------------------------------------- 1 | package com.bahadirakin.redis; 2 | 3 | import org.springframework.cache.annotation.Cacheable; 4 | 5 | public class SomeLongBusinessImpl implements SomeLongBusiness { 6 | 7 | @Cacheable(value = "resultCache2") 8 | @Override 9 | public String doSomeHeavyWork(String input) { 10 | try { 11 | Thread.sleep(5000); 12 | return "Result: " + input; 13 | } catch (InterruptedException e) { 14 | throw new RuntimeException(e); 15 | } 16 | 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /spring-redis/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | spring.redis.host=192.168.33.10 2 | spring.redis.port=6379 -------------------------------------------------------------------------------- /spring-redis/src/test/java/com/bahadirakin/redis/SpringRedisApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.bahadirakin.redis; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.SpringApplicationConfiguration; 6 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 7 | 8 | @RunWith(SpringJUnit4ClassRunner.class) 9 | @SpringApplicationConfiguration(classes = SpringRedisApplication.class) 10 | public class SpringRedisApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /test-with-mockito/.gitignore: -------------------------------------------------------------------------------- 1 | 2 | # Eclipse # 3 | ########### 4 | .classpath 5 | /.settings 6 | .project 7 | /target 8 | 9 | # Intellij 10 | .idea/ 11 | *.iml 12 | *.iws 13 | 14 | # Compiled source # 15 | ################### 16 | *.com 17 | *.class 18 | *.dll 19 | *.exe 20 | *.o 21 | *.so 22 | 23 | # Packages # 24 | ############ 25 | # it's better to unpack these files and commit the raw source 26 | # git has its own built in compression methods 27 | *.7z 28 | *.dmg 29 | *.gz 30 | *.iso 31 | *.jar 32 | *.rar 33 | *.tar 34 | *.zip 35 | 36 | # Logs and databases # 37 | ###################### 38 | *.log 39 | *.sql 40 | *.sqlite 41 | 42 | # OS generated files # 43 | ###################### 44 | .DS_Store 45 | .DS_Store? 46 | ._* 47 | .Spotlight-V100 48 | .Trashes 49 | ehthumbs.db 50 | Thumbs.db 51 | 52 | -------------------------------------------------------------------------------- /test-with-mockito/src/main/java/com/bahadirakin/controllers/LoginController.java: -------------------------------------------------------------------------------- 1 | package com.bahadirakin.controllers; 2 | 3 | import com.bahadirakin.entities.User; 4 | import com.bahadirakin.exceptions.UserNotFoundException; 5 | import com.bahadirakin.services.IUserService; 6 | import org.slf4j.Logger; 7 | import org.slf4j.LoggerFactory; 8 | 9 | import java.io.Serializable; 10 | 11 | /** 12 | * Created by bhdrkn on 08/11/14. 13 | */ 14 | public class LoginController implements Serializable { 15 | 16 | private static final Logger logger = LoggerFactory.getLogger(LoginController.class); 17 | 18 | private IUserService userService; 19 | 20 | public LoginController(IUserService userService) { 21 | this.userService = userService; 22 | } 23 | 24 | public String authenticate(final User user) { 25 | 26 | try { 27 | if (userService.authenticate(user)) { 28 | return "homePage"; 29 | } else { 30 | return "errorPage?message=wrongPassword"; 31 | } 32 | } catch (UserNotFoundException e) { 33 | logger.error("User not found for usernmae: {}", user.getUsername(), e); 34 | return "errorPage?message=userNotFound"; 35 | } 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /test-with-mockito/src/main/java/com/bahadirakin/entities/User.java: -------------------------------------------------------------------------------- 1 | package com.bahadirakin.entities; 2 | 3 | /** 4 | * Created by bhdrkn on 08/11/14. 5 | */ 6 | public class User { 7 | 8 | private Long id; 9 | 10 | private String username; 11 | 12 | private String password; 13 | 14 | public Long getId() { 15 | return id; 16 | } 17 | 18 | public void setId(Long id) { 19 | this.id = id; 20 | } 21 | 22 | public String getUsername() { 23 | return username; 24 | } 25 | 26 | public void setUsername(String username) { 27 | this.username = username; 28 | } 29 | 30 | public String getPassword() { 31 | return password; 32 | } 33 | 34 | public void setPassword(String password) { 35 | this.password = password; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /test-with-mockito/src/main/java/com/bahadirakin/exceptions/UserNotFoundException.java: -------------------------------------------------------------------------------- 1 | package com.bahadirakin.exceptions; 2 | 3 | /** 4 | * Created by bhdrkn on 08/11/14. 5 | */ 6 | public class UserNotFoundException extends Exception { 7 | 8 | public UserNotFoundException() { 9 | } 10 | 11 | public UserNotFoundException(String message) { 12 | super(message); 13 | } 14 | 15 | public UserNotFoundException(String message, Throwable cause) { 16 | super(message, cause); 17 | } 18 | 19 | public UserNotFoundException(Throwable cause) { 20 | super(cause); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /test-with-mockito/src/main/java/com/bahadirakin/services/IUserService.java: -------------------------------------------------------------------------------- 1 | package com.bahadirakin.services; 2 | 3 | import com.bahadirakin.entities.User; 4 | import com.bahadirakin.exceptions.UserNotFoundException; 5 | 6 | /** 7 | * Created by bhdrkn on 08/11/14. 8 | */ 9 | public interface IUserService { 10 | 11 | boolean authenticate(final User user) throws UserNotFoundException; 12 | 13 | } 14 | -------------------------------------------------------------------------------- /user-application/Procfile: -------------------------------------------------------------------------------- 1 | web: java $JAVA_OPTS -jar target/dependency/jetty-runner.jar --port $PORT target/*.war 2 | -------------------------------------------------------------------------------- /user-application/src/main/java/com/bahadirakin/dao/UserRepository.java: -------------------------------------------------------------------------------- 1 | package com.bahadirakin.dao; 2 | 3 | import com.bahadirakin.model.User; 4 | import org.springframework.data.mongodb.repository.MongoRepository; 5 | 6 | /** 7 | * Created by bhdrkn on 08/02/15. 8 | */ 9 | public interface UserRepository extends MongoRepository { 10 | 11 | User findByEmail(final String email); 12 | User findByUsernameAndPassword(final String username, final String password); 13 | } 14 | -------------------------------------------------------------------------------- /user-application/src/main/java/com/bahadirakin/model/User.java: -------------------------------------------------------------------------------- 1 | package com.bahadirakin.model; 2 | 3 | import org.springframework.data.annotation.Id; 4 | import org.springframework.data.mongodb.core.index.Indexed; 5 | import org.springframework.data.mongodb.core.mapping.Document; 6 | 7 | import java.io.Serializable; 8 | 9 | /** 10 | * Created by bhdrkn on 08/02/15. 11 | */ 12 | @Document(collection = "user") 13 | public class User implements Serializable { 14 | 15 | @Id 16 | private String id; 17 | @Indexed(unique = true) 18 | private String username; 19 | @Indexed(unique = true) 20 | private String email; 21 | private String password; 22 | 23 | public String getId() { 24 | return id; 25 | } 26 | 27 | public void setId(String id) { 28 | this.id = id; 29 | } 30 | 31 | public String getUsername() { 32 | return username; 33 | } 34 | 35 | public void setUsername(String username) { 36 | this.username = username; 37 | } 38 | 39 | public String getEmail() { 40 | return email; 41 | } 42 | 43 | public void setEmail(String email) { 44 | this.email = email; 45 | } 46 | 47 | public String getPassword() { 48 | return password; 49 | } 50 | 51 | public void setPassword(String password) { 52 | this.password = password; 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /user-application/src/main/java/com/bahadirakin/service/UserService.java: -------------------------------------------------------------------------------- 1 | package com.bahadirakin.service; 2 | 3 | import com.bahadirakin.model.User; 4 | 5 | import java.util.List; 6 | 7 | /** 8 | * Created by bhdrkn on 08/02/15. 9 | */ 10 | public interface UserService { 11 | 12 | User createUser(final User user); 13 | 14 | User updateUser(String id, final User user); 15 | 16 | User deleteUser(String id, final User user); 17 | 18 | User findUserById(final String id); 19 | 20 | List getAllUsers(); 21 | 22 | User authenticate(final String username, final String password); 23 | 24 | void sendForgottenUsernameAndPasswordEmail(final String email); 25 | } 26 | -------------------------------------------------------------------------------- /user-application/src/main/java/com/bahadirakin/service/UserServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.bahadirakin.service; 2 | 3 | import com.bahadirakin.dao.UserRepository; 4 | import com.bahadirakin.model.User; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.stereotype.Service; 7 | 8 | import java.util.List; 9 | 10 | /** 11 | * Created by bhdrkn on 08/02/15. 12 | */ 13 | @Service 14 | public class UserServiceImpl implements UserService { 15 | 16 | private final UserRepository userRepository; 17 | 18 | @Autowired 19 | public UserServiceImpl(UserRepository userRepository) { 20 | this.userRepository = userRepository; 21 | } 22 | 23 | @Override 24 | public User createUser(User user) { 25 | return userRepository.save(user); 26 | } 27 | 28 | @Override 29 | public User updateUser(String id, User user) { 30 | final User dbUser = userRepository.findOne(id); 31 | dbUser.setUsername(user.getUsername()); 32 | dbUser.setPassword(user.getPassword()); 33 | dbUser.setEmail(user.getEmail()); 34 | return userRepository.save(dbUser); 35 | } 36 | 37 | @Override 38 | public User deleteUser(String id, User user) { 39 | final User dbuser = this.authenticate(user.getUsername(), user.getPassword()); 40 | if(dbuser== null || dbuser.getId().equals(id) == false){ 41 | throw new RuntimeException("Wrong User"); 42 | } 43 | userRepository.delete(user.getId()); 44 | return user; 45 | } 46 | 47 | @Override 48 | public User findUserById(String id) { 49 | return userRepository.findOne(id); 50 | } 51 | 52 | @Override 53 | public List getAllUsers() { 54 | return userRepository.findAll(); 55 | } 56 | 57 | @Override 58 | public User authenticate(String username, String password) { 59 | return userRepository.findByUsernameAndPassword(username, password); 60 | } 61 | 62 | @Override 63 | public void sendForgottenUsernameAndPasswordEmail(String email) { 64 | final User user = userRepository.findByEmail(email); 65 | // Sends email etc. 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /user-application/src/main/resources/applicationContext.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /user-application/src/main/resources/mongodb.properties: -------------------------------------------------------------------------------- 1 | mongodb.hostaddress=ds031601.mongolab.com 2 | mongodb.port=31601 3 | mongodb.database=heroku_app33810136 4 | mongodb.username= 5 | mongodb.password= 6 | 7 | -------------------------------------------------------------------------------- /user-application/src/main/resources/springDataContext.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 15 | 16 | 19 | 20 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /user-application/src/main/webapp/WEB-INF/web.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | user-application 7 | 8 | 9 | contextConfigLocation 10 | classpath*:applicationContext.xml 11 | 12 | 13 | 14 | org.springframework.web.context.ContextLoaderListener 15 | 16 | 17 | 18 | mvc-servlet 19 | org.springframework.web.servlet.DispatcherServlet 20 | 21 | contextConfigLocation 22 | classpath*:applicationContext.xml 23 | 24 | 1 25 | 26 | 27 | 28 | mvc-servlet 29 | / 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /user-application/src/main/webapp/index.jsp: -------------------------------------------------------------------------------- 1 | 2 | 3 |

Hello World!

4 | 5 | 6 | -------------------------------------------------------------------------------- /user-application/src/test/java/com/bahadirakin/dao/UserRepositoryTest.java: -------------------------------------------------------------------------------- 1 | package com.bahadirakin.dao; 2 | 3 | import com.bahadirakin.dao.UserRepository; 4 | import com.bahadirakin.model.User; 5 | import org.junit.Assert; 6 | import org.junit.Before; 7 | import org.junit.BeforeClass; 8 | import org.junit.Test; 9 | import org.junit.runner.RunWith; 10 | import org.springframework.beans.factory.annotation.Autowired; 11 | import org.springframework.test.context.ContextConfiguration; 12 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 13 | 14 | 15 | /** 16 | * Created by bhdrkn on 08/02/15. 17 | */ 18 | @RunWith(SpringJUnit4ClassRunner.class) 19 | @ContextConfiguration(value = {"classpath*:springDataContext-test.xml"}) 20 | public class UserRepositoryTest { 21 | 22 | @Autowired 23 | UserRepository userRepository; 24 | 25 | static User user; 26 | 27 | @Before 28 | public void init() { 29 | if(user != null){ 30 | return; 31 | } 32 | user = new User(); 33 | user.setUsername("bhdrkn"); 34 | user.setEmail("bhdrkn@gmail.com"); 35 | user.setPassword("1q2w3e"); 36 | user = userRepository.save(user); 37 | } 38 | 39 | 40 | @Test 41 | public void testFindByUsernameAndPassword() { 42 | final User user = userRepository.findByUsernameAndPassword("bhdrkn", "1q2w3e"); 43 | Assert.assertNotNull(user); 44 | } 45 | 46 | @Test 47 | public void testNotFindByUsernameAndPassword() { 48 | final User user = userRepository.findByUsernameAndPassword("bhdrkn", "1"); 49 | Assert.assertNull(user); 50 | } 51 | 52 | @Test 53 | public void testFindByEmail(){ 54 | final User user = userRepository.findByEmail("bhdrkn@gmail.com"); 55 | Assert.assertNotNull(user); 56 | } 57 | 58 | @Test 59 | public void testNotFindByEmail(){ 60 | final User user = userRepository.findByEmail("asd"); 61 | Assert.assertNull(user); 62 | } 63 | 64 | } 65 | -------------------------------------------------------------------------------- /user-application/src/test/java/com/bahadirakin/service/UserServiceTest.java: -------------------------------------------------------------------------------- 1 | package com.bahadirakin.service; 2 | 3 | import com.bahadirakin.dao.UserRepository; 4 | import com.bahadirakin.model.User; 5 | import org.junit.Assert; 6 | import org.junit.Before; 7 | import org.junit.Test; 8 | import org.junit.runner.RunWith; 9 | import org.junit.runners.JUnit4; 10 | import org.mockito.InjectMocks; 11 | import org.mockito.Mock; 12 | import org.mockito.Mockito; 13 | import org.mockito.MockitoAnnotations; 14 | 15 | /** 16 | * Created by bhdrkn on 08/02/15. 17 | */ 18 | @RunWith(JUnit4.class) 19 | public class UserServiceTest { 20 | 21 | @Mock 22 | private UserRepository userRepository; 23 | 24 | private UserService userService; 25 | 26 | @Before 27 | public void init(){ 28 | MockitoAnnotations.initMocks(this); 29 | userService = new UserServiceImpl(userRepository); 30 | } 31 | 32 | @Test 33 | public void testAuthentication(){ 34 | final String username = "bhdrkn"; 35 | final String password = "1q2w3e"; 36 | 37 | final User mockUser = new User(); 38 | mockUser.setId("1"); 39 | mockUser.setUsername(username); 40 | mockUser.setPassword(password); 41 | mockUser.setEmail("bhdrkn@gmail.com"); 42 | 43 | Mockito.when(userRepository.findByUsernameAndPassword(username,password)).thenReturn(mockUser); 44 | 45 | final User user = userService.authenticate(username, password); 46 | Assert.assertNotNull(user); 47 | } 48 | 49 | @Test 50 | public void testUnsuccessfulAuthentication(){ 51 | final String username = "bhdrkn"; 52 | final String password = "1q2w3e"; 53 | 54 | Mockito.when(userRepository.findByUsernameAndPassword(username,password)).thenReturn(null); 55 | 56 | final User user = userService.authenticate(username, password); 57 | Assert.assertNull(user); 58 | } 59 | 60 | } 61 | -------------------------------------------------------------------------------- /user-application/src/test/resources/springDataContext-test.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | --------------------------------------------------------------------------------