Sunday, September 9, 2018

JAVA vs SCALA

Good-day everyone, in this blog i will be discussing about JAVA and SCALA programming.



 I am going to talk about:
- What is Scala programming
- The difference between JAVA and SCALA
- Coding comparison between SCALA and JAVA
- Conclusion


What is Scala Programming ?
- It has been introduce in 2001 by Martin Odersky
- Scala is a programing is a type of JVM (Java Virtual Machine) language that incorporate both functional and object orientated programming (Multi-paradigm).
- Uses SBT (Scala Build Tool) to compile
- Major company uses Scala such as:
  -Linkedin
  -Netflix
  -sound-cloud
  -Twitter
  -and many more

Difference between SCALA and JAVA
- Reduce the number of lines of code compare to java
- Which perform than java
- A steep learning curve compare to java
-  JAVA is more readable and understandable than SCALA if your not used to the programming language


Coding comparison between JAVA and SCALA

- Creating an array of String

JAVA

SCALA



As you can see when creating a list and being able to print out the data in the list, in JAVA it has more coding compare to SCALA. Scala does not need a loop to print out all the data whereas java needs a for loops to be able to print out all of the data.



- IF Statement

JAVA



SCALA


As you can see from the images above, they both look familiar when it comes to IF Statement. There are no difference what so ever.


- Creating a function

JAVA


SCALA



The picture above shows again that both JAVA and SCALA are similar when creating a simple additional function. However, SCALA uses less codes compare JAVA




- Creating an object and class

JAVA

SCALA






From the picture above, as you can see there is a big different when creating a class and an object.
JAVA consist of more code compare to SCALA


Conclusion

In conclusion, if you are interested in programing using SCALA you should try and give it ago for yourself. In the beginning SCALA is abit complex to understand at first, but once you learn the basic programing of SCALA then it should be easy when developing a project base on SCALA,

OSB 12c - Pipeline Template

Apa itu Pipeline di OSB 12c?

Pipeline adalah OSB message flow. Di pipeline kita menentukan flow dari service yang akan kita buat, dan di pipeline kita dapat menggunakan bermacam-macam nodes.
  • Conditional Branching -> kita dapat menggunakan conditional branching berdasarkan kondisi tertentu.
  • Operational Branching -> jika di message flow kita didefine WSDL-based procy services, kita sebaiknya menggunakan operation branching. Ketika kita meng-create sebuah operational branch node, kita dapat mem-build branching logic berdasarkan operation yand di-define di WSDL.
  • Pipeline Pair -> mempunyai sebuah single request dan single response di one top-level element. Pipeline pair node memiliki satu descendant di message flow.
  • Route -> merupakan batas antara request/response untuk proxy service. Ketika route node mengirim request message, request pocessing dianggap selesai, dan ketika route node menerima pesan response, response pocessing dimulai. 
  • Stage -> dimana kita dapat melakukan konfigurasi action untuk memanipulasi message yang lewat melalui pipeline.
  • Error Handler -> dapat dibuat di node atau tahap apa saja, untuk menangani kesalahan pada lokasi tertentu.



Pipeline Template

Pipeline template mendefinisikan atau menggambarkan bentuk umum atau pattern message flow. Menggunakan pipeline template kita dapat men-generate message flow konkrit. Satu hal yang perlu kita tahu bahwa kita tidak dapat membuat pipeline template di Oracle Service Bus Console, sehingga kita akan menggunakan JDeveloper.

Cara Membuat Pipeline Template

  • Untuk membuat pipeline template, terlebih dahulu buat proyek baru dan pilih opsi "Service Bus Project".

  • Sekarang untuk membuat pipeline template, klik kanan pada proyek yang baru dibuat dan masuk ke opsi "Pipeline Template". Kemudian berikan nama template pipeline dan juga tentukan lokasi untuk template itu.

  • Sekarang pilih service type-nya, untuk sekarang saya akan memilih "Any XML".


  • Kemudian deploy proyek template pipeline anda ke server.

Bagaimana Menggunakan Pipeline Template?

  • Di langkah-langkah di atas kita telah melihat cara membuat template pipeline, sekarang kita melihat cara menggunakan template pipeline yang dibuat di atas. Untuk melakukan itu maka buat proyek yang baru.
  • Klik kanan pada proyek yang baru dibuat dan pilih New, kemudian pilih opsi "Pipeline".
  • Buka wizard; pada langkah pertama tentukan nama dan deskripsi service. Centang "From Template", ini diperlukan ketika Anda ingin menggunakan template pipeline yang telah dibuat. Untuk mencari template pipeline, klik tombol pencarian dan pilih template pipeline yang kita buat pada langkah di atas.

  • Setelah itu klik pada langkah berikutnya, anda melihat layar di bawah ini, di jendela itu pilih jenis service "Any XML" dan centang kotak centang "Expose as a Proxy Service" karena kita ingin mengekspos pipeline sebagai proxy service. Tentukan nama proxy service dan juga pilih transport proxy service.
  • Setelah itu klik selesai pada langkah di atas, wizard akan membawa anda ke message flow yang didapat dari template pipeline. Anda perhatikan bahwa semua action dan node yang telah dibuat di template pipeline, dapat kita lihat di pipeline kita yang sekarang. Sekarang Anda dapat menambahkan action yang sesuai kebutuhan anda di message flow ini.
  • Setelah langkah ini, tampilan composite anda akan terlihat seperti di bawah ini.


Reference

  • https://docs.oracle.com/middleware/12212/osb/develop/GUID-A576603C-212B-40FE-B799-FE689A77C280.htm#OSBDV88663
  • https://docs.oracle.com/middleware/1213/osb/develop/GUID-2B8355A2-CF24-4D6F-9947-B7F043FE61D3.htm#OSBDV2461

How to look session and kill session in oracle database

Halo sobat Nostra,

Kali ini saya akan membahas bagaimana cara melihat session dan kill session tersebut pada oracle database.

Ini pengalaman saya ketika mengerjakan project Jiwasraya, saya tidak bisa alter table dan selalu error. Error nya seperti gambar di bawah ini









Nah ternyata error tersebut dikarenakan table itu di lock.
Bergumul dengan error  dan bertanya tanya dalam hati, kenapa table itu di lock ya? (xixixi cie yang bergumul :D)
Setelah di telusuri lebih jauh, ternyata table tersebut di lock karena transaksi pada table berjalan lama serta banyak aplikasi yang menggunakan table tersebut dan melakukan transaksi secara bersamaan.
Kebetulan pada saat kasus ini, applikasi sedang di test oleh user IT Jiwasraya, dan table yang ingin saya alter adalah salah satu table yang memiliki data yang sangat banyak yang membutuhkan waktu lebih lama dari biasanya jika kita melakukan select table.
Table di lock bisa juga dikarenakan ketika kita melakukan perubahan pada table namun kita lupa commit dan log off dari sistem.

Cara yang saya lakukan agar table tersebut tidak lock, adalah melihat session dan kill session pada table tersbut dengan cara menggunakan SQL command seperti :

SELECT
    O.OBJECT_NAME,
    S.SID,
    S.SERIAL#,
    S.PROGRAM,
    SQ.SQL_FULLTEXT,
    S.LOGON_TIME
FROM
    V$LOCKED_OBJECT L,
    DBA_OBJECTS O,
    V$SESSION S,
    V$SQL SQ
WHERE
    L.OBJECT_ID = O.OBJECT_ID
    AND L.SESSION_ID = S.SID
    AND S.SQL_ADDRESS = SQ.ADDRESS;

Untuk melihat table yang di lock dapat menggunakan view V$Locked_Object, dan nama table yang di lock tersebut ada pada view DBA_Object.
Untuk menemukan session blocked nya, kita bisa join dengan view V$Session

dan untuk kill session bisa dengan command berikut :


alter system kill session 'SID,SERIAL#';

Kita harus berhati-hati dalam menghapus session dalam database. Jangan sampai salah menghapus session table.
Ada baiknya jika kita ingin kill session pada suatu table harus konsultasi terlebih dahulu dengan tim.

Sekian dari saya tentang bagaimana cara melihat session dan kill session pada oracle database

Terima kasih,

Retrive URL Paramater through OSB



Good-day everyone, in this blog i will be showing you a step-by-step on how to retrieve values from URL and change to a different value.

The Oracle Service Bus (osb) Test

Why do you need to retrieve values from URL?

- In the project that am currently working on, there is a task where we have to extract the values from the URL. When the data has been extracted, i then have to change/modify the value and send that data to another third party vendor.

For example:
A user dials in a number (*123*321#), from that number it will extract data about the user such as their phone number, ID and etc.  Ones the data has been extracted, it will then generate all that data into a URL (http://10.2.43.65/Example?msisdn=65787776998865&id=20202&username=bob).
Afterwards, from that URL we must send it through to another vendor however, the msisdn (user phone number) cannot be shown to another vendor and we must modify its value.


How to retrieve values from URL?

1)

- First add a pipeline pair in the message flow and in each pipeline you should add a stage for each.

2)

- Then right click on "stage1" on the request side and edit stage. Afterwards, you have to add an action which is "Assign". 

3)


- Then click on the expression and type this in: "$inbound/ctx:transport/ctx:request/http:query-parameters/http:parameter[@name="msisdn"]/@value". This is for extracting the values which is msisdn.

4)


- You can add as much parameter as you want but remember, you much change the code as shown:
"$inbound/ctx:transport/ctx:request/http:query-parameters/http:parameter[@name="{the value of your choice}"]/@value". Afterwards, you need to give a variable name after you extract the data as shown in the image above.

5)
- If you wan to check the output, go to the "stage1" of the respond side of the pipeline and add an action called replace. The path should be "." and the variable should be body.

6)


- Then go to the expression and type this in:
<Testing>
https://10.10.10.10/Testing?masisdn={$MSISDN}&amp;inputno={$inputno}&amp;shortno={$shortno}
</Testing>

if you have more than 3 variables then you should add ${your variable name}. For this example i only have 3 variables.

7)

- Afterwards, Activate your OSB and go to your proxyservice. Inside there is a parameter called "query-parameter" under "Transport" and type this in:

<tp:query-parameters xmlns:tp="http://www.bea.com/wli/sb/transports/http">
 <tp:parameter name="msisdn" value="90876778998876" />
 <tp:parameter name="shortno" value="12" />
 <tp:parameter name="inputno" value="2" />
 </tp:query-parameters> 

and execute.

8)

- Once you have execute, you should check if the URL value matches with the number that you have input.

Conclusion

- If you need to extract values from URL through OSB, you should try this method because by using this method it is very it very quick and easy fetching the data. 
Make sure when testing this service is having the right name values because if you miss the value does not match, the value would not be able to show up in the respond.



Two Factor Authentication with Spring Security

Setelah sebelumnya kita udah bahas tentang pentingnya two-factor Authentication atau disingkat 2FA dalam mengamankan suatu apliakasi online, kali ini kita akan bahas tentang penerapan 2FA pada Spring Security. Udah gasabar ? kuy cekidot.


Dari blog sebelumnya kita sudah membahas beberapa metode yang digunakan pada 2FA kali ini kita akan membahas metode 2FA menggunakan software, software yang digunakan adalah Google Authenticator. Sebelumnya kita diharuskan untuk mengunduh Google Authenticator terlebih dahulu di play store atau app store. Pada spring security kita akan menambahkan fungsi baru kedalam sistem simple login dan menggunakan Google Authenticator untuk meng generate token.

Langkah penggunaan Google Authenticator sebagai 2FA adalah sebagai berikut :
  1. User akan registrasi dengan menginput data email dan password
  2. Setelah sukses registrasi user akan diarahkan ke sebuah halaman dimana sudah tersedia QR-Code hasil generate secret key dari user tersebut.
  3. Lalu user scaning QR-Code pada aplikasi Google Authenticator yang sudah diunduh sebelumnya
  4. Setelah itu pada aplikasi Google Authenticator akan terlihat deretan 6 digit unik code.
  5. Kemudian user menuju form login
  6. User memasukan email dan password yang sudah didaftarkan sebelumnya dan memasukan 6 digit kode unik yang tedapat pada Google Authenticator.
  7. Saat data valid maka user akan diijinkan masuk kehalaman selanjutnya.


Gimana ? kebayangkan alur proses nya ? ehehehe

Untuk menabahkan fungsi generate token kita akan menggunakan simple server-side library dengan menambahkan depedency pada pom.xml.



Kemudian kita membuat user entity sebagai berikut.

kita akan menyimpan secret key yang nantinya akan digunakan untuk generate token.

Setelah itu kita perlu menyesuaikan security configuration agar dapat menambahkan parameter tambahan, parameter yang dimaksud adalah verification token. Kita dapat menambahkan parameter tersebut dengan membuat CustomAuthenticationDeatilsSource.


Dan kita akan membuat CustomWebAuthenticationDetails.


Kemudian seperti inilah security configuration yang akan kita buat


Dan tentunya kita menambahkan paramater pada form login.

Untuk AuthenticationDetailsSource dapat dimodifikasi sesuai dengan kabutuhan kita.

Setelah itu kita juga perlu membuat AuthenticationProvider untuk menghandle paramater tambahan.


Dan juga kita perlu membuat Authentication Provider Bean


Dalam Proses registrasi setelah kita mengisi form registrasi maka kita akan diarahkan ke halaman dimana kita bisa scan QR-Code melaui Google Authenticator , berikut adalah method untuk menggenerate QR-Code:



Dan tentu kita akan membuat sebuah halaman untuk menampilkan Qr-Code.

<html>
<body>
<div id="qr">
    <p>
        Scan this Barcode using Google Authenticator app on your phone
        to use it later in login
    </p>
    <img th:src="${param.qr[0]}"/>
</div>
<a href="/login" class="btn btn-primary">Go to login page</a>
</body>

</html>

Yaaappp... selamat mencoba yaaa gais semoga postingan ini bermanfat..aamiin...

Source:https://www.baeldung.com/spring-security-two-factor-authentication-with-soft-token