Thursday, December 5, 2019

Windows Subsystem For Linux 2 (WS-2) Enable SSH

In order to enable ssh on your WSL 2 system (using distro Ubuntu 18.04 ) you need to following configurations:

Open the WSL2, and edit folowing file "/etc/ssh/sshd_config"


and set following:

"Port" 2222
"ListenAddress" 0.0.0.0
"PasswordAuthentication"  "yes"





Save the changes. And then run below command to generate your ssh keys.

sudo ssh-keygen -A

finally restart sshd service using following command,

"sudo service ssh --full-restart"


After that you are all set to go :)

Monday, February 13, 2017

Creating a Test Template in IntelliJ Idea


Here is a quick guide for a test template in intellij. Almost all of the time i am using maven for the java projects i work on and junit and assertj is my primary testing tools. Every time i create test classes i am typing the static includes and a test method annotated with test. Although it's not that much boiler plate this can be prevented thanks to intellij file templates.

We want a test class to be generated automatically for that we are going to create a file template with name "JavaTest" (you can pick any name you want). Here is a quick step by step guide for that:

1. Create a file that contains the things that you want to be part of the template as a java file. (For this case i want junit and assertj static imports to be present along with junit import and a test method annotated with @Test)



2. Select Tools -> Save File As Template from the top menu. This will bring up the Save File As Template Dialog. Give the name "JavaTest" and save the template. (you can change the template as you please)



3.  Right Click to the package you want to create a unit test. From the New menu find the name "JavaTest" and create the file... Voila there you have your tiny little cute test file ready to use :)

As a long term Netbeans user, i find intelliJ easier and faster to use but still from the bottom of my heart i am waiting for Netbeans to make a come back ...





Thursday, November 3, 2016

Maven Snippets

I find maven documentation cryptic to read and hard to understand, even after years of development this aspect of Maven still remains same to me, most of the time i copy snippets from older projects to get things done, Below you can find some common snippets you might need to use time to time in your projects.


1. Deploying Arbitrary Artifact to Nexus

You need to have configured username and password of your nexus server in your settings.xml file for this snippet to work, it uploads the zip artifact to nexus repository.

settings.xml (located in .m2 directory)

<servers>
    <server>
       <id>nexus</id>
       <username>username</username>
       <password>pass</password>
    </server>

  </servers>

Pom.xml

<!-- Deploy File -->
<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-deploy-plugin</artifactId>
    <version>2.8.2</version>
    <executions>
        <execution>
            <phase>package</phase>
            <configuration>
                <artifactId>${project.artifactId}</artifactId>
                <groupId>${project.groupId}</groupId>
                <version>${project.version}</version>
                <packaging>zip</packaging>
                <file>target/application-1.0-SNAPSHOT.zip</file>
                <repositoryId>nexus</repositoryId>
                <url>http://xxx.yyy.zz.tt:8081/nexus/content/repositories/snapshots/</url>
            </configuration>
            <goals>
                <goal>deploy-file</goal>
            </goals>
        </execution>
    </executions>
</plugin>

Sunday, November 1, 2015

Configuring CouchDB uuid generation algorithm

CouchDB can generate _id field of documents for you when you store the documents using POST instead of PUT. The algorithm used by CouchDB to generate the _id fields can be changed although the options are small. We can pick below algorithms for couch db to use to generate the _id fields of our documents: (http://wiki.apache.org/couchdb/HttpGetUuids)


  1. sequential: 26 hex character random prefix, followed by 6 hex characters of sequence, which is incremented by random amounts. When the 6 character sequence overflows, a new random prefix is chosen. There are no guarantees of ordering, but most inserted documents will be sequentially ordered. This improves insert speed as most B-tree edits do not happen randomly. Also, if the documents are likely to be accessed sequentially, this improves access speeds.
  2. random: 32 hex characters generated completely at random.
  3. utc_random: First 14 hex characters are microseconds since Jan 1, 1970 (Unix epoch), followed by 18 random hex characters.
To Update the setting ew can use REST api of the couchDB, 

[rozaydin@RO ~]$ curl -X PUT http://localhost:5984/_config/uuids/algorithm -d '"sequential"'
"sequential"
[rozaydin@RO ~]$

As you can see CouchDB responds with the old algorithm it was using to generate the _id fields prior the update. The same configuration should be able to be done using local.ini file however i failed to find the proper name for the setting if you know how please leave a comment :)

Monday, September 7, 2015

Configuring Jetty Server With Security Certificates

  • Download Jetty 9.3.2 version from http://download.eclipse.org/jetty/ and unzip to a directory (This directory will be called Jetty Home)
  • go into Jetty Home directory and create a new directory inside this directory with name SECURE_BASE (This directory will be called Jetty Base)
  • go into Jetty Base directory and create a new file with name start.ini
  • open start.ini with a text editor and edit it to include below lines
# Initialize module server
--module=server
threads.min=10
threads.max=200
threads.timeout=60000
jetty.dump.start=false
jetty.sump.stop=false
--module=deploy
--module=jsp
--module=ext
--module=resources
--module=client
--module=annotations
--module=http
--module=ssl
--module=https
save and exit.
  • Execute below command in Jetty Base directory
java -jar ../start.jar
then terminate the process via issuing kill -9 pid command
  • create a new directory in Jetty Base directory with name etc.
In the end you should have following directory structure in your Jetty Base directory. (secure-base is Jetty Base in below example)
[rozaydin@RO secure-base]$ pwd
/home/rozaydin/WDH/jetty-9.3.2/secure-base
[rozaydin@RO secure-base]$ ls
etc lib resources start.ini webapps
[rozaydin@RO secure-base]$

2 Create SSL Certificate

Create an SSL certificate by issuing below command please ensure you note the password, this file will be used at https negotiation with the client.
$ keytool -keystore keystore -alias keystore -genkey -keyalg RSA -sigalg SHA256withRSA
 Enter keystore password:  password
 What is your first and last name?
   [Unknown]:  Test Test
 What is the name of your organizational unit?
   [Unknown]:  Software Development
 What is the name of your organization?
   [Unknown]:  Test Test
 What is the name of your City or Locality?
   [Unknown]: Istanbul
 What is the name of your State or Province?
   [Unknown]: Istanbul
 What is the two-letter country code for this unit?
   [Unknown]: TR
 Is CN=
Test Test, OU=Software Development, O=Test Test,
 L=Istanbul, ST=Istanbul, C=TR correct?
   [no]:  yes

 Enter key password for <keystore>
         (RETURN if same as keystore password):
 $

After the execution you should have a file with name keystore at the directory you have issued the command.

2 Configure HTTPS on Jetty

  1. Copy the SSL certificate file (keystore file) you have created in previous step to Jetty Base/etc directory

  2. Https configuration is determined by 4 configuration files located under Jetty Home/etc directory these files are
  • jetty.xml
  • jetty-https.xml
  • jetty-ssl.xml
  • jetty-ssl-context.xml
Open the jetty-ssl-context.xml file and modify below lines accordingly

jetty-ssl-context.xml

<?xml version="1.0"?>
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure_9_3.dtd">
<!-- ============================================================= -->
<!-- SSL ContextFactory configuration -->
<!-- ============================================================= -->
<Configure id="sslContextFactory" class="org.eclipse.jetty.util.ssl.SslContextFactory">
<Set name="KeyStorePath"><Property name="jetty.base" default="." />/<Property name="jetty.sslContext.keyStorePath" deprecated="jetty.keystore" default="etc/keystore"/></Set>
<Set name="KeyStorePassword"><Property name="jetty.sslContext.keyStorePassword" deprecated="jetty.keystore.password" default="test"/></Set>
<Set name="KeyStoreType"><Property name="jetty.sslContext.keyStoreType" default="JKS"/></Set>
<Set name="KeyStoreProvider"><Property name="jetty.sslContext.keyStoreProvider"/></Set>
<Set name="KeyManagerPassword"><Property name="jetty.sslContext.keyManagerPassword" deprecated="jetty.keymanager.password" default="test"/></Set>
<Set name="TrustStorePath"><Property name="jetty.base" default="." />/<Property name="jetty.sslContext.trustStorePath" deprecated="jetty.truststore" default="etc/keystore"/></Set>
<Set name="TrustStorePassword"><Property name="jetty.sslContext.trustStorePassword" deprecated="jetty.truststore.password" default="test"/></Set>
<Set name="TrustStoreType"><Property name="jetty.sslContext.trustStoreType" default="JKS"/></Set>
<Set name="TrustStoreProvider"><Property name="jetty.sslContext.trustStoreProvider"/></Set>
<Set name="EndpointIdentificationAlgorithm"></Set>
<Set name="NeedClientAuth"><Property name="jetty.sslContext.needClientAuth" deprecated="jetty.ssl.needClientAuth" default="false"/></Set>
<Set name="WantClientAuth"><Property name="jetty.sslContext.wantClientAuth" deprecated="jetty.ssl.wantClientAuth" default="false"/></Set>
<Set name="ExcludeCipherSuites">
<Array type="String">
<Item>SSL_RSA_WITH_DES_CBC_SHA</Item>
<Item>SSL_DHE_RSA_WITH_DES_CBC_SHA</Item>
<Item>SSL_DHE_DSS_WITH_DES_CBC_SHA</Item>
<Item>SSL_RSA_EXPORT_WITH_RC4_40_MD5</Item>
<Item>SSL_RSA_EXPORT_WITH_DES40_CBC_SHA</Item>
<Item>SSL_DHE_RSA_EXPORT_WITH_DES40_CBC_SHA</Item>
<Item>SSL_DHE_DSS_EXPORT_WITH_DES40_CBC_SHA</Item>
</Array>
</Set>
<Set name="useCipherSuitesOrder"><Property name="jetty.sslContext.useCipherSuitesOrder" default="true"/></Set>
</Configure>

Here we are setting the password by changing 3 properties listed below, password must be the same as the password that is set to the Certificate file.
<Set name="KeyStorePassword"><Property name="jetty.sslContext.keyStorePassword" deprecated="jetty.keystore.password" default="test"/></Set>
<Set name="KeyManagerPassword"><Property name="jetty.sslContext.keyManagerPassword" deprecated="jetty.keymanager.password" default="test"/></Set>
<Set name="TrustStorePassword"><Property name="jetty.sslContext.trustStorePassword" deprecated="jetty.truststore.password" default="test"/></Set>

4 Run Jetty Server 

After following previous configuration steps, start jetty server by going into Jetty Base directory and issuing command
java -jar ../start.jar
you can access the server using https protocol by using default url https://localhost:8443

Friday, June 12, 2015

Working offline with Maven

While working with projects managed by maven you could run into issues where you have to disconnect your development environment from the internet and continue to work on the code. The experience i had was i had to debug a system deployed to a customer network which had no internet access. I suddenly realized my development environment on my laptop was completely useless. Pretty bad when there are people standing behind you and waiting for you to resolve their problem.

The solution is downloading the maven dependencies to your local by executing below command from the same directory where your pom file is located.

[rozaydin@RO]$ mvn dependency:go-offline

Maven will download all dependencies your project needs and you could be able to continue working with no need to internet access.

Saturday, June 6, 2015

Ucuz Elektrik


Türkiye'de elektrik tarifeleri 3 zamanlı olarak ücretlendirilmekteler. Bu zaman (tarife) dilimleri aşağıda listelenmiştir.

Gündüz (T1)      : 06:00 – 17:00
Puant (T2)          : 17:00 – 22:00
Gece (T3)           : 22:00 – 06:00

En ucuz elektrik 22.00 - 06.00 arasında satılırken en pahalı elektril 17.00 - 22.00 saatleri arasında satılmakta. Hali hazırda geçerli olan ücret tarifelerine göre "Mesken" tipi abonelerin tarifeleri aşağıda listelenmiştir. 


Mesken:

Gündüz: 19,7183
Puant:     35,8753 
Gece:      8,0527 

Görüldüğü gibi en ucuz zaman dilimi GECE tarifesi olmaktadır. Eğer enerji tüketimimizin tamamını gece tarifesi üzerinden yaparsak harcadığımız aynı enerji miktarı için 3 kat daha az ödüyoruz. Basit bir örnek verir ise ortalama enerji faturamız aylık 60 lira ise ödeyeceğimiz rakam 20 liraya düşüyor. 1 sene içerisinde yapacağımız tasarruf miktarı 40 x 12 = 480 lira. Az bir rakam değil. 

Peki enerji tüketimimizin tamamını GECE tarifesi üzerinden yapmak mümkün mü ? Eğer enerjiyi depolayabilir isek evet mümkün. Büyükçe şarj edilebilir bir pilimiz olduğunu düşünün, Tarifenin en ucuz olduğu zaman diliminde kendi kendisini otomatik şarj ediyor ve diğer zaman dilimlerinde ise bu pildeki enerjiyi evimizde kullanıyoruz harcadığımız elektrik miktarını kısmadan ciddi miktarda tasarruf sağladık.

İşte bu şekilde şarj edilebilir bir pil artık var. Elektrikli araçları ile ünlü Amerikan "Tesla" şirketi Power Wall adlı ürün ile karşımızda. Power Wall evinizin duvarına monte ettirebileceğiniz oldukça şık bir ürün. Ancak ürünün fiyatı biraz yüksek 3000$ ve 3500$ fiyat etiketine sahip ki Türkiye standartları için bu ciddi bir rakam. Ancak bu ürünlerin muadilleri daha uygun fiyat etiketi ile çok kısa sürede pazara sürülecektir. Bu durumda daha satın alınabilir bir etiket ile elektrik faturalarımızı ciddi miktarda düşürebilir olacağız.

Monday, May 11, 2015

Latitude Longitude Boundaries on World Map


You might have encountered situations where you wanted to get the latitude and longitude boundaries of an rectangular area on world map, I have put together a simple js application using leaflet js and leaflet.draw plugin to provide the functionality.

  1. You can access the hosted application from here. 
  2. You can access the sources from here. 
Enjoy and please comment if you encounter any issues.


Figure 1 - Boundary Application



Wednesday, May 6, 2015

How to kill multiple processes from terminal with single line

You might encounter situations where you need to kill group of processes, such as when google-chrome is running. Chrome spawns multiple processes and you might want to shut it down from terminal.

[rozaydin@RO ~]$ ps -e | grep chrome
 5017 ?        00:00:01 chrome
 5027 ?        00:00:00 chrome-sandbox
 5028 ?        00:00:00 chrome
 5033 ?        00:00:00 chrome-sandbox
 5036 ?        00:00:00 chrome
 5055 ?        00:00:00 chrome
 5083 ?        00:00:00 chrome
 5091 ?        00:00:00 chrome
 5107 ?        00:00:00 chrome
 5111 ?        00:00:00 chrome
 5115 ?        00:00:00 chrome
 5123 ?        00:00:00 chrome
 5131 ?        00:00:00 chrome
 5139 ?        00:00:00 chrome
 5142 ?        00:00:00 chrome
 5154 ?        00:00:00 chrome
 5160 ?        00:00:00 chrome
[rozaydin@RO ~]$
 

Killing these processes  one by one is a tedious task instead you can use below command the kill them with one single line. (Bird massacre with single stone)


ps -e | grep <processname> | awk '{system("kill -9 "$1)}'


[rozaydin@RO ~]$ ps -e | grep chrome | awk '{system("kill -9 "$1)}'
sh: line 0: kill: (5033) - No such process
sh: line 0: kill: (5036) - No such process
sh: line 0: kill: (5055) - No such process
sh: line 0: kill: (5083) - No such process
sh: line 0: kill: (5107) - No such process
sh: line 0: kill: (5111) - No such process
sh: line 0: kill: (5115) - No such process
sh: line 0: kill: (5123) - No such process
sh: line 0: kill: (5131) - No such process
sh: line 0: kill: (5139) - No such process
sh: line 0: kill: (5142) - No such process
sh: line 0: kill: (5154) - No such process
sh: line 0: kill: (5160) - No such process
[rozaydin@RO ~]$
[rozaydin@RO ~]$ ps -e | grep chrome
[rozaydin@RO ~]$

Tuesday, March 24, 2015

How to list rpm dependencies


You can easily list the dependencies the rpm file requires prior installation, this is particularly useful when you are shipping your rpms in a removable media this way you can ensure you have provided all the dependencies.

Open a terminal and type below command,

rpm -qpR name_of_rpm

You will see output like below;

/bin/sh
rpmlib(CompressedFileNames) <= 3.0.4-1
rpmlib(PayloadFilesHavePrefix) <= 4.0-1
...

Wednesday, March 4, 2015

Building Berkeley DB XML for CentOS systems



Go to this link and download Berkeley DB XML. Version used in this guide is "6.0.17". Once the download complete, unzip the file.

[rozaydin@RO Tutorials]$ ls
dbxml-6.0.17.tar.gz
[rozaydin@RO Tutorials]$ tar -xzf dbxml-6.0.17.tar.gz
[rozaydin@RO Tutorials]$ ls
dbxml-6.0.17  dbxml-6.0.17.tar.gz
[rozaydin@RO Tutorials]$ cd dbxml-6.0.17/
[rozaydin@RO dbxml-6.0.17]$ ls
buildall.sh  db-6.1.19  dbxml  README  xerces-c-src  xqilla
[rozaydin@RO dbxml-6.0.17]$

 DB XML uses  XQilla which is an XQuery and XPath 2 library implemented on top of the  Xerces-C. DB XML requires Berkeley DB as well. So before using it we need to install each of the following dependencies in the following order;
Build and install Berkeley-DB
Build and install Xerces
Build and install XQuilla
Build and install XML-DB
DB XML compilation failed to compile with java 8 switching to java version "1.7.0_72" compilation completed with no errors. Open a terminal switch to root user and set JAVA variables. (PLEASE note you need to use this same terminal for all commands listed below)

[rozaydin@RO dbxml-6.0.17]$ pwd
/home/rozaydin/Desktop/Tutorials/dbxml-6.0.17
[rozaydin@RO dbxml-6.0.17]$ su -
Password:
Last login: Wed Mar  4 12:19:38 EET 2015 on pts/0
[root@RO ~]# export JAVA_HOME=/usr/java/jdk1.7.0_72
[root@RO ~]# export PATH=$JAVA_HOME/bin:$PATH
[root@RO ~]# cd /home/rozaydin/Desktop/Tutorials/dbxml-6.0.17
[root@RO dbxml-6.0.17]#

Now proceed with building Berkeley DB with configure, make, make install use following commands;

[root@RO dbxml-6.0.17]# ls
buildall.sh  db-6.1.19  dbxml  README  xerces-c-src  xqilla
[root@RO dbxml-6.0.17]# cd db-6.1.19/
[root@RO db-6.1.19]# ls
build_android  build_vxworks  build_windows  docs      lang     README  test
build_unix     build_wince    dist           examples  LICENSE  src     util
[root@RO db-6.1.19]# cd build_unix/
[root@RO build_unix]# ../dist/configure --enable-cxx --enable-java
[root@RO build_unix]# make
[root@RO build_unix]# make install

When operation completes this will install Berkeley DB to /usr/local/BerkeleyDB.6.1 directory. Change directory back to where you unzipped XML DB.

[root@RO build_unix]# cd /usr/local/BerkeleyDB.6.1
[root@RO BerkeleyDB.6.1]# ls
bin  docs  include  lib
[root@RO BerkeleyDB.6.1]# cd /home/rozaydin/Desktop/Tutorials/dbxml-6.0.17/
[root@RO dbxml-6.0.17]# pwd
/home/rozaydin/Desktop/Tutorials/dbxml-6.0.17

After this step proceed with building XERCES library.

[root@RO dbxml-6.0.17]# cd xerces-c-src/
[root@RO xerces-c-src]# ls
config        CREDITS  LICENSE      NOTICE    samples  version.incl
config.h.in   doc      m4           projects  scripts  xerces-c.pc.in
configure     INSTALL  Makefile.am  README    src      xerces-c.spec
configure.ac  KEYS     Makefile.in  reconf    tests
[root@RO xerces-c-src]# ./configure
[root@RO xerces-c-src]# make
[root@RO xerces-c-src]# make install

When operation completes this will install XERCES library to /usr/local/bin directory. You should see similar output as below:

test -z "/usr/local/bin" || /bin/mkdir -p "/usr/local/bin"
  /bin/sh ../libtool   --mode=install /bin/install -c CreateDOMDocument DOMCount DOMPrint EnumVal MemParse PParse PSVIWriter Redirect SAX2Count SAX2Print SAXCount SAXPrint SCMPrint SEnumVal StdInParse XInclude '/usr/local/bin'
libtool: install: /bin/install -c .libs/CreateDOMDocument /usr/local/bin/CreateDOMDocument
libtool: install: /bin/install -c .libs/DOMCount /usr/local/bin/DOMCount
libtool: install: /bin/install -c .libs/DOMPrint /usr/local/bin/DOMPrint
libtool: install: /bin/install -c .libs/EnumVal /usr/local/bin/EnumVal
libtool: install: /bin/install -c .libs/MemParse /usr/local/bin/MemParse
libtool: install: /bin/install -c .libs/PParse /usr/local/bin/PParse
libtool: install: /bin/install -c .libs/PSVIWriter /usr/local/bin/PSVIWriter
libtool: install: /bin/install -c .libs/Redirect /usr/local/bin/Redirect
libtool: install: /bin/install -c .libs/SAX2Count /usr/local/bin/SAX2Count
libtool: install: /bin/install -c .libs/SAX2Print /usr/local/bin/SAX2Print
libtool: install: /bin/install -c .libs/SAXCount /usr/local/bin/SAXCount
libtool: install: /bin/install -c .libs/SAXPrint /usr/local/bin/SAXPrint
libtool: install: /bin/install -c .libs/SCMPrint /usr/local/bin/SCMPrint
libtool: install: /bin/install -c .libs/SEnumVal /usr/local/bin/SEnumVal
libtool: install: /bin/install -c .libs/StdInParse /usr/local/bin/StdInParse
libtool: install: /bin/install -c .libs/XInclude /usr/local/bin/XInclude

After this step proceed building XQuilla library (PLEASE note that you need to provide the xerces-c-src directory using ABSOLUTE path not doing so will fail the compilation)

[root@RO xqilla]# ./configure --with-xerces=/home/rozaydin/Desktop/Tutorials/dbxml-6.0.17/xerces-c-src
[root@RO xqilla]# make
[root@RO xqilla]# make install

When operation completes this will install XQuilla library to /usr/local/lib directory.
The last step involves building XML DB in dbxml directory type below commands:

[root@RO dbxml]# pwd
/home/rozaydin/Desktop/Tutorials/dbxml-6.0.17/dbxml
[root@RO dbxml]# cd build_unix/
[root@RO build_unix]# ../configure --enable-java --with-berkeleydb=/usr/local/BerkeleyDB.6.1 --with-xqilla=/usr/local/lib
[root@RO build_unix]# make
[root@RO build_unix]# make install

When operation completes this will install XML DB to /usr/local/BerkeleyDBXML.6.0/ directory. Verify the installation by typing below commands

[root@RO build_unix]# cd /usr/local/BerkeleyDBXML.6.0/
[root@RO BerkeleyDBXML.6.0]# ls
bin  include  lib
[root@RO BerkeleyDBXML.6.0]# cd bin
[root@RO bin]# ls
dbxml  dbxml_dump  dbxml_load  dbxml_load_container
[root@RO bin]# dbxml
bash: dbxml: command not found...
[root@RO bin]# ./dbxml
dbxml>

if you see the prompt you are good :)



Sunday, February 8, 2015

sample pom.xml file for javaee rest application

here is the sample pom file i most of the time use to form the basis of my java web application projects. I use slf4j with logback for logging, mockito, junit and jersey test framework for testing and google gson for json conversion.

  
  
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>org.demo</groupId>
    <artifactId>demo</artifactId>
    <version>1.0.0-SNAPSHOT</version>
    <packaging>war</packaging>

    <name>demo application</name>

    <properties>
        <endorsed.dir>${project.build.directory}/endorsed</endorsed.dir>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>
    
    <dependencies>
        
        <dependency>
            <groupId>javax</groupId>
            <artifactId>javaee-web-api</artifactId>
            <version>7.0</version>
            <scope>provided</scope>
        </dependency>
        
        <dependency>
            <groupId>javax.ws.rs</groupId>
            <artifactId>javax.ws.rs-api</artifactId>
            <version>2.0.1</version>
            <scope>provided</scope>
        </dependency>       
        
        <dependency>
            <groupId>com.google.code.gson</groupId>
            <artifactId>gson</artifactId>            
            <version>2.3.1</version>
        </dependency> 
        
        <!-- Logging -->
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
            <version>1.7.10</version>
        </dependency> 

        <dependency>
            <groupId>ch.qos.logback</groupId>
            <artifactId>logback-classic</artifactId>
            <version>1.1.2</version>
        </dependency> 

        <dependency>
            <groupId>ch.qos.logback</groupId>
            <artifactId>logback-core</artifactId>
            <version>1.1.2</version>
        </dependency>
        
        <!-- Test -->
        <!-- https://jersey.java.net/documentation/latest/user-guide.html#d0e15523 -->
        <dependency>
            <groupId>org.glassfish.jersey.test-framework.providers</groupId>
            <artifactId>jersey-test-framework-provider-grizzly2</artifactId>
            <version>2.15</version>
            <scope>test</scope>
        </dependency>
        
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.12</version>
            <scope>test</scope>
        </dependency>
        
        <dependency>            
            <groupId>org.mockito</groupId>
            <artifactId>mockito-all</artifactId>
            <version>1.10.19</version>  
            <scope>test</scope>          
        </dependency>
                        
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.1</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                    <compilerArguments>
                        <endorseddirs>${endorsed.dir}</endorseddirs>
                    </compilerArguments>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <version>2.3</version>
                <configuration>
                    <failOnMissingWebXml>false</failOnMissingWebXml>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <version>2.6</version>
                <executions>
                    <execution>
                        <phase>validate</phase>
                        <goals>
                            <goal>copy</goal>
                        </goals>
                        <configuration>
                            <outputDirectory>${endorsed.dir}</outputDirectory>
                            <silent>true</silent>
                            <artifactItems>
                                <artifactItem>
                                    <groupId>javax</groupId>
                                    <artifactId>javaee-endorsed-api</artifactId>
                                    <version>7.0</version>
                                    <type>jar</type>
                                </artifactItem>
                            </artifactItems>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

</project>

Thursday, October 2, 2014

Compiling Open Splice Community Edition on CentOS 6.5

OpenSplice DDS is a high-performance messaging technology, and DDS stands for Data Distribution Service for Real-Time Systems (DDS). To be honest i dont know much actually i know very little at all. It seems to be a middleware (a data bus) that is supposed to make your applications to communicate. I had been involved in an m2m project for automatic meter reading (AMR) in the past. The protocol we used was MQTT based. MQTT was easy to understand easy to use and a pleasure to work with however my experience with dds so far not so pleasant it is not easy to understand not easy to use and not pleasant to work with (my personal opinions these are free to not to agree you are). DDS promises a de-centralized structure compared to one server multiple client approach. Anyway the compile steps for open splice is described step by step at the opensplice web site but there is a catch which is not documented you need to have MPC (Make Project Creator)  installed and you need MPC_ROOT environment variable set properly (pointing to directory where you installed MPC). Und you should not be using the MPC from its official web site you need to download modified MPC from PrismTech source repo at git hub. which is A fork of OCI's MakeProjectCreator with some tweaks required to support working with OpenSplice and this piece of information is not documented anywhere (at least not anywhere i can find they should have listed these requirement on their web site again this is my opinion free you are to not to agree) not using the proper MPC causes opensplice compile to fail und lots of headaches. hope someone finds this info valuable and saves some time trying to compile the code. 

Monday, March 10, 2014

Bash Script To Monitor Your Web App


Assume you have a web application deployed on some Linux Server(s) and you want to get an email notification if for some reason your web app went down and stopped providing service. The most straightforward and easy way is to create a cronjob on the server to poll the service status using a HTTP client (wget). Recently we run into this kind of need and created a very simple (and crude and primitive and pathetic) bash script to poll an URL on periodic intervals and based on the http response send an email to the defined mail distribution list to inform people about service status. You can find the bash script below. I need to admit it is very primitive but yet its working for us so far. (Except the flooding of the emails when the server is down)

1.) ssh to your server and open "vim" paste below script and save it with some name.

#!/bin/bash
MAIL_LIST="xx.yy@cc.com aa@bb.tt ll@bb.cc.com"
APPLICATION_URL=http://xxx.yy.zz.tt:8080/core

wget -q -o /dev/null --spider --no-check-certificate $APPLICATION_URL

if [ $? -eq 0 ]
then

MSG="`date` SUCCESS $APPLICATION_URL accessible!"
echo "$MSG" >> log_vulture_watch.log
else

MSG="`date` ERROR $APPLICATION_URL not accessible!"
echo "$MSG" >> log_vulture_watch.log
echo "Unable to access $APPLICATION_URL " | mail -s "Vulture_Watch Server Monitor" $MAIL_LIST
fi


2.) cd to the directory where the script file is located and make it executable. chmod 777 <scriptname>


3.) Type crontab -e and enter a line consisting of time period, and command and then save your settings. type crontab -l to list cronjobs you should see the task you just defined.


# Edit this file to introduce tasks to be run by cron.
#
# Each task to run has to be defined through a single line
# indicating with different fields when the task will be run
# and what command to run for the task
#
# To define the time you can provide concrete values for
# minute (m), hour (h), day of month (dom), month (mon),
# and day of week (dow) or use '*' in these fields (for 'any').#
# Notice that tasks will be started based on the cron's system
# daemon's notion of time and timezones.
#
# Output of the crontab jobs (including errors) is sent through
# email to the user the crontab file belongs to (unless redirected).
#
# For example, you can run a backup of all your user accounts
# at 5 a.m every week with:
# 0 5 * * 1 tar -zcf /var/backups/home.tgz /home/
#
# For more information see the manual pages of crontab(5) and cron(8)
#
# m h  dom mon dow   command

*/1 * * * * /home/ososapp/rscripts/vulture_watch
ososapp@ososapp:~$


You can find plenty of resources about crontab over the internet (http://unixhelp.ed.ac.uk/CGI/man-cgi?crontab+5 ), but what above line says is run the script every minute. (Please pay attention to the "/"  character before the number 1 , if you don't put it your script wont run every single minute.). The last part of the script (/home/ososapp/rscripts/vulture_watch) is the path to your bash script file. (in my case  vulture_watch is the script file name and it is located in directory /home/ososapp/rscripts )

4.) You are done :) enjoy.



Sunday, January 19, 2014

Raspberry Pi Fixing SSH Slow Password Prompt

I have two raspberry pis at home one is always on a web  cam connected to it and it lets me view my aquarium when i want over the internet :) The other i use to experiment with various stuff ranging from reading electrical meters to trying to attach sensors to its GPIO.

Most of the time i am using ssh to login and do stuff on my raspberry pis. They are attached to my home private network and i use putty to do ssh connections to them. The user prompt appears with no delay at all. However it takes quite some time for the password prompt to appear ( taking up to 30 seconds on some occasions ). While searching ubuntu forums for another thing i came across below post about slow password prompt:

http://askubuntu.com/questions/246323/why-ssh-password-prompt-takes-too-long-to-appear

And i wanted to give it a try. I did login to raspberry pi via ssh and run below command, if you dont have vim you can use nano as well.

sudo vim /etc/ssh/sshd_config








Find the line UseDNS in the sshd_config file and if it exists change it to "no". If it does not exist go to the very end of the line and add a new line "UseDNS no". When you are done save the file.











Restart ssh service using command

sudo service ssh restart

Close your ssh and re-connect this time (hopefully) you will get the password prompt instantly :).





Sunday, January 12, 2014

Compiling CapWap on Ubuntu 12.04 LTS

Recently a close friend of mine wanted me to set up a development environment for a project called CapWap, never heard of it before and still not sure what it is, but taking glimpse to it's project page on github convinced me its something cool :)

You can access CapWap project page using link : https://github.com/vollero/openCAPWAP
More detail can be read from project documentation.



Below are the steps to create a development environment for CapWap

1.) Install Virtual Box to your computer. I used Virtual Box 4.3. just download it from https://www.virtualbox.org/wiki/Downloads installation requires no black magic. Clicking next next and next will do the trick.

2.) Once installed run it. And create a new virtual operating system by pressing new. Below are some screenshots, in respective order, i took while creating my virtual OS. (Language is Turkish :) but should not be an issue) i allocated 4096 MB Ram, and 60 GB Hdd space. You should allocate at least 64 MB ram for graphics adapter for a comfortable desktop experience.

     




     

3.) Once you are done go to Ubuntu web site and download 32 Bit Ubuntu 12_04 LTS Desktop Edition 
do not go for 64 bit version even if you have an 64 bit system.You can download ubuntu from this link: http://www.ubuntu.com/download/desktop


4.) Once the download is complete. open VirtualBox, select the Virtual OS from the left pane and right click on it than select setting from the popup menu. A new window will open, click on storage from left pane, and mount your freshly downloaded iso image. (screen shots below)













5.) Once iso image is mounted start your virtual operating system (go back to main screen in virtualbox select your virtual operating system from the left pane and click start) A new window will appear and ubuntu 12_04 LTS setup screen will welcome you. installation is pretty easy just go next next and follow on screen instructions its nearly impossible for you to fail. ( one thing to mention is once the installation is complete un-mount the iso image you previously mounted otherwise you will be greeted with setup screen again :) ) installation takes up some time so its a great time to waste time on the internet ...

6.) If you survived up to this point rest is a little more straight forward. i installed Netbeans as development IDE the reason is i love Netbeans :). You need to install JDK and than Netbeans follow steps below.

7.) In order to install jdk (java development kit) open terminal and type below commands in respective order select OK and Yes options when prompted. ( i followed the guide available from link: http://askubuntu.com/questions/309900/installing-java-7-update-25-on-12-04-lts works flawlessly )

sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update
sudo apt-get install oracle-java7-installer
java -version
if everything goes ok you should be seeing installed java version on the terminal.
8.) Once the jdk installation is complete download netbeans ide from www.netbeans.org. If you are not planning to do java development selecting C++ development version is sufficient.

















When the download completes run the netbeans installer. Your installer file should be located in Downloads directory under your home directory. Installer can be invoked with sudo bash ./"netbeans-installer-name"

cd ~/Downloads
sudo bash ./netbeans-7.4-cpp-linux.sh
installation is pretty straightforward and for c++ development netbeans requires around 210 mb of space. Netbeans will automatically detect required configuration just do next next and next. Once the installation is complete fire up netbeans. ( Click on dash home button from the left pane on desktop type netbeans to the search bar and click on it)

















9.) Up to this point we dealt with with virtual box, ubuntu and netbeans setups from this moment on we will finally clone the CapWap repository install necessary libraries and modify makefile and we will compile in the end. Select Team->Git->Clone (Screen shot below)











type https://github.com/vollero/openCAPWAP as the repository url and click next, in next screen just click next and finish.


























Once the clone opration complete the ide will show a dialog "Do you want to create an IDE project from cloned resources?" click Create Project. Follow the screen shots for next steps.










Well if you followed properly you should be seeing the project in the ide right now, congrats only a few more steps left to make it compile properly.
To make CapWap compile you need to install libpcap-dev, libssl-dev libraries and you need to tweak a few lines in the make file.
Open the terminal and type below commands respectively

sudo apt-get install libpcap-dev

sudo apt-get install libssl-dev

then open Netbeans and double click MakeFile (under important Files) Find the line that starts with LDFLAGS and change it as below:

LDFLAGS = /usr/lib/i386-linux-gnu/libz.a /usr/lib/i386-linux-gnu/libssl.a /usr/lib/i386-linux-gnu/libcrypto.a -lpthread -ldl -lz -D_REENTRANT
Well thats it. Save MakeFile and press clean build from the top, it should compile with no errors and you are ready to go.

I hope someone finds this article useful, feel free to leave your comments below.



Wednesday, March 27, 2013

Kira Gelir Vergisi
Dün kira gelir beyannamesi vermek için Yakacık vergi dairesine annem ile beraber gittik. Devletin vatandaşını  nasıl kaz gibi yolduğunu ve bunu küstah memurları ile yaptığını görmek için ibretlik bir yer. Para vermek için çektiğiniz çileden sonra saçma sapan kurdukları internet sitesini ve saçma sapan sistemlerini görmek insana ben bu adamlara niye para veriyorum diye sorduruyor. Sahi neden ben bin bir zahmetle bankalara yem olmak pahasına yıllarca sürecek kredi borcu altına girip satın aldığım bir evden elde ettiğim geliri seninle paylaşıyorum ? Normalde siyasetle bir işim olmaz ama bir sonraki seçimlerde iktidar partisi bizim evden tek bir oy alamayacak. Devlet insanlar için var olmalı insanlar devlet için değil. Yapılan bunca saçma sapan harcamaya ben vatandaş olarak ortak olmak zorunda değilim ve kendi malımı devlet kelimesi arkasına saklanan bu insanlara da vermek istemiyorum. Umarım toplumumuzda benim gibi düşünen insanlar vardır ve artık bu yüksek vergi saçmalığına bir son verilir. Vatandaşın malı devletin malı demek değildir. İstediğiniz zaman cebinize indirebileceğiniz bir varlıkta değildir. Bir sonraki seçimlerde umarım bunu net bir şekilde anlarsınız.