<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:blogger='http://schemas.google.com/blogger/2008' xmlns:georss='http://www.georss.org/georss' xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-2919956819843973860</id><updated>2024-03-19T13:55:13.764-07:00</updated><title type='text'>Java by experience</title><subtitle type='html'>Learning j2ee by paying attention</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://pieterroskam.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2919956819843973860/posts/default?redirect=false'/><link rel='alternate' type='text/html' href='http://pieterroskam.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><link rel='next' type='application/atom+xml' href='http://www.blogger.com/feeds/2919956819843973860/posts/default?start-index=26&amp;max-results=25&amp;redirect=false'/><author><name>java by experience</name><uri>http://www.blogger.com/profile/07404653852761857615</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>48</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-2919956819843973860.post-2543496510538191104</id><published>2018-09-25T03:06:00.003-07:00</published><updated>2018-09-25T03:07:06.047-07:00</updated><title type='text'>The builder pattern in Kotlin</title><content type='html'>&lt;br /&gt;
&lt;div style=&quot;text-align: center;&quot;&gt;
&lt;b&gt;Introduction&lt;/b&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
The most of you are probably familiar with the builder pattern. I used this pattern a couple of times in Java later on with the @Builder annotation from the Lombok project. I am aware of the fact that the annotations of Lombok project are also usable in Kotlin. This is just for fun or when you are not using Lombok for what reason suits you.&amp;nbsp;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: center;&quot;&gt;
&lt;b&gt;the code&lt;/b&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
For this example I used a data class called Address. I am aware that it lacks some fields but that is not important in this explanation. Ok, lets get down to it:&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
data class Address(&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: red;&quot;&gt;&lt;b&gt;//The class members that will contain the data.&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; val addressLine1: String,&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; val addressLine2: String = &quot;&quot;,&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; val city: String,&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; val zip: String,&lt;br /&gt;
&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: red;&quot;&gt;&lt;b&gt;//The builder class&amp;nbsp;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; class Builder {&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; private lateinit var addressLine1: String&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; private var addressLine2: String = &quot;&quot;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; private var city: String = &quot;&quot;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; private var state: String = &quot;&quot;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: red;&quot;&gt;&lt;b&gt;//The assignment to the class members.&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; fun addressLine1(addressLine1: String) = apply { this.addressLine1 = addressLine1 }&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; fun addressLine2(addressLine2: String) = apply { this.addressLine2 = addressLine2 }&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; fun city(city: String) = apply { this.city = city }&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; fun country(country: String) = apply { this.country = country }&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: red;&quot;&gt;&lt;b&gt;//The build method we need to call.&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; fun build() = Address(&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; addressLine1,&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; addressLine2,&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; city,&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; state,&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; country&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; )&lt;br /&gt;
&amp;nbsp; &amp;nbsp; }&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;span style=&quot;color: red;&quot;&gt;&lt;b&gt;//The instanciation of the Adress class.&amp;nbsp;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;val address:Address = Address&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: red;&quot;&gt;&lt;b&gt;// calling the builder class.&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;.Builder()&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;span style=&quot;color: red;&quot;&gt;&lt;b&gt;//filling the fields with data.&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; .addressLine1(&quot;Address1&quot;)&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; .addressLine2(&quot;Address2&quot;)&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; .city(&quot;City&quot;)&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; .country(&quot;Country&quot;)&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: red;&quot;&gt;&lt;b&gt;//calling the build method&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; .build()&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: red;&quot;&gt;// Voila data&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; println(address.addressLine1)&lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;text-align: center;&quot;&gt;
&lt;b&gt;Conclusion&lt;/b&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
As allways, with a new way you have to get used to the fact that things are different. If you are new to Kotlin this might look magical to you. At least it did to me. Now I am working with Kotlin for a while I am used to the syntax. I am capable of doing stuff in Kotlin I did not think I would ever do.&amp;nbsp;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
Have fun!&lt;/div&gt;
&amp;nbsp; </content><link rel='replies' type='application/atom+xml' href='http://pieterroskam.blogspot.com/feeds/2543496510538191104/comments/default' title='Reacties posten'/><link rel='replies' type='text/html' href='http://pieterroskam.blogspot.com/2018/09/the-builder-pattern-in-kotlin.html#comment-form' title='0 reacties'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2919956819843973860/posts/default/2543496510538191104'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2919956819843973860/posts/default/2543496510538191104'/><link rel='alternate' type='text/html' href='http://pieterroskam.blogspot.com/2018/09/the-builder-pattern-in-kotlin.html' title='The builder pattern in Kotlin'/><author><name>java by experience</name><uri>http://www.blogger.com/profile/07404653852761857615</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2919956819843973860.post-3517734322522544938</id><published>2018-02-13T13:28:00.000-08:00</published><updated>2018-02-14T01:08:24.705-08:00</updated><title type='text'>rpc call to bitcoind</title><content type='html'>&lt;br /&gt;
&lt;div style=&quot;text-align: center;&quot;&gt;
&lt;b&gt;Introduction&lt;/b&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
Lately, in the news you can find a lot of material about bitcoins or the technique behind it. I have been reading a lot about this the last couple of months. It made me curious howto connect to the bitcoind myself. It must be possible too connect to the daemon and get that information yourself. I know, curiousity killed the cat. But I am still alive. Lets dive into the code and see what we should do.&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: center;&quot;&gt;
&lt;b&gt;The example&lt;/b&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: center;&quot;&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
So lets get started with the fun shall we? The surprising part is that it was less difficult then I thought it would be. Too get the right parts of all the different examples together and make it work was the hardest part.&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
First of all we need the bitcoind. We can install the daemon and ask if it is still alive. That is why I prefer too install bitcoin-qt. This has an interface where you can see some things like if it is running on testnet. Install it like:&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;pre style=&quot;background-color: #eff0f1; border: 0px; box-sizing: inherit; color: #111111; font-family: Consolas, Menlo, Monaco, &amp;quot;Lucida Console&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace, sans-serif; font-size: 13px; font-stretch: inherit; font-variant-east-asian: inherit; font-variant-numeric: inherit; line-height: inherit; margin-bottom: 1em; max-height: 600px; overflow: auto; padding: 5px; vertical-align: baseline; width: auto; word-wrap: normal;&quot;&gt;&lt;code style=&quot;border: 0px; box-sizing: inherit; font-family: Consolas, Menlo, Monaco, &amp;quot;Lucida Console&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace, sans-serif; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline; white-space: inherit;&quot;&gt;sudo add-apt-repository ppa:bitcoin/bitcoin 
sudo apt-get update
sudo apt-get install bitcoin-qt&lt;/code&gt;&lt;/pre&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
place in the ~/.bitcoin folder the file bitcoin.conf. The content should be als followed to run on testnet:&lt;/div&gt;
## bitcoin.conf configuration file. Lines beginning with # are comments.&lt;br /&gt;
### Uncomment and edit options you wish to use.&lt;br /&gt;
&lt;br /&gt;
## JSON-RPC options (for controlling a running bitcoin-qt/bitcoind process)&lt;br /&gt;
&lt;br /&gt;
# server=1 tells Bitcoin to accept JSON-RPC commands.&lt;br /&gt;
server=1&lt;br /&gt;
&lt;br /&gt;
# You must set rpcuser and rpcpassword to secure the JSON-RPC api&lt;br /&gt;
# You should create your own new random password.&lt;br /&gt;
# The username and password MUST NOT be the same.&lt;br /&gt;
&lt;br /&gt;
rpcuser=user&lt;br /&gt;
rpcpassword=password&lt;br /&gt;
&lt;br /&gt;
# How many seconds bitcoin will wait for a complete RPC HTTP request&lt;br /&gt;
# after the HTTP connection is established.&lt;br /&gt;
rpctimeout=30&lt;br /&gt;
&lt;br /&gt;
# By default, only RPC connections from localhost are allowed. Specify&lt;br /&gt;
# as many rpcallowip= settings as you like to allow connections from&lt;br /&gt;
# other hosts (and you may use * as a wildcard character):&lt;br /&gt;
#rpcallowip=10.1.1.*&lt;br /&gt;
#rpcallowip=192.168.1.*&lt;br /&gt;
&lt;br /&gt;
# Listen for RPC connections on this TCP port:&lt;br /&gt;
rpcport=8332&lt;br /&gt;
&lt;br /&gt;
# You can use bitcoind to send commands to bitcoin-qt/bitcoind&lt;br /&gt;
# running on another host using this option:&lt;br /&gt;
rpcconnect=127.0.0.1&lt;br /&gt;
&lt;br /&gt;
# Use Secure Sockets Layer (also known as TLS or HTTPS) to communicate&lt;br /&gt;
# with Bitcoin -server or bitcoind&lt;br /&gt;
#rpcssl=1&lt;br /&gt;
&lt;br /&gt;
# OpenSSL settings used when rpcssl=1&lt;br /&gt;
rpcsslciphers=TLSv1+HIGH:!SSLv2:!aNULL:!eNULL:!AH:!3DES:@STRENGTH&lt;br /&gt;
rpcsslcertificatechainfile=server.cert&lt;br /&gt;
rpcsslprivatekeyfile=server.pem&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
## Network-related settings:&lt;br /&gt;
&lt;br /&gt;
# Run on the test network instead of the real bitcoin network.&lt;br /&gt;
testnet=1&lt;br /&gt;
&lt;br /&gt;
# Connect via a socks proxy&lt;br /&gt;
#proxy=127.0.0.1:9050&lt;br /&gt;
&lt;br /&gt;
# Select the version of socks proxy to use (4-5, default: 5)&lt;br /&gt;
#socks=5&lt;br /&gt;
&lt;br /&gt;
# Use proxy to reach tor hidden services (default: same as -proxy)&lt;br /&gt;
#tor=&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;br /&gt;
&lt;br /&gt;
##############################################################&lt;br /&gt;
## Quick Primer on addnode vs connect ##&lt;br /&gt;
## Let&#39;s say for instance you use addnode=4.2.2.4 ##&lt;br /&gt;
## addnode will connect you to and tell you about the ##&lt;br /&gt;
## nodes connected to 4.2.2.4. In addition it will tell##&lt;br /&gt;
## the other nodes connected to it that you exist so ##&lt;br /&gt;
## they can connect to you. ##&lt;br /&gt;
## connect will not do the above when you &#39;connect&#39; to it.##&lt;br /&gt;
## It will *only* connect you to 4.2.2.4 and no one else.##&lt;br /&gt;
## ##&lt;br /&gt;
## So if you&#39;re behind a firewall, or have other problems ##&lt;br /&gt;
## finding nodes, add some using &#39;addnode&#39;. ##&lt;br /&gt;
## ##&lt;br /&gt;
## If you want to stay private, use &#39;connect&#39; to only ##&lt;br /&gt;
## connect to &quot;trusted&quot; nodes. ##&lt;br /&gt;
## ##&lt;br /&gt;
## If you run multiple nodes on a LAN, there&#39;s no need for##&lt;br /&gt;
## all of them to open lots of connections. Instead ##&lt;br /&gt;
## &#39;connect&#39; them all to one node that is port forwarded ##&lt;br /&gt;
## and has lots of connections. ##&lt;br /&gt;
## Thanks goes to [Noodle] on Freenode. ##&lt;br /&gt;
##############################################################&lt;br /&gt;
&lt;br /&gt;
# Use as many addnode= settings as you like to attempt connection to specific peers&lt;br /&gt;
#addnode=69.164.218.197&lt;br /&gt;
#addnode=10.0.0.2:8333&lt;br /&gt;
&lt;br /&gt;
# or use as many connect= settings as you like to connect ONLY to specific peers:&lt;br /&gt;
#connect=69.164.218.197&lt;br /&gt;
#connect=192.168.1.20:8333&lt;br /&gt;
&lt;br /&gt;
# Do not use Internet Relay Chat to find peers.&lt;br /&gt;
noirc=0&lt;br /&gt;
&lt;br /&gt;
# Maximum number of inbound+outbound connections.&lt;br /&gt;
#maxconnections=125&lt;br /&gt;
&lt;br /&gt;
# Miscellaneous options&lt;br /&gt;
&lt;br /&gt;
# Pre-generate this many public/private key pairs, so wallet backups will be valid&lt;br /&gt;
# after future transactions.&lt;br /&gt;
#keypool=100&lt;br /&gt;
&lt;br /&gt;
# Add an optional transaction fee every time you send bitcoins.&lt;br /&gt;
#paytxfee=0.01&lt;br /&gt;
&lt;br /&gt;
# Add timestamps to debug.log&lt;br /&gt;
#logtimestamps=1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
# User interface options&lt;br /&gt;
&lt;br /&gt;
# Start Bitcoin minimized&lt;br /&gt;
#min=1&lt;br /&gt;
&lt;br /&gt;
# Minimize to the system tray&lt;br /&gt;
minimizetotray=0&lt;br /&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
I post&amp;nbsp; a lot of options so you can play with it if you like.&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
The whole thing is actually working on apache httpClient:&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&amp;lt;dependency&amp;gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;lt;groupId&amp;gt;org.apache.httpcomponents&amp;lt;/groupId&amp;gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;lt;artifactId&amp;gt;httpclient&amp;lt;/artifactId&amp;gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;lt;version&amp;gt;4.5.3&amp;lt;/version&amp;gt;&lt;br /&gt;
&amp;lt;/dependency&amp;gt;&lt;br /&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;pre style=&quot;background-color: white;&quot;&gt;&lt;div style=&quot;font-family: &amp;quot;Times New Roman&amp;quot;; white-space: normal;&quot;&gt;
To start we have too do some boilerplate coding:&lt;/div&gt;
&lt;div style=&quot;font-family: &amp;quot;Times New Roman&amp;quot;; white-space: normal;&quot;&gt;
&lt;/div&gt;
&lt;div style=&quot;font-family: &amp;quot;Times New Roman&amp;quot;; white-space: normal;&quot;&gt;
&lt;b&gt;//To start with a Logger is like coffee in the morning.&lt;/b&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &amp;quot;Times New Roman&amp;quot;; white-space: normal;&quot;&gt;
&lt;pre style=&quot;font-family: &amp;quot;DejaVu Sans Mono&amp;quot;; font-size: 11.3pt;&quot;&gt;Logger log = LoggerFactory.&lt;span style=&quot;font-style: italic;&quot;&gt;getLogger&lt;/span&gt;(RpcServer.&lt;span style=&quot;font-weight: bold;&quot;&gt;class&lt;/span&gt;.getName());&lt;/pre&gt;
&lt;pre style=&quot;font-family: &amp;quot;DejaVu Sans Mono&amp;quot;; font-size: 11.3pt;&quot;&gt;&lt;b&gt;//We have to provide some cred. too login to the bitcoind&lt;/b&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/pre&gt;
&lt;pre style=&quot;background-color: white;&quot;&gt;&lt;pre&gt;&lt;span style=&quot;font-family: &amp;quot;dejavu sans mono&amp;quot;;&quot;&gt;&lt;span style=&quot;font-size: 11.3pt;&quot;&gt;&lt;span style=&quot;color: red;&quot;&gt;&lt;b&gt;//The username and password should match the ones in the conf file.&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;/pre&gt;
&lt;pre style=&quot;background-color: white;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;dejavu sans mono&amp;quot;;&quot;&gt;&lt;span style=&quot;font-size: 11.3pt;&quot;&gt;CredentialsProvider credsProvider = &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: navy; font-family: &amp;quot;dejavu sans mono&amp;quot;; font-size: 11.3pt; font-weight: bold;&quot;&gt;new &lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;dejavu sans mono&amp;quot;;&quot;&gt;&lt;span style=&quot;font-size: 11.3pt;&quot;&gt;BasicCredentialsProvider();
credsProvider.setCredentials(
        &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: navy; font-family: &amp;quot;dejavu sans mono&amp;quot;; font-size: 11.3pt; font-weight: bold;&quot;&gt;new &lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;dejavu sans mono&amp;quot;;&quot;&gt;&lt;span style=&quot;font-size: 11.3pt;&quot;&gt;AuthScope(&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: green; font-family: &amp;quot;dejavu sans mono&amp;quot;; font-size: 11.3pt; font-weight: bold;&quot;&gt;&quot;127.0.0.1&quot;&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;dejavu sans mono&amp;quot;;&quot;&gt;&lt;span style=&quot;font-size: 11.3pt;&quot;&gt;, &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: blue; font-family: &amp;quot;dejavu sans mono&amp;quot;; font-size: 11.3pt;&quot;&gt;8332&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;dejavu sans mono&amp;quot;;&quot;&gt;&lt;span style=&quot;font-size: 11.3pt;&quot;&gt;),
        &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: navy; font-family: &amp;quot;dejavu sans mono&amp;quot;; font-size: 11.3pt; font-weight: bold;&quot;&gt;new &lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;dejavu sans mono&amp;quot;;&quot;&gt;&lt;span style=&quot;font-size: 11.3pt;&quot;&gt;UsernamePasswordCredentials(&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: green; font-family: &amp;quot;dejavu sans mono&amp;quot;; font-size: 11.3pt; font-weight: bold;&quot;&gt;&quot;user&quot;&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;dejavu sans mono&amp;quot;;&quot;&gt;&lt;span style=&quot;font-size: 11.3pt;&quot;&gt;, &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: green; font-family: &amp;quot;dejavu sans mono&amp;quot;; font-size: 11.3pt; font-weight: bold;&quot;&gt;&quot;password&quot;&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;dejavu sans mono&amp;quot;;&quot;&gt;&lt;span style=&quot;font-size: 11.3pt;&quot;&gt;));&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: red; font-family: &amp;quot;dejavu sans mono&amp;quot;; font-size: 11.3pt;&quot;&gt;&lt;b&gt;
&lt;/b&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style=&quot;background-color: white;&quot;&gt;&lt;span style=&quot;color: red; font-family: &amp;quot;dejavu sans mono&amp;quot;; font-size: 11.3pt;&quot;&gt;&lt;b&gt;//Building a HttpClient for the start of the communication.&lt;/b&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style=&quot;background-color: white;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;dejavu sans mono&amp;quot;;&quot;&gt;&lt;span style=&quot;font-size: 11.3pt;&quot;&gt;CloseableHttpClient client = HttpClients.&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;dejavu sans mono&amp;quot;; font-size: 11.3pt; font-style: italic;&quot;&gt;custom&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;dejavu sans mono&amp;quot;;&quot;&gt;&lt;span style=&quot;font-size: 11.3pt;&quot;&gt;()
        .setDefaultCredentialsProvider(credsProvider)
        .build();&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style=&quot;background-color: white;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;dejavu sans mono&amp;quot;;&quot;&gt;&lt;span style=&quot;font-size: 11.3pt;&quot;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: red; font-family: &amp;quot;dejavu sans mono&amp;quot;; font-size: 11.3pt;&quot;&gt;&lt;b&gt;//Setting up the request to the server. get ip and port from the&lt;/b&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style=&quot;background-color: white; font-family: &amp;quot;DejaVu Sans Mono&amp;quot;; font-size: 11.3pt;&quot;&gt;&lt;span style=&quot;color: red;&quot;&gt;&lt;b&gt;//~/.bitcoin/bitcoin.conf.&lt;/b&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style=&quot;background-color: white; font-family: &amp;quot;DejaVu Sans Mono&amp;quot;; font-size: 11.3pt;&quot;&gt;&lt;span style=&quot;color: red;&quot;&gt;&lt;b&gt;
&lt;/b&gt;&lt;/span&gt;HttpPost request = &lt;span style=&quot;color: navy; font-weight: bold;&quot;&gt;new &lt;/span&gt;HttpPost(&lt;span style=&quot;color: green; font-weight: bold;&quot;&gt;&quot;http://127.0.0.1:8332&quot;&lt;/span&gt;);&lt;/pre&gt;
&lt;pre style=&quot;background-color: white; font-family: &amp;quot;DejaVu Sans Mono&amp;quot;; font-size: 11.3pt;&quot;&gt;&lt;/pre&gt;
&lt;pre style=&quot;background-color: white; font-family: &amp;quot;DejaVu Sans Mono&amp;quot;; font-size: 11.3pt;&quot;&gt;&lt;span style=&quot;color: red;&quot;&gt;&lt;b&gt;// no we start with the interesting part:&lt;/b&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style=&quot;background-color: white; font-family: &amp;quot;DejaVu Sans Mono&amp;quot;; font-size: 11.3pt;&quot;&gt;&lt;pre style=&quot;font-family: &amp;quot;DejaVu Sans Mono&amp;quot;; font-size: 11.3pt;&quot;&gt;&lt;span style=&quot;color: navy; font-weight: bold;&quot;&gt;try &lt;/span&gt;{&lt;/pre&gt;
&lt;pre style=&quot;font-family: &amp;quot;DejaVu Sans Mono&amp;quot;; font-size: 11.3pt;&quot;&gt;    &lt;span style=&quot;color: red;&quot;&gt;&lt;b&gt;//This is the most interesting part. Here we setup the &lt;/b&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style=&quot;font-family: &amp;quot;DejaVu Sans Mono&amp;quot;; font-size: 11.3pt;&quot;&gt;&lt;span style=&quot;color: red;&quot;&gt;&lt;b&gt;    //rpc call to the daemon. &lt;/b&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style=&quot;font-family: &amp;quot;DejaVu Sans Mono&amp;quot;; font-size: 11.3pt;&quot;&gt;request.setEntity(&lt;span style=&quot;color: navy; font-weight: bold;&quot;&gt;new &lt;/span&gt;StringEntity(&lt;span style=&quot;color: green; font-weight: bold;&quot;&gt;&quot;{&lt;/span&gt;&lt;span style=&quot;color: navy; font-weight: bold;&quot;&gt;\&quot;&lt;/span&gt;&lt;span style=&quot;color: green; font-weight: bold;&quot;&gt;jsonrpc&lt;/span&gt;&lt;span style=&quot;color: navy; font-weight: bold;&quot;&gt;\&quot;&lt;/span&gt;&lt;span style=&quot;color: green; font-weight: bold;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: navy; font-weight: bold;&quot;&gt;\&quot;&lt;/span&gt;&lt;span style=&quot;color: green; font-weight: bold;&quot;&gt;1.0&lt;/span&gt;&lt;span style=&quot;color: navy; font-weight: bold;&quot;&gt;\&quot; + &lt;/span&gt;&lt;/pre&gt;
&lt;pre style=&quot;font-family: &amp;quot;DejaVu Sans Mono&amp;quot;; font-size: 11.3pt;&quot;&gt;&lt;span style=&quot;color: navy; font-weight: bold;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: green; font-weight: bold;&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: navy; font-weight: bold;&quot;&gt;\&quot;&lt;/span&gt;&lt;span style=&quot;color: green; font-weight: bold;&quot;&gt;id&lt;/span&gt;&lt;span style=&quot;color: navy; font-weight: bold;&quot;&gt;\&quot;&lt;/span&gt;&lt;span style=&quot;color: green; font-weight: bold;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: navy; font-weight: bold;&quot;&gt;\&quot;&lt;/span&gt;&lt;span style=&quot;color: green; font-weight: bold;&quot;&gt;curltext&lt;/span&gt;&lt;span style=&quot;color: navy; font-weight: bold;&quot;&gt;\&quot;&lt;/span&gt;&lt;span style=&quot;color: green; font-weight: bold;&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: navy; font-weight: bold;&quot;&gt;\&quot;&lt;/span&gt;&lt;span style=&quot;color: green; font-weight: bold;&quot;&gt;method&lt;/span&gt;&lt;span style=&quot;color: navy; font-weight: bold;&quot;&gt;\&quot;&lt;/span&gt;&lt;span style=&quot;color: green; font-weight: bold;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: navy; font-weight: bold;&quot;&gt;\&quot;&lt;/span&gt;&lt;span style=&quot;color: green; font-weight: bold;&quot;&gt;getblockchaininfo&lt;/span&gt;&lt;span style=&quot;color: navy; font-weight: bold;&quot;&gt;\&quot;&lt;/span&gt;&lt;span style=&quot;color: green; font-weight: bold;&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: navy; font-weight: bold;&quot;&gt;\&quot;&lt;/span&gt;&lt;span style=&quot;color: green; font-weight: bold;&quot;&gt;params&lt;/span&gt;&lt;span style=&quot;color: navy; font-weight: bold;&quot;&gt;\&quot;&lt;/span&gt;&lt;span style=&quot;color: green; font-weight: bold;&quot;&gt;:[]}&quot;&lt;/span&gt;));&lt;/pre&gt;
&lt;pre style=&quot;font-family: &amp;quot;DejaVu Sans Mono&amp;quot;; font-size: 11.3pt;&quot;&gt;    &lt;span style=&quot;color: red;&quot;&gt;&lt;b&gt;// retrieving the response from the daemon&lt;/b&gt;&lt;/span&gt;
    HttpResponse response = client.execute(request);&lt;/pre&gt;
&lt;pre style=&quot;font-family: &amp;quot;DejaVu Sans Mono&amp;quot;; font-size: 11.3pt;&quot;&gt;    &lt;span style=&quot;color: red;&quot;&gt;&lt;b&gt;// converting the result to a string and print it.&lt;/b&gt;&lt;/span&gt;
    ByteArrayOutputStream byteArrayOutputStream = &lt;/pre&gt;
&lt;pre style=&quot;font-family: &amp;quot;DejaVu Sans Mono&amp;quot;; font-size: 11.3pt;&quot;&gt;&lt;span style=&quot;color: navy; font-weight: bold;&quot;&gt;new &lt;/span&gt;ByteArrayOutputStream();
    response.getEntity().writeTo(byteArrayOutputStream);
    String theString = &lt;span style=&quot;color: navy; font-weight: bold;&quot;&gt;new &lt;/span&gt;String(byteArrayOutputStream.toByteArray());
    log.info(theString);
} &lt;span style=&quot;color: navy; font-weight: bold;&quot;&gt;catch &lt;/span&gt;(UnsupportedEncodingException e) {
    log.error(&lt;span style=&quot;color: green; font-weight: bold;&quot;&gt;&quot;wrong url&quot;&lt;/span&gt;, e);
} &lt;span style=&quot;color: navy; font-weight: bold;&quot;&gt;catch &lt;/span&gt;(ClientProtocolException e) {
    log.error(&lt;span style=&quot;color: green; font-weight: bold;&quot;&gt;&quot;wrong protocol&quot;&lt;/span&gt;, e);
} &lt;span style=&quot;color: navy; font-weight: bold;&quot;&gt;catch &lt;/span&gt;(IOException e) {
    log.error(&lt;span style=&quot;color: green; font-weight: bold;&quot;&gt;&quot;io&quot;&lt;/span&gt;, e);
}&lt;/pre&gt;
&lt;pre style=&quot;font-family: &amp;quot;DejaVu Sans Mono&amp;quot;; font-size: 11.3pt;&quot;&gt;&lt;/pre&gt;
&lt;pre style=&quot;font-family: &amp;quot;DejaVu Sans Mono&amp;quot;; font-size: 11.3pt;&quot;&gt;&lt;/pre&gt;
&lt;/pre&gt;
&lt;pre style=&quot;background-color: white; font-family: &amp;quot;DejaVu Sans Mono&amp;quot;; font-size: 11.3pt; text-align: center;&quot;&gt;&lt;b&gt;Conclusion&lt;/b&gt;&lt;/pre&gt;
&lt;pre style=&quot;background-color: white; font-family: &amp;quot;DejaVu Sans Mono&amp;quot;; font-size: 11.3pt; text-align: center;&quot;&gt;&lt;b&gt;
&lt;/b&gt;&lt;/pre&gt;
&lt;pre style=&quot;background-color: white; font-family: &amp;quot;DejaVu Sans Mono&amp;quot;; font-size: 11.3pt; text-align: left;&quot;&gt;After a day of searching it was blissfully simple. &lt;/pre&gt;
&lt;pre style=&quot;background-color: white; font-family: &amp;quot;DejaVu Sans Mono&amp;quot;; font-size: 11.3pt; text-align: left;&quot;&gt;I enjoyed talking to the legendary bitcoin daemon and &lt;/pre&gt;
&lt;pre style=&quot;background-color: white; font-family: &amp;quot;DejaVu Sans Mono&amp;quot;; font-size: 11.3pt; text-align: left;&quot;&gt;get some information out of it. This is still a simple method.&lt;/pre&gt;
&lt;pre style=&quot;background-color: white; font-family: &amp;quot;DejaVu Sans Mono&amp;quot;; font-size: 11.3pt; text-align: left;&quot;&gt;The daemon has some more complex ones where you also might need some&lt;/pre&gt;
&lt;pre style=&quot;background-color: white; font-family: &amp;quot;DejaVu Sans Mono&amp;quot;; font-size: 11.3pt; text-align: left;&quot;&gt;parameters. At the line of request.setEntity, in the json part there&lt;/pre&gt;
&lt;pre style=&quot;background-color: white; font-family: &amp;quot;DejaVu Sans Mono&amp;quot;; font-size: 11.3pt; text-align: left;&quot;&gt;is also a parameter section. You can address all the parameters there.&lt;/pre&gt;
&lt;pre style=&quot;background-color: white; font-family: &amp;quot;DejaVu Sans Mono&amp;quot;; font-size: 11.3pt; text-align: left;&quot;&gt;Don&#39;t forget too change the method section.&lt;/pre&gt;
&lt;pre style=&quot;background-color: white; font-family: &amp;quot;DejaVu Sans Mono&amp;quot;; font-size: 11.3pt; text-align: left;&quot;&gt;For this see:&lt;/pre&gt;
&lt;pre style=&quot;background-color: white; text-align: left;&quot;&gt;&lt;span style=&quot;font-family: dejavu sans mono;&quot;&gt;&lt;span style=&quot;font-size: 15.0667px;&quot;&gt;https://bitcoin.org/en/release/v0.15.0&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style=&quot;background-color: white; font-family: &amp;quot;DejaVu Sans Mono&amp;quot;; font-size: 11.3pt; text-align: left;&quot;&gt;&lt;/pre&gt;
&lt;pre style=&quot;background-color: white; font-family: &amp;quot;DejaVu Sans Mono&amp;quot;; font-size: 11.3pt; text-align: left;&quot;&gt;Have fun!&lt;/pre&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://pieterroskam.blogspot.com/feeds/3517734322522544938/comments/default' title='Reacties posten'/><link rel='replies' type='text/html' href='http://pieterroskam.blogspot.com/2018/02/rpc-call-to-bitcoind.html#comment-form' title='0 reacties'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2919956819843973860/posts/default/3517734322522544938'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2919956819843973860/posts/default/3517734322522544938'/><link rel='alternate' type='text/html' href='http://pieterroskam.blogspot.com/2018/02/rpc-call-to-bitcoind.html' title='rpc call to bitcoind'/><author><name>java by experience</name><uri>http://www.blogger.com/profile/07404653852761857615</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2919956819843973860.post-624171598071692075</id><published>2017-08-26T14:58:00.000-07:00</published><updated>2017-08-27T04:52:34.722-07:00</updated><title type='text'>spring boot service with Kotlin</title><content type='html'>&lt;span style=&quot;font-family: &amp;quot;arial&amp;quot; , &amp;quot;helvetica&amp;quot; , sans-serif;&quot;&gt;Introduction&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;arial&amp;quot; , &amp;quot;helvetica&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &amp;quot;arial&amp;quot; , &amp;quot;helvetica&amp;quot; , sans-serif;&quot;&gt;Kotlin is a fairly new programming language orignally developed by jetbrains and these days supported on android by Google. Also since spring 5.0 is it possible to write kotlin programs in spring &amp;nbsp;(also spring boot applications). Kotlin runs on the jvm and is easily compatible with excisting java classes. &amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;arial&amp;quot; , &amp;quot;helvetica&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &amp;quot;arial&amp;quot; , &amp;quot;helvetica&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &amp;quot;arial&amp;quot; , &amp;quot;helvetica&amp;quot; , sans-serif;&quot;&gt;The jvm it runs on at the moment I am writing this, is Java 6. No, dont worry the clever part is, that the team behind Kotlin found ways to make the features up to Java 8 available in te last version of Kotlin (1.1.4). The style of programming is more the kind of functional programming.&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;arial&amp;quot; , &amp;quot;helvetica&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &amp;quot;arial&amp;quot; , &amp;quot;helvetica&amp;quot; , sans-serif;&quot;&gt;Unfortunally I cannot cover Kotlin complete in this post but It will give you a rough Idea How it works and how powerfull it is.&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;arial&amp;quot; , &amp;quot;helvetica&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &amp;quot;arial&amp;quot; , &amp;quot;helvetica&amp;quot; , sans-serif;&quot;&gt;Lets play with some examples:&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;arial&amp;quot; , &amp;quot;helvetica&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &amp;quot;arial&amp;quot; , &amp;quot;helvetica&amp;quot; , sans-serif;&quot;&gt;Example 1: Hello world&lt;/span&gt;&lt;span style=&quot;background-color: white; color: #333333; font-family: &amp;quot;arial&amp;quot; , &amp;quot;helvetica&amp;quot; , sans-serif; font-size: 14px;&quot;&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white; color: #333333; font-family: &amp;quot;arial&amp;quot; , &amp;quot;helvetica&amp;quot; , sans-serif; font-size: 14px;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;pre style=&quot;background-color: white; font-family: &amp;quot;DejaVu Sans Mono&amp;quot;; font-size: 11.3pt;&quot;&gt;&lt;span style=&quot;color: navy; font-weight: bold;&quot;&gt;fun &lt;/span&gt;main(args: Array&amp;lt;String&amp;gt;) {
&lt;span style=&quot;color: green; font-weight: bold;&quot;&gt;    &lt;/span&gt;println(&quot;hello world&quot;)
}&lt;/pre&gt;
&lt;pre style=&quot;background-color: white; font-family: &amp;quot;DejaVu Sans Mono&amp;quot;; font-size: 11.3pt;&quot;&gt;&lt;/pre&gt;
&lt;pre style=&quot;background-color: white; font-family: &amp;quot;DejaVu Sans Mono&amp;quot;; font-size: 11.3pt;&quot;&gt;A view small points that should get our attention:&lt;/pre&gt;
&lt;pre style=&quot;background-color: white; font-family: &amp;quot;DejaVu Sans Mono&amp;quot;; font-size: 11.3pt;&quot;&gt;&lt;/pre&gt;
&lt;pre style=&quot;background-color: white;&quot;&gt;&lt;ol&gt;
&lt;li&gt;&lt;span style=&quot;font-family: &amp;quot;dejavu sans mono&amp;quot;;&quot;&gt;&lt;span style=&quot;font-size: 15.0667px;&quot;&gt;There is no class definition around the main method.&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;font-family: &amp;quot;dejavu sans mono&amp;quot;;&quot;&gt;&lt;span style=&quot;font-size: 15.0667px;&quot;&gt;The declartion of the function is not void but fun&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;font-family: &amp;quot;dejavu sans mono&amp;quot;;&quot;&gt;&lt;span style=&quot;font-size: 15.0667px;&quot;&gt;the args arguments is not an String[] array but an Array type.&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;font-family: &amp;quot;dejavu sans mono&amp;quot;;&quot;&gt;&lt;span style=&quot;font-size: 15.0667px;&quot;&gt;The definition of the args is first the name : type.&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;font-family: &amp;quot;dejavu sans mono&amp;quot;;&quot;&gt;&lt;span style=&quot;font-size: 15.0667px;&quot;&gt;The println() command. In java: &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;arial&amp;quot; , &amp;quot;helvetica&amp;quot; , sans-serif;&quot;&gt;System.out.println()&lt;/span&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;.&lt;/span&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;span style=&quot;font-family: &amp;quot;arial&amp;quot; , &amp;quot;helvetica&amp;quot; , sans-serif;&quot;&gt;in this small example we allready see a lot of differences which actually&lt;/span&gt; 

&lt;div&gt;
&lt;span style=&quot;font-family: &amp;quot;dejavu sans mono&amp;quot;;&quot;&gt;&lt;span style=&quot;font-size: 15.0667px;&quot;&gt;lead to less code lines (lazy programmers like me love that).&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: &amp;quot;dejavu sans mono&amp;quot;;&quot;&gt;&lt;span style=&quot;font-size: 15.0667px;&quot;&gt;The way the &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;dejavu sans mono&amp;quot;; font-size: 15.0667px;&quot;&gt;args types are declared, also goes for the declaration &lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: &amp;quot;dejavu sans mono&amp;quot;; font-size: 15.0667px;&quot;&gt;o&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;dejavu sans mono&amp;quot;; font-size: 15.0667px;&quot;&gt;f the var types some examples:&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: &amp;quot;dejavu sans mono&amp;quot;;&quot;&gt;&lt;span style=&quot;font-size: 15.0667px;&quot;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;pre style=&quot;font-family: &amp;quot;DejaVu Sans Mono&amp;quot;; font-size: 11.3pt;&quot;&gt;&lt;span style=&quot;color: navy; font-weight: bold;&quot;&gt;val &lt;/span&gt;double: Double = &lt;span style=&quot;color: blue;&quot;&gt;10.0 &lt;/span&gt;&lt;span style=&quot;font-style: italic;&quot;&gt;&lt;span style=&quot;color: red;&quot;&gt;// 64 bit&lt;/span&gt;&lt;span style=&quot;color: grey;&quot;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: navy; font-weight: bold;&quot;&gt;val &lt;/span&gt;float: Float = &lt;span style=&quot;color: blue;&quot;&gt;10.0F &lt;/span&gt;&lt;span style=&quot;color: grey; font-style: italic;&quot;&gt;/&lt;/span&gt;&lt;span style=&quot;font-style: italic;&quot;&gt;&lt;span style=&quot;color: red;&quot;&gt;/ or f, 32 bit&lt;/span&gt;&lt;span style=&quot;color: grey;&quot;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: navy; font-weight: bold;&quot;&gt;val &lt;/span&gt;long: Long = &lt;span style=&quot;color: blue;&quot;&gt;10L &lt;/span&gt;&lt;span style=&quot;font-style: italic;&quot;&gt;&lt;span style=&quot;color: red;&quot;&gt;// 64 bit&lt;/span&gt;&lt;span style=&quot;color: grey;&quot;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: navy; font-weight: bold;&quot;&gt;val &lt;/span&gt;int: Int = &lt;span style=&quot;color: blue;&quot;&gt;10 &lt;/span&gt;&lt;span style=&quot;font-style: italic;&quot;&gt;&lt;span style=&quot;color: red;&quot;&gt;// 32 bit&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: grey; font-style: italic;&quot;&gt;
&lt;/span&gt;&lt;span style=&quot;color: navy; font-weight: bold;&quot;&gt;val &lt;/span&gt;hexadecimal = &lt;span style=&quot;color: blue;&quot;&gt;0x0F &lt;/span&gt;&lt;span style=&quot;font-style: italic;&quot;&gt;&lt;span style=&quot;color: red;&quot;&gt;// Prefix &#39;0x&#39;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style=&quot;font-family: &amp;quot;DejaVu Sans Mono&amp;quot;; font-size: 11.3pt;&quot;&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;val&lt;/span&gt;&lt;span style=&quot;color: red;&quot;&gt; &lt;/span&gt;&lt;/span&gt;binary = 0b01&lt;span style=&quot;color: red;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;font-style: italic;&quot;&gt;&lt;span style=&quot;color: red;&quot;&gt;// Prefix &#39;0b&#39;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: &amp;quot;dejavu sans mono&amp;quot;;&quot;&gt;&lt;span style=&quot;font-size: 15.0667px;&quot;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: &amp;quot;dejavu sans mono&amp;quot;;&quot;&gt;&lt;span style=&quot;font-size: 15.0667px;&quot;&gt;Example 2 calling a java class: &lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: &amp;quot;dejavu sans mono&amp;quot;;&quot;&gt;&lt;span style=&quot;font-size: 15.0667px;&quot;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;color: red; font-family: &amp;quot;dejavu sans mono&amp;quot;;&quot;&gt;&lt;span style=&quot;font-size: 15.0667px;&quot;&gt;// The java class&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;pre style=&quot;font-family: &amp;quot;DejaVu Sans Mono&amp;quot;; font-size: 11.3pt;&quot;&gt;&lt;span style=&quot;color: navy; font-weight: bold;&quot;&gt;public class &lt;/span&gt;Test {

    &lt;span style=&quot;color: navy; font-weight: bold;&quot;&gt;public &lt;/span&gt;String hello() {
        &lt;span style=&quot;color: navy; font-weight: bold;&quot;&gt;return &lt;/span&gt;&lt;span style=&quot;color: green; font-weight: bold;&quot;&gt;&quot;Hello&quot;&lt;/span&gt;;
    }
}&lt;/pre&gt;
&lt;pre style=&quot;font-family: &amp;quot;DejaVu Sans Mono&amp;quot;; font-size: 11.3pt;&quot;&gt;&lt;/pre&gt;
&lt;pre style=&quot;font-family: &amp;quot;DejaVu Sans Mono&amp;quot;; font-size: 11.3pt;&quot;&gt;&lt;span style=&quot;color: red;&quot;&gt;// The Kotlin code:&lt;/span&gt;&lt;/pre&gt;
&lt;pre style=&quot;font-family: &amp;quot;DejaVu Sans Mono&amp;quot;; font-size: 11.3pt;&quot;&gt;&lt;span style=&quot;color: red;&quot;&gt;
&lt;/span&gt;&lt;/pre&gt;
&lt;pre style=&quot;font-family: &amp;quot;DejaVu Sans Mono&amp;quot;; font-size: 11.3pt;&quot;&gt;&lt;span style=&quot;color: red;&quot;&gt;//To declare a var you use var. To declare a constant you use val.&lt;/span&gt;&lt;/pre&gt;
&lt;pre style=&quot;font-family: &amp;quot;DejaVu Sans Mono&amp;quot;; font-size: 11.3pt;&quot;&gt;&lt;span style=&quot;color: red;&quot;&gt;// Here we declare the java class defined above.&lt;/span&gt;&lt;/pre&gt;
&lt;pre style=&quot;font-family: &amp;quot;DejaVu Sans Mono&amp;quot;; font-size: 11.3pt;&quot;&gt;&lt;span style=&quot;color: navy; font-weight: bold;&quot;&gt;var &lt;/span&gt;&lt;span style=&quot;color: #660e7a; font-style: italic;&quot;&gt;test &lt;/span&gt;= Test();

&lt;span style=&quot;color: navy; font-weight: bold;&quot;&gt;fun &lt;/span&gt;main(args:Array&amp;lt;String&amp;gt;) {&lt;/pre&gt;
&lt;pre style=&quot;font-family: &amp;quot;DejaVu Sans Mono&amp;quot;; font-size: 11.3pt;&quot;&gt;    &lt;span style=&quot;color: red;&quot;&gt;//Here we call the hello method declared in the Test class.&lt;/span&gt;
    &lt;span style=&quot;font-style: italic;&quot;&gt;println&lt;/span&gt;(&lt;span style=&quot;color: #660e7a; font-style: italic;&quot;&gt;test&lt;/span&gt;.hello());
}&lt;/pre&gt;
&lt;pre style=&quot;font-family: &amp;quot;DejaVu Sans Mono&amp;quot;; font-size: 11.3pt;&quot;&gt;&lt;/pre&gt;
&lt;pre style=&quot;font-family: &amp;quot;DejaVu Sans Mono&amp;quot;; font-size: 11.3pt;&quot;&gt;Example 3: the spring boot service:&lt;/pre&gt;
&lt;pre style=&quot;font-family: &amp;quot;DejaVu Sans Mono&amp;quot;; font-size: 11.3pt;&quot;&gt;&lt;/pre&gt;
&lt;pre style=&quot;font-family: &amp;quot;DejaVu Sans Mono&amp;quot;; font-size: 11.3pt;&quot;&gt;The best part of this is that the project can be an &lt;/pre&gt;
&lt;pre style=&quot;font-family: &amp;quot;DejaVu Sans Mono&amp;quot;; font-size: 11.3pt;&quot;&gt;maven project as usual or any other build tool you desire.&lt;/pre&gt;
&lt;pre style=&quot;font-family: &amp;quot;DejaVu Sans Mono&amp;quot;; font-size: 11.3pt;&quot;&gt;&lt;/pre&gt;
&lt;pre style=&quot;font-family: &amp;quot;DejaVu Sans Mono&amp;quot;; font-size: 11.3pt;&quot;&gt;&lt;/pre&gt;
&lt;pre style=&quot;font-family: &amp;quot;DejaVu Sans Mono&amp;quot;; font-size: 11.3pt;&quot;&gt;The pom file needs:&lt;/pre&gt;
&lt;pre style=&quot;font-family: &amp;quot;DejaVu Sans Mono&amp;quot;; font-size: 11.3pt;&quot;&gt;&lt;/pre&gt;
&lt;pre style=&quot;font-family: &amp;quot;DejaVu Sans Mono&amp;quot;; font-size: 11.3pt;&quot;&gt;&lt;span style=&quot;background-color: #efefef;&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;background-color: #efefef; color: navy; font-weight: bold;&quot;&gt;parent&lt;/span&gt;&lt;span style=&quot;background-color: #efefef;&quot;&gt;&amp;gt;&lt;/span&gt;
    &lt;span style=&quot;background-color: #efefef;&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;background-color: #efefef; color: navy; font-weight: bold;&quot;&gt;groupId&lt;/span&gt;&lt;span style=&quot;background-color: #efefef;&quot;&gt;&amp;gt;&lt;/span&gt;org.springframework.boot&lt;span style=&quot;background-color: #efefef;&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span style=&quot;background-color: #efefef; color: navy; font-weight: bold;&quot;&gt;groupId&lt;/span&gt;&lt;span style=&quot;background-color: #efefef;&quot;&gt;&amp;gt;&lt;/span&gt;
    &lt;span style=&quot;background-color: #efefef;&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;background-color: #efefef; color: navy; font-weight: bold;&quot;&gt;artifactId&lt;/span&gt;&lt;span style=&quot;background-color: #efefef;&quot;&gt;&amp;gt;&lt;/span&gt;spring-boot-starter-parent&lt;span style=&quot;background-color: #efefef;&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span style=&quot;background-color: #efefef; color: navy; font-weight: bold;&quot;&gt;artifactId&lt;/span&gt;&lt;span style=&quot;background-color: #efefef;&quot;&gt;&amp;gt;&lt;/span&gt;
    &lt;span style=&quot;background-color: #efefef;&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;background-color: #efefef; color: navy; font-weight: bold;&quot;&gt;version&lt;/span&gt;&lt;span style=&quot;background-color: #efefef;&quot;&gt;&amp;gt;&lt;/span&gt;LATEST_VERSION&lt;span style=&quot;background-color: #efefef;&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span style=&quot;background-color: #efefef; color: navy; font-weight: bold;&quot;&gt;version&lt;/span&gt;&lt;span style=&quot;background-color: #efefef;&quot;&gt;&amp;gt;&lt;/span&gt;
&lt;span style=&quot;background-color: #efefef;&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span style=&quot;background-color: #efefef; color: navy; font-weight: bold;&quot;&gt;parent&lt;/span&gt;&lt;span style=&quot;background-color: #efefef;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style=&quot;font-family: &amp;quot;DejaVu Sans Mono&amp;quot;; font-size: 11.3pt;&quot;&gt;&lt;/pre&gt;
&lt;pre style=&quot;font-family: &amp;quot;DejaVu Sans Mono&amp;quot;; font-size: 11.3pt;&quot;&gt;The code looks like follows:&lt;/pre&gt;
&lt;pre style=&quot;font-family: &amp;quot;DejaVu Sans Mono&amp;quot;; font-size: 11.3pt;&quot;&gt;&lt;/pre&gt;
&lt;pre style=&quot;font-family: &amp;quot;DejaVu Sans Mono&amp;quot;; font-size: 11.3pt;&quot;&gt;&lt;span style=&quot;color: red;&quot;&gt;//The main function comparable with what we know from Java.&lt;/span&gt;&lt;/pre&gt;
&lt;pre style=&quot;font-family: &amp;quot;DejaVu Sans Mono&amp;quot;; font-size: 11.3pt;&quot;&gt;&lt;span style=&quot;color: red;&quot;&gt;//The point of interest is that the main function needs to be&lt;/span&gt;&lt;/pre&gt;
&lt;pre style=&quot;font-family: &amp;quot;DejaVu Sans Mono&amp;quot;; font-size: 11.3pt;&quot;&gt;&lt;span style=&quot;color: red;&quot;&gt;//declared outside the class application. Otherwise the method&lt;/span&gt;&lt;/pre&gt;
&lt;pre style=&quot;font-family: &amp;quot;DejaVu Sans Mono&amp;quot;; font-size: 11.3pt;&quot;&gt;&lt;span style=&quot;color: red;&quot;&gt;// will not be seen as a main method.&lt;/span&gt;&lt;/pre&gt;
&lt;pre style=&quot;font-family: &amp;quot;DejaVu Sans Mono&amp;quot;; font-size: 11.3pt;&quot;&gt;&lt;span style=&quot;color: navy; font-weight: bold;&quot;&gt;fun &lt;/span&gt;main(args: Array&amp;lt;String&amp;gt;) {
    SpringApplication.run(Application::&lt;span style=&quot;color: navy; font-weight: bold;&quot;&gt;class&lt;/span&gt;.&lt;span style=&quot;color: #660e7a; font-style: italic;&quot;&gt;java&lt;/span&gt;, *args)
}

&lt;span style=&quot;color: red;&quot;&gt;// The class declaration simular to what we know in Java &lt;/span&gt;&lt;/pre&gt;
&lt;pre style=&quot;font-family: &amp;quot;DejaVu Sans Mono&amp;quot;; font-size: 11.3pt;&quot;&gt;&lt;span style=&quot;color: red;&quot;&gt;//with some small&lt;/span&gt; &lt;span style=&quot;color: red;&quot;&gt;adjustements. By default a class is final&lt;/span&gt;&lt;/pre&gt;
&lt;pre style=&quot;font-family: &amp;quot;DejaVu Sans Mono&amp;quot;; font-size: 11.3pt;&quot;&gt;&lt;span style=&quot;color: red;&quot;&gt;//in Kotlin. To undo this we need the keyword open. Spring Boot&lt;/span&gt;&lt;/pre&gt;
&lt;pre style=&quot;font-family: &amp;quot;DejaVu Sans Mono&amp;quot;; font-size: 11.3pt;&quot;&gt;&lt;span style=&quot;color: red;&quot;&gt;// requires that.&lt;/span&gt;&lt;/pre&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: &amp;quot;dejavu sans mono&amp;quot;; font-size: 11.3pt;&quot;&gt;@SpringBootApplication&lt;/span&gt;&lt;/div&gt;
&lt;pre style=&quot;font-family: &amp;quot;DejaVu Sans Mono&amp;quot;; font-size: 11.3pt;&quot;&gt;&lt;span style=&quot;color: navy; font-weight: bold;&quot;&gt;open class &lt;/span&gt;Application&lt;span style=&quot;color: grey;&quot;&gt;() {&lt;/span&gt;&lt;span style=&quot;color: grey;&quot;&gt;
&lt;/span&gt;&lt;span style=&quot;color: grey;&quot;&gt;}&lt;/span&gt;&lt;span style=&quot;color: grey;&quot;&gt;
&lt;/span&gt;&lt;span style=&quot;color: red;&quot;&gt;// finally the rest controller It has all the characteristics &lt;/span&gt;&lt;/pre&gt;
&lt;pre style=&quot;font-family: &amp;quot;DejaVu Sans Mono&amp;quot;; font-size: 11.3pt;&quot;&gt;&lt;span style=&quot;color: red;&quot;&gt;//I described earlier. Like the fun definition of the function etc.&lt;/span&gt;&lt;/pre&gt;
&lt;pre style=&quot;font-family: &amp;quot;DejaVu Sans Mono&amp;quot;; font-size: 11.3pt;&quot;&gt;&lt;span style=&quot;color: red;&quot;&gt; For the&lt;/span&gt; &lt;span style=&quot;color: red;&quot;&gt;rest it is code as we know it from Spring.&lt;/span&gt;&lt;/pre&gt;
&lt;pre style=&quot;font-family: &amp;quot;DejaVu Sans Mono&amp;quot;; font-size: 11.3pt;&quot;&gt;&lt;span style=&quot;color: navy;&quot;&gt;@RestController&lt;/span&gt;&lt;span style=&quot;color: navy; font-weight: bold;&quot;&gt;class &lt;/span&gt;CustomerController {

    &lt;span style=&quot;color: navy;&quot;&gt;@RequestMapping&lt;/span&gt;(&lt;span style=&quot;color: #4a86e8;&quot;&gt;value =  &lt;/span&gt;&lt;span style=&quot;color: green; font-weight: bold;&quot;&gt;&quot;/test&quot;&lt;/span&gt;)
    &lt;span style=&quot;color: navy; font-weight: bold;&quot;&gt;fun &lt;/span&gt;test(): String {
        &lt;span style=&quot;color: navy; font-weight: bold;&quot;&gt;return   &lt;/span&gt;&lt;span style=&quot;color: green; font-weight: bold;&quot;&gt;&quot;Hello world&quot;&lt;/span&gt;;
    }

}&lt;/pre&gt;
&lt;pre style=&quot;font-family: &amp;quot;DejaVu Sans Mono&amp;quot;; font-size: 11.3pt;&quot;&gt;&lt;/pre&gt;
&lt;pre style=&quot;font-family: &amp;quot;DejaVu Sans Mono&amp;quot;; font-size: 11.3pt;&quot;&gt;To make this example work create an .kt file and&lt;/pre&gt;
&lt;pre style=&quot;font-family: &amp;quot;DejaVu Sans Mono&amp;quot;; font-size: 11.3pt;&quot;&gt;compile it with:&lt;/pre&gt;
&lt;pre style=&quot;font-family: &amp;quot;DejaVu Sans Mono&amp;quot;; font-size: 11.3pt;&quot;&gt; kotlinc your_file.kt -include-runtime -d your_file.jar &lt;/pre&gt;
&lt;pre style=&quot;font-family: &amp;quot;DejaVu Sans Mono&amp;quot;; font-size: 11.3pt;&quot;&gt;and run it with:&lt;/pre&gt;
&lt;pre style=&quot;font-size: 11.3pt;&quot;&gt;&lt;div style=&quot;break-inside: avoid; font-size: 14px; line-height: 22px; margin-bottom: 15px; white-space: pre-wrap; word-wrap: break-word;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;arial&amp;quot; , &amp;quot;helvetica&amp;quot; , sans-serif;&quot;&gt;java -jar your_file.jar&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;break-inside: avoid; font-size: 14px; line-height: 22px; margin-bottom: 15px; white-space: pre-wrap; word-wrap: break-word;&quot;&gt;
Or use an ide that does this kind of work for you (leasy me again)&lt;/div&gt;
&lt;div style=&quot;break-inside: avoid; font-size: 14px; line-height: 22px; margin-bottom: 15px; white-space: pre-wrap; word-wrap: break-word;&quot;&gt;
&lt;/div&gt;
&lt;div style=&quot;break-inside: avoid; font-size: 14px; line-height: 22px; margin-bottom: 15px; white-space: pre-wrap; word-wrap: break-word;&quot;&gt;
Conclusion:&lt;/div&gt;
&lt;div style=&quot;break-inside: avoid; font-size: 14px; line-height: 22px; margin-bottom: 15px; white-space: pre-wrap; word-wrap: break-word;&quot;&gt;
With Kotlin we produce significant less lines of code and still have the power that we used to. Important is that Kotlin has a wide range of support from compagnies and frameworks which make our lives as programmers easier. I hope you will play a bit with it and enjoy it as much As I did. At last but not least I would like to thank Shaun Thomas from Sytac for giving a wonderfull presentation about Kotlin which enlightened me to write this post.&lt;/div&gt;
&lt;div style=&quot;break-inside: avoid; font-size: 14px; line-height: 22px; margin-bottom: 15px; white-space: pre-wrap; word-wrap: break-word;&quot;&gt;
Have fun!&lt;/div&gt;
&lt;/pre&gt;
&lt;/div&gt;
&lt;/pre&gt;
</content><link rel='replies' type='application/atom+xml' href='http://pieterroskam.blogspot.com/feeds/624171598071692075/comments/default' title='Reacties posten'/><link rel='replies' type='text/html' href='http://pieterroskam.blogspot.com/2017/08/spring-boot-service-with-kotlin.html#comment-form' title='0 reacties'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2919956819843973860/posts/default/624171598071692075'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2919956819843973860/posts/default/624171598071692075'/><link rel='alternate' type='text/html' href='http://pieterroskam.blogspot.com/2017/08/spring-boot-service-with-kotlin.html' title='spring boot service with Kotlin'/><author><name>java by experience</name><uri>http://www.blogger.com/profile/07404653852761857615</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2919956819843973860.post-8990049880937772926</id><published>2016-07-13T13:26:00.000-07:00</published><updated>2016-07-13T13:26:10.952-07:00</updated><title type='text'>autocomplete with javascript</title><content type='html'>&lt;div style=&quot;text-align: center;&quot;&gt;
&lt;b&gt;introduction&lt;/b&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
Every now and then as a java programmer you run into a java script piece. I have to admit that java script and myself are not good friends for ages now. Every time I have to do something with java script I cry in silence. &amp;nbsp;So I started a nice Java project to work out some java script stuff and see If I could deal with it (call me a masochist). One of the things that kept me wandering around for a while was how to build a autocomplete that &amp;nbsp;calls a service. I found a lot of examples with prefab list. After digging around a lot I found an example that connected to a service. It was not working so i started trying and finally i got it working.&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: center;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: center;&quot;&gt;
&lt;b&gt;The solution&lt;/b&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: center;&quot;&gt;
&lt;span style=&quot;color: red;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;color: red;&quot;&gt;//jquery libraries needed.&lt;/span&gt;&lt;/div&gt;
&lt;pre style=&quot;background-color: white; font-family: &amp;quot;DejaVu Sans Mono&amp;quot;; font-size: 9pt;&quot;&gt;&lt;span style=&quot;background-color: #efefef;&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;background-color: #efefef; color: navy; font-weight: bold;&quot;&gt;script &lt;/span&gt;&lt;span style=&quot;background-color: #efefef; color: blue; font-weight: bold;&quot;&gt;src=&lt;/span&gt;&lt;span style=&quot;background-color: #efefef; color: green; font-weight: bold;&quot;&gt;&quot;&lt;/span&gt;&lt;span style=&quot;background-color: #f7faff;&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;background-color: #f7faff; color: #660e7a; font-weight: bold;&quot;&gt;c&lt;/span&gt;&lt;span style=&quot;background-color: #f7faff; color: navy; font-weight: bold;&quot;&gt;:url &lt;/span&gt;&lt;span style=&quot;background-color: #f7faff; color: blue; font-weight: bold;&quot;&gt;value&lt;/span&gt;&lt;span style=&quot;background-color: #f7faff; color: green; font-weight: bold;&quot;&gt;=&quot;https://code.jquery.com/jquery-3.0.0.min.js&quot; &lt;/span&gt;&lt;span style=&quot;background-color: #f7faff;&quot;&gt;/&amp;gt;&lt;/span&gt;&lt;span style=&quot;background-color: #efefef; color: green; font-weight: bold;&quot;&gt;&quot; &lt;/span&gt;&lt;/pre&gt;
&lt;pre style=&quot;background-color: white; font-family: &amp;quot;DejaVu Sans Mono&amp;quot;; font-size: 9pt;&quot;&gt;&lt;span style=&quot;background-color: #efefef; color: blue; font-weight: bold;&quot;&gt;type=&lt;/span&gt;&lt;span style=&quot;background-color: #efefef; color: green; font-weight: bold;&quot;&gt;&quot;text/javascript&quot;&lt;/span&gt;&lt;span style=&quot;background-color: #efefef;&quot;&gt;&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span style=&quot;background-color: #efefef; color: navy; font-weight: bold;&quot;&gt;script&lt;/span&gt;&lt;span style=&quot;background-color: #efefef;&quot;&gt;&amp;gt;&lt;/span&gt;
&lt;span style=&quot;background-color: #efefef;&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;background-color: #efefef; color: navy; font-weight: bold;&quot;&gt;script &lt;/span&gt;&lt;span style=&quot;background-color: #efefef; color: blue; font-weight: bold;&quot;&gt;src=&lt;/span&gt;&lt;span style=&quot;background-color: #efefef; color: green; font-weight: bold;&quot;&gt;&quot;https://code.jquery.com/ui/1.12.0/jquery-ui.js&quot;&lt;/span&gt;&lt;span style=&quot;background-color: #efefef;&quot;&gt;&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span style=&quot;background-color: #efefef; color: navy; font-weight: bold;&quot;&gt;script&lt;/span&gt;&lt;span style=&quot;background-color: #efefef;&quot;&gt;&amp;gt;&lt;/span&gt;
&lt;span style=&quot;background-color: #efefef;&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;background-color: #efefef; color: navy; font-weight: bold;&quot;&gt;link &lt;/span&gt;&lt;span style=&quot;background-color: #efefef; color: blue; font-weight: bold;&quot;&gt;rel=&lt;/span&gt;&lt;span style=&quot;background-color: #efefef; color: green; font-weight: bold;&quot;&gt;&quot;stylesheet&quot; &lt;/span&gt;&lt;span style=&quot;background-color: #efefef; color: blue; font-weight: bold;&quot;&gt;href=&lt;/span&gt;&lt;span style=&quot;background-color: #efefef; color: green; font-weight: bold;&quot;&gt;&quot;//code.jquery.com/ui/1.12.0/themes/base/&lt;/span&gt;&lt;/pre&gt;
&lt;pre style=&quot;background-color: white; font-family: &amp;quot;DejaVu Sans Mono&amp;quot;; font-size: 9pt;&quot;&gt;&lt;span style=&quot;background-color: #efefef; color: green; font-weight: bold;&quot;&gt;jquery-ui.css&quot;&lt;/span&gt;&lt;span style=&quot;background-color: #efefef;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;color: red;&quot;&gt;// the html label and input that gonna function as autocomplete.&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;color: red;&quot;&gt;// the css class is coming from jquer ui.&amp;nbsp;&lt;/span&gt;&lt;/div&gt;
&lt;pre style=&quot;background-color: white; font-family: &amp;quot;DejaVu Sans Mono&amp;quot;; font-size: 9pt;&quot;&gt;&lt;span style=&quot;background-color: #efefef;&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;background-color: #efefef; color: navy; font-weight: bold;&quot;&gt;div &lt;/span&gt;&lt;span style=&quot;background-color: #efefef; color: blue; font-weight: bold;&quot;&gt;class=&lt;/span&gt;&lt;span style=&quot;background-color: #efefef; color: green; font-weight: bold;&quot;&gt;&quot;ui-widget&quot;&lt;/span&gt;&lt;span style=&quot;background-color: #efefef;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style=&quot;background-color: white; font-family: &amp;quot;DejaVu Sans Mono&amp;quot;; font-size: 9pt;&quot;&gt;&lt;span style=&quot;background-color: #efefef;&quot;&gt;  &amp;lt;&lt;/span&gt;&lt;span style=&quot;background-color: #efefef; color: navy; font-weight: bold;&quot;&gt;td&lt;/span&gt;&lt;span style=&quot;background-color: #efefef;&quot;&gt;&amp;gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;background-color: #efefef; color: navy; font-weight: bold;&quot;&gt;label &lt;/span&gt;&lt;span style=&quot;background-color: #efefef; color: blue; font-weight: bold;&quot;&gt;for=&lt;/span&gt;&lt;span style=&quot;background-color: #efefef; color: green; font-weight: bold;&quot;&gt;&quot;autocompleteChars&quot;&lt;/span&gt;&lt;span style=&quot;background-color: #efefef;&quot;&gt;&amp;gt;&lt;/span&gt;Autocomplete: &lt;span style=&quot;background-color: #efefef;&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span style=&quot;background-color: #efefef; color: navy; font-weight: bold;&quot;&gt;label&lt;/span&gt;&lt;span style=&quot;background-color: #efefef;&quot;&gt;&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span style=&quot;background-color: #efefef; color: navy; font-weight: bold;&quot;&gt;td&lt;/span&gt;&lt;span style=&quot;background-color: #efefef;&quot;&gt;&amp;gt;&lt;/span&gt;
&lt;span style=&quot;background-color: #efefef;&quot;&gt;  &amp;lt;&lt;/span&gt;&lt;span style=&quot;background-color: #efefef; color: navy; font-weight: bold;&quot;&gt;td&lt;/span&gt;&lt;span style=&quot;background-color: #efefef;&quot;&gt;&amp;gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;background-color: #efefef; color: navy; font-weight: bold;&quot;&gt;input &lt;/span&gt;&lt;span style=&quot;background-color: #efefef; color: blue; font-weight: bold;&quot;&gt;id=&lt;/span&gt;&lt;span style=&quot;background-color: #efefef; color: green; font-weight: bold;&quot;&gt;&quot;autocompleteChars&quot;&lt;/span&gt;&lt;span style=&quot;background-color: #efefef;&quot;&gt;&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span style=&quot;background-color: #efefef; color: navy; font-weight: bold;&quot;&gt;td&lt;/span&gt;&lt;span style=&quot;background-color: #efefef;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style=&quot;background-color: white; font-family: &amp;quot;DejaVu Sans Mono&amp;quot;; font-size: 9pt;&quot;&gt;&lt;span style=&quot;background-color: #efefef;&quot;&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;div style=&quot;text-align: center;&quot;&gt;
&lt;b&gt;&lt;span style=&quot;color: red;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;color: red;&quot;&gt;&lt;b&gt;// &lt;/b&gt;The array that is gonna contain the service result.&lt;/span&gt;&lt;/div&gt;
&lt;pre style=&quot;background-color: white; font-family: &amp;quot;DejaVu Sans Mono&amp;quot;; font-size: 9pt;&quot;&gt;&lt;span style=&quot;color: navy; font-weight: bold;&quot;&gt;var &lt;/span&gt;&lt;span style=&quot;color: #660e7a; font-style: italic; font-weight: bold;&quot;&gt;autoCompleteContent&lt;/span&gt;;
&lt;span style=&quot;color: #660e7a; font-weight: bold;&quot;&gt;$&lt;/span&gt;( &lt;span style=&quot;color: navy; font-weight: bold;&quot;&gt;function&lt;/span&gt;() {&lt;/pre&gt;
&lt;pre style=&quot;background-color: white; font-family: &amp;quot;DejaVu Sans Mono&amp;quot;; font-size: 9pt;&quot;&gt;    &lt;span style=&quot;color: red;&quot;&gt;//coupling the autocomplete to the html input.&lt;/span&gt;
    &lt;span style=&quot;color: #660e7a; font-weight: bold;&quot;&gt;$&lt;/span&gt;(&lt;span style=&quot;color: green; font-weight: bold;&quot;&gt;&quot;#autocompleteChars&quot;&lt;/span&gt;).&lt;span style=&quot;color: #660e7a; font-weight: bold;&quot;&gt;autocomplete&lt;/span&gt;({
        &lt;span style=&quot;color: #7a7a43;&quot;&gt;source&lt;/span&gt;: &lt;span style=&quot;color: navy; font-weight: bold;&quot;&gt;function&lt;/span&gt;( request, response ) {
            &lt;span style=&quot;color: #660e7a; font-weight: bold;&quot;&gt;$&lt;/span&gt;.&lt;span style=&quot;color: #7a7a43;&quot;&gt;post&lt;/span&gt;({
                        &lt;span style=&quot;color: #660e7a; font-weight: bold;&quot;&gt;url&lt;/span&gt;: &lt;span style=&quot;color: green; font-weight: bold;&quot;&gt;&quot;&amp;lt;the url to the service&amp;gt;&quot; &lt;/span&gt;&lt;/pre&gt;
&lt;pre style=&quot;background-color: white; font-family: &amp;quot;DejaVu Sans Mono&amp;quot;; font-size: 9pt;&quot;&gt;+ &lt;span style=&quot;color: #660e7a; font-weight: bold;&quot;&gt;document&lt;/span&gt;.&lt;span style=&quot;color: #7a7a43;&quot;&gt;getElementById&lt;/span&gt;(&lt;span style=&quot;color: green; font-weight: bold;&quot;&gt;&#39;autocompleteChars&#39;&lt;/span&gt;).&lt;span style=&quot;color: #660e7a; font-weight: bold;&quot;&gt;value&lt;/span&gt;,
                        &lt;span style=&quot;color: #660e7a; font-weight: bold;&quot;&gt;dataType&lt;/span&gt;: &lt;span style=&quot;color: green; font-weight: bold;&quot;&gt;&quot;json&quot;&lt;/span&gt;,&lt;/pre&gt;
&lt;pre style=&quot;background-color: white; font-family: &amp;quot;DejaVu Sans Mono&amp;quot;; font-size: 9pt;&quot;&gt;                        // &lt;span style=&quot;color: red;&quot;&gt;if the request was successfull.&lt;/span&gt;
                        &lt;span style=&quot;color: #7a7a43;&quot;&gt;success&lt;/span&gt;: &lt;span style=&quot;color: navy; font-weight: bold;&quot;&gt;function&lt;/span&gt;( data ) {
                            response( &lt;span style=&quot;color: #660e7a; font-weight: bold;&quot;&gt;$&lt;/span&gt;.&lt;span style=&quot;color: #7a7a43;&quot;&gt;map&lt;/span&gt;( data, &lt;span style=&quot;color: navy; font-weight: bold;&quot;&gt;function&lt;/span&gt;( item ) {&lt;/pre&gt;
&lt;pre style=&quot;background-color: white; font-family: &amp;quot;DejaVu Sans Mono&amp;quot;; font-size: 9pt;&quot;&gt;
&lt;/pre&gt;
&lt;pre style=&quot;background-color: white; font-family: &amp;quot;DejaVu Sans Mono&amp;quot;; font-size: 9pt;&quot;&gt;                                &lt;span style=&quot;color: red;&quot;&gt;//reïnitializing the array to empty the previous.&lt;/span&gt;&lt;/pre&gt;
&lt;pre style=&quot;background-color: white; font-family: &amp;quot;DejaVu Sans Mono&amp;quot;; font-size: 9pt;&quot;&gt;                                &lt;span style=&quot;color: #660e7a; font-style: italic; font-weight: bold;&quot;&gt;autoCompleteContent &lt;/span&gt;= &lt;span style=&quot;color: navy; font-weight: bold;&quot;&gt;new &lt;/span&gt;Array();&lt;/pre&gt;
&lt;pre style=&quot;background-color: white; font-family: &amp;quot;DejaVu Sans Mono&amp;quot;; font-size: 9pt;&quot;&gt;                                &lt;span style=&quot;color: red;&quot;&gt;//looping through the results from the service.&lt;/span&gt; 
                                &lt;span style=&quot;color: navy; font-weight: bold;&quot;&gt;for&lt;/span&gt;(&lt;span style=&quot;color: #660e7a; font-weight: bold;&quot;&gt;index&lt;/span&gt;=&lt;span style=&quot;color: blue;&quot;&gt;0&lt;/span&gt;; &lt;span style=&quot;color: #660e7a; font-weight: bold;&quot;&gt;index&lt;/span&gt;&amp;lt;item.&lt;span style=&quot;color: #660e7a; font-weight: bold;&quot;&gt;length&lt;/span&gt;; &lt;span style=&quot;color: #660e7a; font-weight: bold;&quot;&gt;index&lt;/span&gt;++) {&lt;/pre&gt;
&lt;pre style=&quot;background-color: white; font-family: &amp;quot;DejaVu Sans Mono&amp;quot;; font-size: 9pt;&quot;&gt;                                    &lt;span style=&quot;color: red;&quot;&gt;//creating the layout of an autocomplet line.&lt;/span&gt;
                                    &lt;span style=&quot;color: navy; font-weight: bold;&quot;&gt;var &lt;/span&gt;&lt;span style=&quot;color: #458383;&quot;&gt;autoComplete &lt;/span&gt;=  item[&lt;span style=&quot;color: #660e7a; font-weight: bold;&quot;&gt;index&lt;/span&gt;][&lt;span style=&quot;color: green; font-weight: bold;&quot;&gt;&#39;element1&#39;&lt;/span&gt;] &lt;/pre&gt;
&lt;pre style=&quot;background-color: white; font-family: &amp;quot;DejaVu Sans Mono&amp;quot;; font-size: 9pt;&quot;&gt;                                     + &lt;span style=&quot;color: green; font-weight: bold;&quot;&gt;&#39;  &#39; &lt;/span&gt;+ item[&lt;span style=&quot;color: #660e7a; font-weight: bold;&quot;&gt;index&lt;/span&gt;][&lt;span style=&quot;color: green; font-weight: bold;&quot;&gt;&#39;element2&#39;&lt;/span&gt;];&lt;/pre&gt;
&lt;pre style=&quot;background-color: white; font-family: &amp;quot;DejaVu Sans Mono&amp;quot;; font-size: 9pt;&quot;&gt;                                    &lt;span style=&quot;color: red;&quot;&gt;// adding it to the array&lt;/span&gt;
                                    &lt;span style=&quot;color: #660e7a; font-style: italic; font-weight: bold;&quot;&gt;autoCompleteContent&lt;/span&gt;.&lt;span style=&quot;color: #7a7a43;&quot;&gt;push&lt;/span&gt;(&lt;span style=&quot;color: #458383;&quot;&gt;autoComplete&lt;/span&gt;);
                                }&lt;/pre&gt;
&lt;pre style=&quot;background-color: white; font-family: &amp;quot;DejaVu Sans Mono&amp;quot;; font-size: 9pt;&quot;&gt;                                &lt;span style=&quot;color: red;&quot;&gt;//return the list as desired to the html input.&lt;/span&gt;
                                &lt;span style=&quot;color: navy; font-weight: bold;&quot;&gt;return &lt;/span&gt;&lt;span style=&quot;color: #660e7a; font-style: italic; font-weight: bold;&quot;&gt;autoCompleteContent&lt;/span&gt;;
                            }));
                        }
                    })&lt;/pre&gt;
&lt;pre style=&quot;background-color: white; font-family: &amp;quot;DejaVu Sans Mono&amp;quot;; font-size: 9pt;&quot;&gt;                     &lt;span style=&quot;color: red;&quot;&gt;// if the request fails.&lt;/span&gt;
                    .&lt;span style=&quot;font-style: italic;&quot;&gt;fail&lt;/span&gt;(&lt;span style=&quot;color: navy; font-weight: bold;&quot;&gt;function&lt;/span&gt;(response) {
                        &lt;span style=&quot;color: #7a7a43;&quot;&gt;console.log&lt;/span&gt;(&lt;span style=&quot;color: green; font-weight: bold;&quot;&gt;&#39;Error: &#39; &lt;/span&gt;+ response.&lt;span style=&quot;color: #660e7a; font-weight: bold;&quot;&gt;responseText&lt;/span&gt;);
                    });
        },
        &lt;span style=&quot;color: #660e7a; font-weight: bold;&quot;&gt;minLength&lt;/span&gt;: &lt;span style=&quot;color: blue;&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;    &lt;/span&gt;});
});&lt;/pre&gt;
&lt;pre style=&quot;background-color: white; font-family: &amp;quot;DejaVu Sans Mono&amp;quot;; font-size: 9pt;&quot;&gt;
&lt;/pre&gt;
&lt;pre style=&quot;background-color: white; font-family: &amp;quot;DejaVu Sans Mono&amp;quot;; font-size: 9pt; text-align: center;&quot;&gt;&lt;b&gt;Conclusion&lt;/b&gt;&lt;/pre&gt;
&lt;pre style=&quot;background-color: white; font-family: &amp;quot;DejaVu Sans Mono&amp;quot;; font-size: 9pt; text-align: center;&quot;&gt;&lt;b&gt;
&lt;/b&gt;&lt;/pre&gt;
&lt;pre style=&quot;background-color: white; font-family: &amp;quot;DejaVu Sans Mono&amp;quot;; font-size: 9pt; text-align: left;&quot;&gt;The prove I found in fighting this little piece of code was that I found out&lt;/pre&gt;
&lt;pre style=&quot;background-color: white; font-family: &amp;quot;DejaVu Sans Mono&amp;quot;; font-size: 9pt; text-align: left;&quot;&gt; that I am still the plumber in the backend. I just love building stuff in &lt;/pre&gt;
&lt;pre style=&quot;background-color: white; font-family: &amp;quot;DejaVu Sans Mono&amp;quot;; font-size: 9pt; text-align: left;&quot;&gt;the backend &lt;span style=&quot;font-size: 9pt;&quot;&gt;and sometimes just popup at the frontend to do a trick or two but &lt;/span&gt;&lt;/pre&gt;
&lt;pre style=&quot;background-color: white; font-family: &amp;quot;DejaVu Sans Mono&amp;quot;; font-size: 9pt; text-align: left;&quot;&gt;&lt;span style=&quot;font-size: 9pt;&quot;&gt;to move silently back again. &lt;/span&gt;&lt;span style=&quot;font-size: 9pt;&quot;&gt;I am happy that I finished this piece and made &lt;/span&gt;&lt;/pre&gt;
&lt;pre style=&quot;background-color: white; font-family: &amp;quot;DejaVu Sans Mono&amp;quot;; font-size: 9pt; text-align: left;&quot;&gt;&lt;span style=&quot;font-size: 9pt;&quot;&gt;it work. &lt;/span&gt;&lt;span style=&quot;font-size: 9pt;&quot;&gt;There are many ways to rome &lt;/span&gt;&lt;span style=&quot;font-size: 9pt;&quot;&gt;even in the javascript world.&lt;/span&gt;&lt;/pre&gt;
&lt;pre style=&quot;background-color: white; font-family: &amp;quot;DejaVu Sans Mono&amp;quot;; font-size: 9pt; text-align: left;&quot;&gt;&lt;span style=&quot;font-size: 9pt;&quot;&gt;You find some of those roads by google. But with the most &lt;/span&gt;&lt;span style=&quot;font-size: 9pt;&quot;&gt;of them you never get &lt;/span&gt;&lt;/pre&gt;
&lt;pre style=&quot;background-color: white; font-family: &amp;quot;DejaVu Sans Mono&amp;quot;; font-size: 9pt; text-align: left;&quot;&gt;&lt;span style=&quot;font-size: 9pt;&quot;&gt;to Rome. &lt;/span&gt;&lt;span style=&quot;font-size: 9pt;&quot;&gt;I hope that I can help some other java developers with this, &lt;/span&gt;&lt;span style=&quot;font-size: 9pt;&quot;&gt;that just &lt;/span&gt;&lt;/pre&gt;
&lt;pre style=&quot;background-color: white; font-family: &amp;quot;DejaVu Sans Mono&amp;quot;; font-size: 9pt; text-align: left;&quot;&gt;&lt;span style=&quot;font-size: 9pt;&quot;&gt;as me, &lt;/span&gt;&lt;span style=&quot;font-size: 9pt;&quot;&gt;allways struggle with javascript.&lt;/span&gt;&lt;/pre&gt;
&lt;pre style=&quot;background-color: white; font-family: &amp;quot;DejaVu Sans Mono&amp;quot;; font-size: 9pt; text-align: left;&quot;&gt;
&lt;/pre&gt;
&lt;pre style=&quot;background-color: white; font-family: &amp;quot;DejaVu Sans Mono&amp;quot;; font-size: 9pt; text-align: left;&quot;&gt;Have fun!&lt;/pre&gt;
&lt;pre style=&quot;background-color: white; font-family: &amp;quot;DejaVu Sans Mono&amp;quot;; font-size: 9pt;&quot;&gt;
&lt;/pre&gt;
</content><link rel='replies' type='application/atom+xml' href='http://pieterroskam.blogspot.com/feeds/8990049880937772926/comments/default' title='Reacties posten'/><link rel='replies' type='text/html' href='http://pieterroskam.blogspot.com/2016/07/autocomplete-with-javascript.html#comment-form' title='0 reacties'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2919956819843973860/posts/default/8990049880937772926'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2919956819843973860/posts/default/8990049880937772926'/><link rel='alternate' type='text/html' href='http://pieterroskam.blogspot.com/2016/07/autocomplete-with-javascript.html' title='autocomplete with javascript'/><author><name>java by experience</name><uri>http://www.blogger.com/profile/07404653852761857615</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2919956819843973860.post-7576723266228281816</id><published>2016-06-21T07:53:00.001-07:00</published><updated>2016-06-21T07:55:47.708-07:00</updated><title type='text'>Alternative implementation of an Interface with lambda</title><content type='html'>&lt;div style=&quot;text-align: center;&quot;&gt;
&lt;b&gt;Introduction&lt;/b&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: center;&quot;&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
Normally to have an implementation of an Interface is extra work&amp;nbsp;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;/div&gt;
&lt;ol&gt;
&lt;li&gt;Create a class&lt;/li&gt;
&lt;li&gt;Implement the Interface&lt;/li&gt;
&lt;li&gt;Implementing the&amp;nbsp;&amp;nbsp;method(s)&lt;/li&gt;
&lt;/ol&gt;
&lt;div&gt;
I always thought of this as the boring part except implementing the method(s)&lt;/div&gt;
&amp;nbsp;So I was fooling a bit around with Lambda&#39;s in Java and figured a way of interface implementation without creating an extra class for it. I thought that this way might be nice when the implementation of the Interface happens &amp;nbsp;only ones. Like in Spring when you use Inversion of Control.&lt;br /&gt;
&lt;div&gt;
Lets have a look at how it could be done with Lambda&#39;s&lt;br /&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: center;&quot;&gt;
&lt;b&gt;The solution to the problem&lt;/b&gt;&amp;nbsp;&lt;/div&gt;
&lt;div style=&quot;text-align: center;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
First of all you create the Interface:&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;pre style=&quot;background-color: white; font-family: &amp;quot;Courier New&amp;quot;; font-size: 12.8px; white-space: pre-wrap;&quot;&gt;&lt;span style=&quot;color: navy; font-weight: bold;&quot;&gt;public interface &lt;/span&gt;WorkerInterface {
  &lt;span style=&quot;color: red;&quot;&gt;//The method to implement&lt;/span&gt; &lt;/pre&gt;
&lt;pre style=&quot;background-color: white; font-family: &amp;quot;Courier New&amp;quot;; font-size: 12.8px; white-space: pre-wrap;&quot;&gt;  &lt;span style=&quot;color: navy; font-weight: bold;&quot;&gt;void &lt;/span&gt;doSomeWork();
}&lt;/pre&gt;
&lt;pre style=&quot;background-color: white; font-family: &amp;quot;Courier New&amp;quot;; font-size: 12.8px; white-space: pre-wrap;&quot;&gt;&lt;/pre&gt;
&lt;pre style=&quot;background-color: white; font-family: &amp;quot;Courier New&amp;quot;; font-size: 12.8px; white-space: pre-wrap;&quot;&gt;&lt;/pre&gt;
&lt;pre style=&quot;background-color: white; font-family: &amp;quot;Courier New&amp;quot;; font-size: 12.8px; white-space: pre-wrap;&quot;&gt;Secondary the class that is having the interface and the implemented method:&lt;/pre&gt;
&lt;pre style=&quot;background-color: white; font-family: &amp;quot;Courier New&amp;quot;; font-size: 12.8px; white-space: pre-wrap;&quot;&gt;&lt;/pre&gt;
&lt;pre style=&quot;background-color: white;&quot;&gt;&lt;pre style=&quot;font-family: &amp;quot;Courier New&amp;quot;; font-size: 12.8px; white-space: pre-wrap;&quot;&gt;&lt;span style=&quot;color: navy; font-weight: bold;&quot;&gt;public class &lt;/span&gt;LambdaTest {&lt;/pre&gt;
&lt;pre style=&quot;font-family: &amp;quot;Courier New&amp;quot;; font-size: 12.8px; white-space: pre-wrap;&quot;&gt;    &lt;span style=&quot;color: red;&quot;&gt;//The method that executes the Interfaces method.&lt;/span&gt;
    &lt;span style=&quot;color: navy; font-weight: bold;&quot;&gt;private void &lt;/span&gt;execute(WorkerInterface worker) {
        worker.doSomeWork();
    }

    &lt;span style=&quot;color: red;&quot;&gt;//Just the plain old main to start up this class.&lt;/span&gt;
    &lt;span style=&quot;color: navy; font-weight: bold;&quot;&gt;public static void &lt;/span&gt;main(String [] args) {
        LambdaTest lambdaTest = &lt;span style=&quot;color: navy; font-weight: bold;&quot;&gt;new &lt;/span&gt;LambdaTest();
        lambdaTest.run();
    }

    &lt;span style=&quot;color: navy; font-weight: bold;&quot;&gt;private void &lt;/span&gt;run() {&lt;/pre&gt;
&lt;pre style=&quot;font-family: &amp;quot;Courier New&amp;quot;; font-size: 12.8px; white-space: pre-wrap;&quot;&gt;        &lt;span style=&quot;color: red;&quot;&gt;//A list with names to start this examples&lt;/span&gt;
        List&amp;lt;String&amp;gt; names = &lt;span style=&quot;color: navy; font-weight: bold;&quot;&gt;new &lt;/span&gt;ArrayList&amp;lt;&amp;gt;();
        names.add(&lt;span style=&quot;color: green; font-weight: bold;&quot;&gt;&quot;Test1&quot;&lt;/span&gt;);
        names.add(&lt;span style=&quot;color: green; font-weight: bold;&quot;&gt;&quot;Test2&quot;&lt;/span&gt;);
        names.add(&lt;span style=&quot;color: green; font-weight: bold;&quot;&gt;&quot;Test3&quot;&lt;/span&gt;);&lt;/pre&gt;
&lt;pre style=&quot;font-family: &amp;quot;Courier New&amp;quot;; font-size: 12.8px; white-space: pre-wrap;&quot;&gt;        &lt;span style=&quot;color: red;&quot;&gt;//The lambda way to do a for loop&lt;/span&gt;&lt;/pre&gt;
&lt;pre style=&quot;font-family: &amp;quot;Courier New&amp;quot;; font-size: 12.8px; white-space: pre-wrap;&quot;&gt;&lt;span style=&quot;color: red;&quot;&gt;        //With the first arrow you assign name to the execute method.&lt;/span&gt;&lt;/pre&gt;
&lt;pre style=&quot;font-family: &amp;quot;Courier New&amp;quot;; font-size: 12.8px; white-space: pre-wrap;&quot;&gt;         names.forEach(name -&amp;gt;&lt;/pre&gt;
&lt;pre style=&quot;font-family: &amp;quot;Courier New&amp;quot;; font-size: 12.8px; white-space: pre-wrap;&quot;&gt;&lt;span style=&quot;color: red;&quot;&gt;        //With the second arrow you assign the execute method.&lt;/span&gt;&lt;/pre&gt;
&lt;pre style=&quot;font-family: &amp;quot;Courier New&amp;quot;; font-size: 12.8px; white-space: pre-wrap;&quot;&gt;&lt;span style=&quot;color: red; font-family: &amp;quot;courier new&amp;quot;; font-size: 12.8px; white-space: pre-wrap;&quot;&gt;        // to the implementation you had in mind.&lt;/span&gt;&lt;/pre&gt;
&lt;pre style=&quot;font-family: &amp;quot;Courier New&amp;quot;; font-size: 12.8px; white-space: pre-wrap;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot;; font-size: 12.8px; white-space: pre-wrap;&quot;&gt;&lt;span style=&quot;color: red;&quot;&gt;        &lt;/span&gt;execute( () -&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style=&quot;font-family: &amp;quot;Courier New&amp;quot;; font-size: 12.8px; white-space: pre-wrap;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot;; font-size: 12.8px; white-space: pre-wrap;&quot;&gt;       System.&lt;/span&gt;&lt;span style=&quot;color: #660e7a; font-family: &amp;quot;courier new&amp;quot;; font-size: 12.8px; font-style: italic; font-weight: bold; white-space: pre-wrap;&quot;&gt;out&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot;; font-size: 12.8px; white-space: pre-wrap;&quot;&gt;.println(name) ));
    }
}

&lt;/span&gt;&lt;div style=&quot;text-align: center;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot;; font-size: 12.8px; white-space: pre-wrap;&quot;&gt;&lt;b&gt;Conclusion&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot;; font-size: 12.8px; white-space: pre-wrap;&quot;&gt;&lt;b&gt;
&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot;;&quot;&gt;&lt;span style=&quot;font-size: 12.8px; white-space: pre-wrap;&quot;&gt;As you can see this works quite easy. By using a double assignment one assign the data to the execute method and the other to assign the execute method to the implementation, it is possible to make an Interface method execute something without an extra class file. &lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot;;&quot;&gt;&lt;span style=&quot;font-size: 12.8px; white-space: pre-wrap;&quot;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot;;&quot;&gt;&lt;span style=&quot;font-size: 12.8px; white-space: pre-wrap;&quot;&gt;Have fun!&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot;; font-size: 12.8px; white-space: pre-wrap;&quot;&gt;
&lt;/span&gt;&lt;/pre&gt;
&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://pieterroskam.blogspot.com/feeds/7576723266228281816/comments/default' title='Reacties posten'/><link rel='replies' type='text/html' href='http://pieterroskam.blogspot.com/2016/06/alternative-implementation-of-interface.html#comment-form' title='0 reacties'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2919956819843973860/posts/default/7576723266228281816'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2919956819843973860/posts/default/7576723266228281816'/><link rel='alternate' type='text/html' href='http://pieterroskam.blogspot.com/2016/06/alternative-implementation-of-interface.html' title='Alternative implementation of an Interface with lambda'/><author><name>java by experience</name><uri>http://www.blogger.com/profile/07404653852761857615</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2919956819843973860.post-7785298520927944150</id><published>2016-01-31T04:04:00.000-08:00</published><updated>2016-01-31T04:04:07.746-08:00</updated><title type='text'>Apache HttpClient connect</title><content type='html'>&lt;div style=&quot;text-align: center;&quot;&gt;
&lt;b&gt;Introduction&lt;/b&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: center;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;b&gt;&amp;nbsp;&lt;/b&gt;As sometimes needed you want one service to communicate with the other without interference of the frontend. One of the ways to do that is to setup a connection through the apache httpClient. In our project we allready did that but with an old version of te HttpClient. Therefore we needed to upgrade to the latest version. At this point in time it is 4.5.1. The only downside of this client is, that it is still not upgraded to HTTP 2.0. &lt;a href=&quot;https://hc.apache.org/httpcomponents-client-ga/&quot; target=&quot;_blank&quot;&gt;read the specs here&lt;/a&gt;. But we did it anyway in the hope that the coming version would use the&lt;a href=&quot;https://en.wikipedia.org/wiki/HTTP/2&quot; target=&quot;_blank&quot;&gt; HTTP 2.0 &lt;/a&gt;specifications.&amp;nbsp;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: center;&quot;&gt;
&lt;b&gt;The solutution&lt;/b&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: center;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
This solution is not giving you the whole shabang&amp;nbsp;&lt;b&gt; &lt;/b&gt;but it gives you a good idea howto setup a basic configuration that works and will help you to setup through a proxy or not.&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;color: red;&quot;&gt;//The maven part:&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&amp;lt;dependency&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;groupId&amp;gt;org.apache.httpcomponents&amp;lt;/groupId&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;artifactId&amp;gt;httpclient&amp;lt;/artifactId&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;version&amp;gt;4.5.1&amp;lt;/version&amp;gt;&lt;br /&gt;&amp;lt;/dependency&amp;gt;&lt;br /&gt;&amp;lt;dependency&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;groupId&amp;gt;org.apache.httpcomponents&amp;lt;/groupId&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;artifactId&amp;gt;httpcore&amp;lt;/artifactId&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;version&amp;gt;4.4.4&amp;lt;/version&amp;gt;&lt;br /&gt;&amp;lt;/dependency&amp;gt;&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;color: red;&quot;&gt;&lt;b&gt;//&lt;/b&gt;If you in need of a proxy set it up like this with ofcourse the right adress and&amp;nbsp;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;color: red;&quot;&gt;//port.&lt;b&gt; &lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;pre style=&quot;background-color: white; color: black; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt;&lt;a href=&quot;https://hc.apache.org/httpcomponents-core-ga/httpcore/apidocs/org/apache/http/HttpHost.html&quot; target=&quot;_blank&quot;&gt;HttpHost&lt;/a&gt; proxy = &lt;span style=&quot;color: navy; font-weight: bold;&quot;&gt;new &lt;/span&gt;HttpHost(&lt;span style=&quot;color: green; font-weight: bold;&quot;&gt;&quot;proxy&quot;&lt;/span&gt;, &lt;span style=&quot;color: blue;&quot;&gt;8080&lt;/span&gt;, &lt;span style=&quot;color: green; font-weight: bold;&quot;&gt;&quot;http&quot;&lt;/span&gt;);
&lt;span style=&quot;color: red;&quot;&gt;// Configure the request with timeouts and in this case a proxy.&amp;nbsp;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style=&quot;background-color: white; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt;&lt;span style=&quot;color: orange;&quot;&gt;&lt;span style=&quot;color: red;&quot;&gt;//If you don&#39;t need a proxy you can leave that particular part ou&lt;/span&gt;t &lt;/span&gt;&lt;/pre&gt;
&lt;pre style=&quot;background-color: white; color: black; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt;&lt;a href=&quot;https://hc.apache.org/httpcomponents-client-ga/httpclient/apidocs/org/apache/http/client/config/RequestConfig.html&quot; target=&quot;_blank&quot;&gt;RequestConfig&lt;/a&gt; config = RequestConfig.&lt;span style=&quot;font-style: italic;&quot;&gt;custom&lt;/span&gt;()
        .setConnectionRequestTimeout(&lt;span style=&quot;color: blue;&quot;&gt;3&lt;wbr&gt;&lt;/wbr&gt;0000&lt;/span&gt;)
        .setSocketTimeout(&lt;span style=&quot;color: blue;&quot;&gt;30000&lt;/span&gt;)
        .setProxy(proxy)
        .build();&lt;/pre&gt;
&lt;pre style=&quot;background-color: white; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt;&lt;span style=&quot;color: red;&quot;&gt;//Instead of using the HttpMethod in the old version we now&amp;nbsp;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style=&quot;background-color: white; color: black; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt;&lt;span style=&quot;color: red;&quot;&gt;//should use the &lt;a href=&quot;https://hc.apache.org/httpcomponents-client-ga/httpclient/apidocs/org/apache/http/client/methods/HttpGet.html&quot; target=&quot;_blank&quot;&gt;HttpGet&lt;/a&gt; or the &lt;a href=&quot;https://hc.apache.org/httpcomponents-client-ga/httpclient/apidocs/org/apache/http/client/methods/HttpPost.html&quot; target=&quot;_blank&quot;&gt;HttpPost&lt;/a&gt; &lt;/span&gt;HttpGet httpget =&amp;nbsp;&lt;/pre&gt;
&lt;pre style=&quot;background-color: white; color: black; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt;&lt;span style=&quot;color: navy; font-weight: bold;&quot;&gt;new &lt;/span&gt;HttpGet(&lt;span style=&quot;color: green; font-weight: bold;&quot;&gt;&quot;&lt;a href=&quot;http://yourservice/getEverything&quot; target=&quot;_blank&quot;&gt;http://yourservice/&lt;wbr&gt;&lt;/wbr&gt;getEverything&lt;/a&gt;&quot;&lt;/span&gt;);
httpget.setConfig(config);&lt;/pre&gt;
&lt;pre style=&quot;background-color: white; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt;&lt;span style=&quot;color: red;&quot;&gt;//This is one of the ways to setup a HttpClient.&lt;/span&gt;&lt;/pre&gt;
&lt;pre style=&quot;background-color: white; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt;&lt;span style=&quot;color: red;&quot;&gt;//there are many more ways as you will find in these &lt;a href=&quot;https://hc.apache.org/httpcomponents-client-ga/examples.html&quot; target=&quot;_blank&quot;&gt;examples&lt;/a&gt;. &lt;/span&gt;&lt;/pre&gt;
&lt;pre style=&quot;background-color: white; color: black; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt;HttpClient client = HttpClientBuilder.&lt;span style=&quot;font-style: italic;&quot;&gt;create&lt;/span&gt;()
        .build();&lt;/pre&gt;
&lt;pre style=&quot;background-color: white; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt;&lt;span style=&quot;color: red;&quot;&gt;// retrieving the response as &lt;a href=&quot;https://hc.apache.org/httpcomponents-core-ga/httpcore/apidocs/org/apache/http/HttpResponse.html&quot; target=&quot;_blank&quot;&gt;HttpResponse&lt;/a&gt; and printout&lt;/span&gt;&lt;/pre&gt;
&lt;pre style=&quot;background-color: white; color: black; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt;&lt;span style=&quot;color: red;&quot;&gt;//the http status&lt;/span&gt;HttpResponse response = client.execute(httpget);
System.&lt;span style=&quot;color: #660e7a; font-style: italic; font-weight: bold;&quot;&gt;out&lt;/span&gt;.println(response.&lt;wbr&gt;&lt;/wbr&gt;getStatusLine());&lt;/pre&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: center;&quot;&gt;
&lt;b&gt;Conclusion&lt;/b&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
It is not so hard to set this up once you have an idea of what you need to do. I been searching the internet for a some examples. The sad story of this search was that there a lot of old examples out there. I only hope that this library is soon updated to http 2.0.&lt;b&gt; &lt;/b&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://pieterroskam.blogspot.com/feeds/7785298520927944150/comments/default' title='Reacties posten'/><link rel='replies' type='text/html' href='http://pieterroskam.blogspot.com/2016/01/apache-httpclient-connect.html#comment-form' title='0 reacties'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2919956819843973860/posts/default/7785298520927944150'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2919956819843973860/posts/default/7785298520927944150'/><link rel='alternate' type='text/html' href='http://pieterroskam.blogspot.com/2016/01/apache-httpclient-connect.html' title='Apache HttpClient connect'/><author><name>java by experience</name><uri>http://www.blogger.com/profile/07404653852761857615</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2919956819843973860.post-9012565151319412672</id><published>2016-01-13T12:24:00.000-08:00</published><updated>2016-01-13T14:32:43.928-08:00</updated><title type='text'>retrieve the end date from a certificate</title><content type='html'>&lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;text-align: center;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: center;&quot;&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&amp;nbsp;&lt;b&gt;Introduction&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: center;&quot;&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;This week we had a really nice challenge. As most companies we use certificates. They help us to keep the connections secure. The downside of certificates is that they need to be renewed now and then. It is so easy to notice an expired certificate by undesirable behaviour of the connection. If this happens&amp;nbsp; your already to late. To be ahead of this, we decided to do a check up on this particular certificate.&amp;nbsp;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: center;&quot;&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;b&gt;The solution&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;To start of all you need an object of the type &lt;a href=&quot;https://docs.oracle.com/javase/7/docs/api/java/security/cert/Certificate.html&quot; target=&quot;_blank&quot;&gt;Certificate. &lt;/a&gt;In this mather I start with an certificate, &lt;/span&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;span class=&quot;short_text&quot; id=&quot;result_box&quot; lang=&quot;en&quot;&gt;&lt;span class=&quot;hps&quot;&gt;which needed to be read&lt;/span&gt; &lt;span class=&quot;hps&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;hps&quot;&gt;disk&lt;/span&gt;&lt;/span&gt;:&amp;nbsp; &amp;nbsp; &lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;span style=&quot;color: red;&quot;&gt;//Take the file from disk as an inputStream using the classloader for this.&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;InputStream inputStream = this.getClass().getClassLoader().getResourceAsStream(&quot;testCertificate/testCertificate.pem&quot;);&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;br /&gt;&lt;span style=&quot;color: red;&quot;&gt;//getting the &lt;a href=&quot;https://docs.oracle.com/javase/7/docs/api/java/security/cert/CertificateFactory.html&quot; target=&quot;_blank&quot;&gt;CertificateFactory&lt;/a&gt; of the type x.509&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;span style=&quot;color: red;&quot;&gt;//(&lt;a href=&quot;https://docs.oracle.com/javase/7/docs/api/java/security/cert/X509Certificate.html&quot; target=&quot;_blank&quot;&gt;X509Certificate&lt;/a&gt; is the only child of &lt;a href=&quot;https://docs.oracle.com/javase/7/docs/api/java/security/cert/Certificate.html&quot; target=&quot;_blank&quot;&gt;Certificate&lt;/a&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;CertificateFactory certFactory = CertificateFactory.getInstance(&quot;X.509&quot;);&lt;br /&gt;Certificate certificate = certFactory.generateCertificate(inputStream);&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;span style=&quot;color: red;&quot;&gt;// setting up the keystore with an default type. You can also use:&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;table border=&quot;0&quot; cellpadding=&quot;3&quot; cellspacing=&quot;0&quot; class=&quot;overviewSummary&quot; summary=&quot;Method Summary table, listing methods, and an explanation&quot;&gt;&lt;tbody&gt;
&lt;tr class=&quot;rowColor&quot;&gt;&lt;td class=&quot;colLast&quot;&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;span style=&quot;color: red;&quot;&gt;&lt;code&gt;&lt;b&gt;//getInstance&lt;/b&gt;(String&amp;nbsp;type,Provider&amp;nbsp;provider) &lt;/code&gt;&lt;/span&gt;&lt;/span&gt;&lt;/td&gt;&lt;td class=&quot;colLast&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;altColor&quot;&gt;&lt;td class=&quot;colFirst&quot;&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;span style=&quot;color: red;&quot;&gt;&lt;code&gt;&lt;b&gt;//getInstance&lt;/b&gt;(String&amp;nbsp;type,
           String&amp;nbsp;provider)&lt;/code&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;span style=&quot;color: red;&quot;&gt;&lt;code&gt;// &lt;/code&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: red;&quot;&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;Type could be pkcs12 or jks&lt;/span&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;code&gt;&lt;b&gt; &lt;/b&gt;&lt;/code&gt;these are archive file formats for storing many //cryptography objects as a single file.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: red;&quot;&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;// types could be SUN or bc (bouncy castle). &lt;/span&gt;&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;a href=&quot;https://docs.oracle.com/javase/7/docs/api/java/security/KeyStore.html&quot; target=&quot;_blank&quot;&gt;KeyStore&lt;/a&gt; keyStore = KeyStore.getInstance(KeyStore.getDefaultType());&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;color: red;&quot;&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;//adding the certificate to the keystore with an alias&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;keyStore.setCertificateEntry(&quot;alias&quot;, certificate);&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;color: red;&quot;&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;// creating the date object outside the scope of the try we can return it later.&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;Date notAfter = null;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;try {&lt;br /&gt;&lt;span style=&quot;color: red;&quot;&gt;&amp;nbsp; // initializing the keystore with null to prevent exceptions to be thrown later on.&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&amp;nbsp; keyStore.load(null);&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;br /&gt;&lt;span style=&quot;color: red;&quot;&gt;//checking if the keystore has an alias and retrieve the first one.&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;color: red;&quot;&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;&amp;nbsp;//(we only have one). If you know the alias you can loose this piece of code. &lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if(keyStore.aliases().hasMoreElements()) {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Enumeration&amp;lt;String&amp;gt; aliasses = keyStore.aliases();&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; String alias = aliasses.nextElement();&amp;nbsp;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;color: red;&quot;&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;// cast it to the &lt;/span&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;a href=&quot;https://docs.oracle.com/javase/7/docs/api/java/security/cert/X509Certificate.html&quot; target=&quot;_blank&quot;&gt;X509Certificate&lt;/a&gt; That has the getNotAfter method. &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: red;&quot;&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;span style=&quot;color: red;&quot;&gt;&lt;a href=&quot;https://docs.oracle.com/javase/7/docs/api/java/security/cert/Certificate.html&quot; target=&quot;_blank&quot;&gt;Certificate&lt;/a&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;color: red;&quot;&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;span style=&quot;color: red;&quot;&gt;//doesn&#39;t have that.&lt;/span&gt;&lt;/span&gt; &lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;X509Certificate certificate = (X509Certificate) keyStore.getCertificate(alias);&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;color: red;&quot;&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;&amp;nbsp;// assigning the date to the end date of the certificate.&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;notAfter = certificate.getNotAfter();&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;} catch (KeyStoreException ke) {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; log.error(&quot;could not read keystore or certificate&quot;, ke);&lt;br /&gt;} catch (CertificateException ce) {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; log.error(&quot;no certifications in keystore&quot;, ce);&lt;br /&gt;} catch (NoSuchAlgorithmException nse) {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; log.error(&quot;wrong algorythm for certificate.&quot;, nse);&lt;br /&gt;} catch (IOException ioe) {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; log.error(&quot;could not read certificate.&quot;, ioe);&lt;br /&gt;} &lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;color: red;&quot;&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;// returning the end date.&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;return notAfter;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: center;&quot;&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;b&gt;Conclusion&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;To understand what is happening in this particular piece of code acquires some time and dedication. The fun part starts when you understand it. I still enjoy the moments where I crack a case like this and understand why it is needed to&amp;nbsp; be done like this. I hope you enjoy it also.&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;b&gt; &lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;Have fun!&lt;/span&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://pieterroskam.blogspot.com/feeds/9012565151319412672/comments/default' title='Reacties posten'/><link rel='replies' type='text/html' href='http://pieterroskam.blogspot.com/2016/01/retrieve-end-date-from-certificate.html#comment-form' title='0 reacties'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2919956819843973860/posts/default/9012565151319412672'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2919956819843973860/posts/default/9012565151319412672'/><link rel='alternate' type='text/html' href='http://pieterroskam.blogspot.com/2016/01/retrieve-end-date-from-certificate.html' title='retrieve the end date from a certificate'/><author><name>java by experience</name><uri>http://www.blogger.com/profile/07404653852761857615</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2919956819843973860.post-3188326072059141579</id><published>2016-01-12T12:56:00.000-08:00</published><updated>2016-01-12T13:07:48.855-08:00</updated><title type='text'>testing log statements</title><content type='html'>&lt;div style=&quot;text-align: center;&quot;&gt;
&lt;b&gt;Introduction&lt;/b&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: center;&quot;&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
Testing can sometimes make your head spin. For example when a method is a void and you are not allowed to use powermock.&amp;nbsp;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
The thing with a method like that, is that it is not returning an Object on which you can test on.&amp;nbsp;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
If you are lucky it might have a parameter that changes during the execution of the method.&amp;nbsp;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
Sometimes it has a log statement based on a Exception or on an event captured in an if statement, that happened during execution.&amp;nbsp;&amp;nbsp;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
That gives also opportunities. Let me show how.&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: center;&quot;&gt;
&lt;b&gt;The solution&lt;/b&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;b&gt;&amp;nbsp; &lt;/b&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
For working with log files the best thing to do is approach them with log appenders.&amp;nbsp;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;color: red;&quot;&gt;//We start with a mock appender:&amp;nbsp; &lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;pre style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;&lt;pre style=&quot;font-family: &#39;Courier New&#39;;&quot;&gt;&lt;span style=&quot;color: olive;&quot;&gt;&lt;span style=&quot;color: red;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;@&lt;/span&gt;&lt;/span&gt;Mock&lt;/span&gt;&lt;span style=&quot;color: navy; font-weight: bold;&quot;&gt;private &lt;/span&gt;Appender &lt;span style=&quot;color: #660e7a; font-weight: bold;&quot;&gt;mockAppender&lt;/span&gt;;&lt;/pre&gt;
&lt;pre style=&quot;font-family: &#39;Courier New&#39;;&quot;&gt;&lt;span style=&quot;color: red;&quot;&gt;//Creating a rootlogger to hold all the appenders.&lt;/span&gt; &lt;/pre&gt;
&lt;pre style=&quot;font-family: &#39;Courier New&#39;;&quot;&gt;ch.qos.logback.classic.Logger root =&amp;nbsp;&lt;/pre&gt;
&lt;pre style=&quot;font-family: &#39;Courier New&#39;;&quot;&gt;(ch.qos.logback.classic.&lt;wbr&gt;&lt;/wbr&gt;Logger) LoggerFactory.&lt;span style=&quot;font-style: italic;&quot;&gt;getLogger&lt;/span&gt;&amp;nbsp;&lt;/pre&gt;
&lt;pre style=&quot;font-family: &#39;Courier New&#39;;&quot;&gt;(ch.&lt;wbr&gt;&lt;/wbr&gt;qos.logback.classic.Logger.&lt;span style=&quot;color: #660e7a; font-style: italic; font-weight: bold;&quot;&gt;ROO&lt;wbr&gt;&lt;/wbr&gt;T_LOGGER_NAME&lt;/span&gt;);&lt;/pre&gt;
&amp;nbsp;
&lt;pre style=&quot;font-family: &#39;Courier New&#39;;&quot;&gt;&amp;nbsp;&lt;span style=&quot;color: red;&quot;&gt;// appending the &lt;/span&gt;&lt;a href=&quot;https://mockito.googlecode.com/hg-history/1.6/javadoc/org/mockito/ArgumentMatcher.html&quot; target=&quot;_blank&quot;&gt;ArgumentMatcher&lt;/a&gt;&lt;span style=&quot;color: red;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: red;&quot;&gt; to the mockAppender.&lt;/span&gt; &lt;/pre&gt;
&lt;pre style=&quot;font-family: &#39;Courier New&#39;;&quot;&gt;&lt;pre style=&quot;font-family: &#39;Courier New&#39;;&quot;&gt;Mockito.&lt;span style=&quot;font-style: italic;&quot;&gt;verify&lt;/span&gt;(&lt;span style=&quot;color: #660e7a; font-weight: bold;&quot;&gt;mockAppender&lt;/span&gt;).&lt;wbr&gt;&lt;/wbr&gt;doAppend(Mockito.&lt;span style=&quot;font-style: italic;&quot;&gt;argThat&lt;/span&gt;&amp;nbsp;&lt;/pre&gt;
&lt;pre style=&quot;font-family: &#39;Courier New&#39;;&quot;&gt;(&lt;span style=&quot;color: navy; font-weight: bold;&quot;&gt;new &lt;/span&gt;&lt;a href=&quot;https://mockito.googlecode.com/hg-history/1.6/javadoc/org/mockito/ArgumentMatcher.html&quot; target=&quot;_blank&quot;&gt;ArgumentMatcher&lt;/a&gt;&amp;lt;Object&amp;gt;() {&lt;span style=&quot;color: olive;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style=&quot;font-family: &#39;Courier New&#39;;&quot;&gt;&lt;span style=&quot;color: red;&quot;&gt;//implementing the matches method to see if the&lt;/span&gt;&lt;/pre&gt;
&lt;pre style=&quot;font-family: &#39;Courier New&#39;;&quot;&gt;&lt;span style=&quot;color: olive;&quot;&gt;&lt;span style=&quot;color: red;&quot;&gt;// log text appears in the log file&lt;/span&gt; &lt;/span&gt;&lt;/pre&gt;
&lt;pre style=&quot;font-family: &#39;Courier New&#39;;&quot;&gt;&lt;span style=&quot;color: olive;&quot;&gt;@Override&lt;/span&gt;&lt;span style=&quot;color: navy; font-weight: bold;&quot;&gt;public boolean &lt;/span&gt;matches(&lt;span style=&quot;color: navy; font-weight: bold;&quot;&gt;final &lt;/span&gt;Object argument) {
&lt;span style=&quot;color: navy; font-weight: bold;&quot;&gt;return &lt;/span&gt;((LoggingEvent) argument).getFormattedMessage(&lt;wbr&gt;&lt;/wbr&gt;)&lt;/pre&gt;
&lt;pre style=&quot;font-family: &#39;Courier New&#39;;&quot;&gt;&lt;span style=&quot;color: red;&quot;&gt;//The text we want to search.&lt;/span&gt; &lt;/pre&gt;
&lt;pre style=&quot;font-family: &#39;Courier New&#39;;&quot;&gt;.contains(&lt;span style=&quot;color: green; font-weight: bold;&quot;&gt;&quot;test logging text that should be found&quot;&lt;/span&gt;);}}));&lt;/pre&gt;
&amp;nbsp;
&lt;/pre&gt;
&lt;/pre&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: center;&quot;&gt;
&lt;b&gt;The conclusion&lt;/b&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
Void methods could be still a call for an asperine when it comes to testing. There are some helpful methods I believe that this is one of them. I used it this time to test a method that checked if an certificate was expired. This way I could pump up the test coverage of my code.&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
Have fun!&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&amp;nbsp; &lt;/div&gt;
&lt;pre style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;&lt;pre style=&quot;font-family: &#39;Courier New&#39;;&quot;&gt;&lt;/pre&gt;
&lt;/pre&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://pieterroskam.blogspot.com/feeds/3188326072059141579/comments/default' title='Reacties posten'/><link rel='replies' type='text/html' href='http://pieterroskam.blogspot.com/2016/01/testing-log-statements.html#comment-form' title='0 reacties'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2919956819843973860/posts/default/3188326072059141579'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2919956819843973860/posts/default/3188326072059141579'/><link rel='alternate' type='text/html' href='http://pieterroskam.blogspot.com/2016/01/testing-log-statements.html' title='testing log statements'/><author><name>java by experience</name><uri>http://www.blogger.com/profile/07404653852761857615</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2919956819843973860.post-2216903216918000570</id><published>2015-12-18T14:57:00.003-08:00</published><updated>2016-01-25T12:44:05.275-08:00</updated><title type='text'>A bit of Reflection</title><content type='html'>&lt;h4 style=&quot;text-align: center;&quot;&gt;
Introduction&lt;/h4&gt;
In all the years I have been programming one of the dullest things I found to do was writing and maintaining converters. I had a couple of discussion about the subject. The point that always came up as a defence to not use bean mappers like Dozer was the fact that they used Reflection under the hood. I agree up to some level that the use of Reflection in production code should not be used in production code. The interesting point is that most of the third party libraries are using Reflection under the hood. Every library that uses Annotations for example are using it. Think about Spring, all the JPA libraries, log4j, Junit etc...&lt;br /&gt;
So why not for something like bean mapping. So lets see if we can build one our selfs.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;h4 style=&quot;text-align: center;&quot;&gt;
The solution&lt;/h4&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
A bean mapper is meant to&amp;nbsp; copy values from one bean to the other. So what you need to accomplish this is to know the field names of the &quot;other&quot; bean.&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&amp;nbsp;The solution is actually not that complicated What I did was create a couple of Annotations and a handler.&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
If the field names are different you can pass the name of the fields in the &quot;other&quot; bean by using an annotation. &lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
The Annotations look like this:&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;color: red;&quot;&gt;//The rentention policy tells when this Annotation should be used.&lt;/span&gt;&lt;/div&gt;
&lt;pre style=&quot;background-color: white; color: black; font-family: &#39;DejaVu Sans Mono&#39;; font-size: 9.0pt;&quot;&gt;&lt;span style=&quot;color: olive;&quot;&gt;@Retention&lt;/span&gt;(RetentionPolicy.&lt;span style=&quot;color: #660e7a; font-style: italic; font-weight: bold;&quot;&gt;RUNTIME&lt;/span&gt;)&lt;/pre&gt;
&lt;pre style=&quot;background-color: white; color: black; font-family: &#39;DejaVu Sans Mono&#39;; font-size: 9.0pt;&quot;&gt;&lt;span style=&quot;color: red;&quot;&gt;//The target tells where the annation should be placed. In this case field only.&lt;/span&gt;
&lt;span style=&quot;color: olive;&quot;&gt;@Target&lt;/span&gt;(ElementType.&lt;span style=&quot;color: #660e7a; font-style: italic; font-weight: bold;&quot;&gt;FIELD&lt;/span&gt;)
&lt;span style=&quot;color: navy; font-weight: bold;&quot;&gt;public &lt;/span&gt;@&lt;span style=&quot;color: navy; font-weight: bold;&quot;&gt;interface &lt;/span&gt;&lt;span style=&quot;color: olive;&quot;&gt;Copy &lt;/span&gt;{&lt;/pre&gt;
&lt;pre style=&quot;background-color: white; color: black; font-family: &#39;DejaVu Sans Mono&#39;; font-size: 9.0pt;&quot;&gt;&lt;span style=&quot;color: red;&quot;&gt;    // the string that contains the value given to the Annotation.&lt;/span&gt;
    &lt;span style=&quot;color: navy; font-weight: bold;&quot;&gt;public &lt;/span&gt;String copyTo();

}&lt;/pre&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
If the field names are the same you can do it without an annotation.&amp;nbsp;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
I show that later.&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
If you dont want the fields to be copied you can use simply another annotation that prevents the field to be part of the copy process:&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;pre style=&quot;background-color: white; color: black; font-family: &#39;DejaVu Sans Mono&#39;; font-size: 9.0pt;&quot;&gt;&lt;span style=&quot;color: olive;&quot;&gt;@Retention&lt;/span&gt;(RetentionPolicy.&lt;span style=&quot;color: #660e7a; font-style: italic; font-weight: bold;&quot;&gt;RUNTIME&lt;/span&gt;)
&lt;span style=&quot;color: olive;&quot;&gt;@Target&lt;/span&gt;(ElementType.&lt;span style=&quot;color: #660e7a; font-style: italic; font-weight: bold;&quot;&gt;FIELD&lt;/span&gt;)
&lt;span style=&quot;color: navy; font-weight: bold;&quot;&gt;public &lt;/span&gt;@&lt;span style=&quot;color: navy; font-weight: bold;&quot;&gt;interface &lt;/span&gt;&lt;span style=&quot;color: olive;&quot;&gt;IgnoreCopy &lt;/span&gt;{
}&lt;/pre&gt;
&lt;pre style=&quot;background-color: white; color: black; font-family: &#39;DejaVu Sans Mono&#39;; font-size: 9.0pt;&quot;&gt;&lt;/pre&gt;
&lt;pre style=&quot;background-color: white; color: black; font-family: &#39;DejaVu Sans Mono&#39;; font-size: 9.0pt;&quot;&gt;The annotation in use look something like this:&lt;/pre&gt;
&lt;pre style=&quot;background-color: white; color: black; font-family: &#39;DejaVu Sans Mono&#39;; font-size: 9.0pt;&quot;&gt;&lt;/pre&gt;
&lt;pre style=&quot;background-color: white; color: black; font-family: &#39;DejaVu Sans Mono&#39;; font-size: 9.0pt;&quot;&gt;&lt;span style=&quot;color: red;&quot;&gt;// copying with a different field name&lt;/span&gt;&lt;/pre&gt;
&lt;pre style=&quot;background-color: white; color: black; font-family: &#39;DejaVu Sans Mono&#39;; font-size: 9.0pt;&quot;&gt;&lt;span style=&quot;color: olive;&quot;&gt;@Copy&lt;/span&gt;(copyTo = &lt;span style=&quot;color: green; font-weight: bold;&quot;&gt;&quot;testString2&quot;&lt;/span&gt;)
&lt;span style=&quot;color: navy; font-weight: bold;&quot;&gt;private &lt;/span&gt;String &lt;span style=&quot;color: #660e7a; font-weight: bold;&quot;&gt;testString&lt;/span&gt;;
&lt;span style=&quot;color: red;&quot;&gt;// copying wit the same fieldname&lt;/span&gt;
&lt;span style=&quot;color: navy; font-weight: bold;&quot;&gt;private &lt;/span&gt;String &lt;span style=&quot;color: #660e7a; font-weight: bold;&quot;&gt;testStringNoAnnotation&lt;/span&gt;;&lt;/pre&gt;
&lt;pre style=&quot;background-color: white; color: black; font-family: &#39;DejaVu Sans Mono&#39;; font-size: 9.0pt;&quot;&gt;&lt;span style=&quot;color: red;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style=&quot;background-color: white; color: black; font-family: &#39;DejaVu Sans Mono&#39;; font-size: 9.0pt;&quot;&gt;&lt;span style=&quot;color: red;&quot;&gt;should not be copied.&lt;/span&gt;
&lt;span style=&quot;color: olive;&quot;&gt;@IgnoreCopy&lt;/span&gt;&lt;span style=&quot;color: navy; font-weight: bold;&quot;&gt;private &lt;/span&gt;String &lt;span style=&quot;color: #660e7a; font-weight: bold;&quot;&gt;notToCopy&lt;/span&gt;;&lt;/pre&gt;
&lt;pre style=&quot;background-color: white; color: black; font-family: &#39;DejaVu Sans Mono&#39;; font-size: 9.0pt;&quot;&gt;&lt;/pre&gt;
&lt;pre style=&quot;background-color: white; color: black; font-family: &#39;DejaVu Sans Mono&#39;; font-size: 9.0pt;&quot;&gt;&lt;/pre&gt;
&lt;pre style=&quot;background-color: white; color: black; font-family: &#39;DejaVu Sans Mono&#39;; font-size: 9.0pt;&quot;&gt;To copy the values first of all you need the fields of the bean to copy from:&lt;/pre&gt;
&lt;pre style=&quot;background-color: white; color: black; font-family: &#39;DejaVu Sans Mono&#39;; font-size: 9.0pt;&quot;&gt;&lt;span style=&quot;color: red;&quot;&gt;//Use the getDeclaredFields instead of the getFields. Otherwise you can&#39;t find&amp;nbsp;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style=&quot;background-color: white; color: black; font-family: &#39;DejaVu Sans Mono&#39;; font-size: 9.0pt;&quot;&gt;&lt;span style=&quot;color: red;&quot;&gt;//the field you are searching for. &lt;/span&gt;&lt;/pre&gt;
&lt;pre style=&quot;background-color: white; color: black; font-family: &#39;DejaVu Sans Mono&#39;; font-size: 9.0pt;&quot;&gt;Field[] fields = copyFrom.getClass().getDeclaredFields();&lt;/pre&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;color: red;&quot;&gt;//looping through the fields to find the annotation if needed.&lt;/span&gt;&lt;/div&gt;
&lt;pre style=&quot;background-color: white; color: black; font-family: &#39;DejaVu Sans Mono&#39;; font-size: 9.0pt;&quot;&gt;&lt;span style=&quot;color: navy; font-weight: bold;&quot;&gt;for&lt;/span&gt;(Field field : fields) {&lt;/pre&gt;
&lt;pre style=&quot;background-color: white; color: black; font-family: &#39;DejaVu Sans Mono&#39;; font-size: 9.0pt;&quot;&gt;    &lt;span style=&quot;color: red;&quot;&gt;//The annotation if the field names are different.&lt;/span&gt;
    &lt;span style=&quot;color: olive;&quot;&gt;Copy &lt;/span&gt;copy = field.getAnnotation(&lt;span style=&quot;color: olive;&quot;&gt;Copy&lt;/span&gt;.&lt;span style=&quot;color: navy; font-weight: bold;&quot;&gt;class&lt;/span&gt;);&lt;/pre&gt;
&lt;pre style=&quot;background-color: white; color: black; font-family: &#39;DejaVu Sans Mono&#39;; font-size: 9.0pt;&quot;&gt;    &lt;span style=&quot;color: red;&quot;&gt;//The annotation to see if the field shouldn&#39;t be copied.&lt;/span&gt; 
    &lt;span style=&quot;color: olive;&quot;&gt;IgnoreCopy &lt;/span&gt;ignoreCopy = field.getAnnotation(&lt;span style=&quot;color: olive;&quot;&gt;IgnoreCopy&lt;/span&gt;.&lt;span style=&quot;color: navy; font-weight: bold;&quot;&gt;class&lt;/span&gt;);
    &lt;span style=&quot;color: navy; font-weight: bold;&quot;&gt;if&lt;/span&gt;(ignoreCopy == &lt;span style=&quot;color: navy; font-weight: bold;&quot;&gt;null&lt;/span&gt;) {
        &lt;span style=&quot;color: navy; font-weight: bold;&quot;&gt;if &lt;/span&gt;( copy != &lt;span style=&quot;color: navy; font-weight: bold;&quot;&gt;null&lt;/span&gt;) {&lt;/pre&gt;
&lt;pre style=&quot;background-color: white; color: black; font-family: &#39;DejaVu Sans Mono&#39;; font-size: 9.0pt;&quot;&gt;            &lt;span style=&quot;color: red;&quot;&gt;//the actual method to copy with different field name&lt;/span&gt; 
            addValueToField(copyFrom,copyTo, field, copy.copyTo());
        } &lt;span style=&quot;color: navy; font-weight: bold;&quot;&gt;else &lt;/span&gt;{
            &lt;span style=&quot;color: red;&quot;&gt;//the actual method to copy with the same  field name&lt;/span&gt; 
            addValueToField(copyFrom, copyTo, field, field.getName());
        }
    }
}&lt;/pre&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;pre style=&quot;background-color: white; color: black; font-family: &#39;DejaVu Sans Mono&#39;; font-size: 9.0pt;&quot;&gt;&lt;span style=&quot;color: navy; font-weight: bold;&quot;&gt;private void &lt;/span&gt;addValueToField(&lt;span style=&quot;color: navy; font-weight: bold;&quot;&gt;final &lt;/span&gt;Object copyFrom,&amp;nbsp;&lt;/pre&gt;
&lt;pre style=&quot;background-color: white; color: black; font-family: &#39;DejaVu Sans Mono&#39;; font-size: 9.0pt;&quot;&gt;&lt;span style=&quot;color: navy; font-weight: bold;&quot;&gt;final &lt;/span&gt;Object copyTo, &lt;span style=&quot;color: navy; font-weight: bold;&quot;&gt;final &lt;/span&gt;Field field, &lt;span style=&quot;color: navy; font-weight: bold;&quot;&gt;final &lt;/span&gt;String name) {
    &lt;span style=&quot;color: navy; font-weight: bold;&quot;&gt;try &lt;/span&gt;{&lt;/pre&gt;
&lt;pre style=&quot;background-color: white; color: black; font-family: &#39;DejaVu Sans Mono&#39;; font-size: 9.0pt;&quot;&gt;        &lt;span style=&quot;color: red;&quot;&gt;// Searching for the field in the &quot;other&quot; bean&lt;/span&gt;
        Field copyToField = copyTo.getClass().getDeclaredField(name);&lt;/pre&gt;
&lt;pre style=&quot;background-color: white; color: black; font-family: &#39;DejaVu Sans Mono&#39;; font-size: 9.0pt;&quot;&gt;        &lt;span style=&quot;color: red;&quot;&gt;// The fields are private so we make them accessible&lt;/span&gt;
        copyToField.setAccessible(&lt;span style=&quot;color: navy; font-weight: bold;&quot;&gt;true&lt;/span&gt;);
        field.setAccessible(&lt;span style=&quot;color: navy; font-weight: bold;&quot;&gt;true&lt;/span&gt;);&lt;/pre&gt;
&lt;pre style=&quot;background-color: white; color: black; font-family: &#39;DejaVu Sans Mono&#39;; font-size: 9.0pt;&quot;&gt;        &lt;span style=&quot;color: red;&quot;&gt;// The actual copying of the values&lt;/span&gt;
        copyToField.set(copyTo, field.get(copyFrom));&lt;/pre&gt;
&lt;pre style=&quot;background-color: white; color: black; font-family: &#39;DejaVu Sans Mono&#39;; font-size: 9.0pt;&quot;&gt;        &lt;span style=&quot;color: red;&quot;&gt;//stop the accessibility of the fields.&lt;/span&gt; 
        copyToField.setAccessible(&lt;span style=&quot;color: navy; font-weight: bold;&quot;&gt;false&lt;/span&gt;);
        field.setAccessible(&lt;span style=&quot;color: navy; font-weight: bold;&quot;&gt;false&lt;/span&gt;);
    } &lt;span style=&quot;color: navy; font-weight: bold;&quot;&gt;catch &lt;/span&gt;(NoSuchFieldException e) {
        &lt;span style=&quot;color: #660e7a; font-style: italic; font-weight: bold;&quot;&gt;log&lt;/span&gt;.error(&lt;span style=&quot;color: green; font-weight: bold;&quot;&gt;&quot;could not find field &quot; &lt;/span&gt;+ name);
        e.printStackTrace();
    } &lt;span style=&quot;color: navy; font-weight: bold;&quot;&gt;catch &lt;/span&gt;(IllegalAccessException e) {
        &lt;span style=&quot;color: #660e7a; font-style: italic; font-weight: bold;&quot;&gt;log&lt;/span&gt;.error(&lt;span style=&quot;color: green; font-weight: bold;&quot;&gt;&quot;could not access field &quot; &lt;/span&gt;+ name);
        e.printStackTrace();
    }
}&lt;/pre&gt;
&lt;pre style=&quot;background-color: white; color: black; font-family: &#39;DejaVu Sans Mono&#39;; font-size: 9.0pt;&quot;&gt;&amp;nbsp;&lt;/pre&gt;
&lt;pre style=&quot;background-color: white; color: black; font-family: &#39;DejaVu Sans Mono&#39;; font-size: 9.0pt;&quot;&gt;&amp;nbsp;&lt;/pre&gt;
&lt;pre style=&quot;background-color: white; color: black; font-family: &#39;DejaVu Sans Mono&#39;; font-size: 9.0pt;&quot;&gt; &lt;/pre&gt;
&lt;pre style=&quot;background-color: white; font-family: &amp;quot;dejavu sans mono&amp;quot;; font-size: 9pt;&quot;&gt;&lt;span style=&quot;color: red;&quot;&gt;// I added two more methods that are helpfull with the cherry picking.&amp;nbsp;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style=&quot;background-color: white; color: black; font-family: &#39;DejaVu Sans Mono&#39;; font-size: 9.0pt;&quot;&gt;  &lt;/pre&gt;
&lt;pre style=&quot;background-color: white; color: black; font-family: &#39;DejaVu Sans Mono&#39;; font-size: 9.0pt;&quot;&gt;&lt;span style=&quot;color: red;&quot;&gt;&lt;span style=&quot;font-style: italic;&quot;&gt;/**&lt;/span&gt;&lt;span style=&quot;font-style: italic;&quot;&gt; * checks if ignorefield is set in the target.class&lt;/span&gt;&lt;span style=&quot;font-style: italic;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style=&quot;background-color: white; color: black; font-family: &#39;DejaVu Sans Mono&#39;; font-size: 9.0pt;&quot;&gt;&lt;span style=&quot;color: red;&quot;&gt;&lt;span style=&quot;font-style: italic;&quot;&gt;* &lt;/span&gt;&lt;span style=&quot;font-style: italic; font-weight: bold;&quot;&gt;@param &lt;/span&gt;&lt;span style=&quot;font-style: italic; font-weight: bold;&quot;&gt;copyTo &lt;/span&gt;&lt;span style=&quot;font-style: italic;&quot;&gt;the target class.&lt;/span&gt;&lt;span style=&quot;font-style: italic;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style=&quot;background-color: white; color: black; font-family: &#39;DejaVu Sans Mono&#39;; font-size: 9.0pt;&quot;&gt;&lt;span style=&quot;color: red;&quot;&gt;&lt;span style=&quot;font-style: italic;&quot;&gt;* &lt;/span&gt;&lt;span style=&quot;font-style: italic; font-weight: bold;&quot;&gt;@param &lt;/span&gt;&lt;span style=&quot;font-style: italic; font-weight: bold;&quot;&gt;fieldName &lt;/span&gt;&lt;span style=&quot;font-style: italic;&quot;&gt;the fieldname to be set.&lt;/span&gt;&lt;span style=&quot;font-style: italic;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style=&quot;background-color: white; color: black; font-family: &#39;DejaVu Sans Mono&#39;; font-size: 9.0pt;&quot;&gt;&lt;span style=&quot;color: red;&quot;&gt;&lt;span style=&quot;font-style: italic;&quot;&gt;* &lt;/span&gt;&lt;span style=&quot;font-style: italic; font-weight: bold;&quot;&gt;@return &lt;/span&gt;&lt;span style=&quot;font-style: italic;&quot;&gt;a boolean if the field is right to set.&lt;/span&gt;&lt;span style=&quot;font-style: italic;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style=&quot;background-color: white; color: black; font-family: &#39;DejaVu Sans Mono&#39;; font-size: 9.0pt;&quot;&gt;&lt;span style=&quot;color: red;&quot;&gt;&lt;span style=&quot;font-style: italic;&quot;&gt;*/&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style=&quot;background-color: white; color: black; font-family: &#39;DejaVu Sans Mono&#39;; font-size: 9.0pt;&quot;&gt;&lt;span style=&quot;color: red;&quot;&gt;&lt;span style=&quot;font-style: italic;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: navy; font-weight: bold;&quot;&gt;private boolean &lt;/span&gt;ignoreCopyToField(&lt;span style=&quot;color: navy; font-weight: bold;&quot;&gt;final &lt;/span&gt;Object copyTo, &lt;span style=&quot;color: navy; font-weight: bold;&quot;&gt;final &lt;/span&gt;String fieldName) {
    Field field = &lt;span style=&quot;color: navy; font-weight: bold;&quot;&gt;null&lt;/span&gt;;&lt;/pre&gt;
&lt;pre style=&quot;background-color: white; font-family: &amp;quot;dejavu sans mono&amp;quot;; font-size: 9pt;&quot;&gt;&lt;span style=&quot;color: red;&quot;&gt;    // A list of fieldnames to prevent the NoSuchFieldException&lt;/span&gt;&lt;/pre&gt;
&lt;pre style=&quot;background-color: white; color: black; font-family: &#39;DejaVu Sans Mono&#39;; font-size: 9.0pt;&quot;&gt;&amp;nbsp;        List&amp;lt;String&amp;gt; fieldNames = checkFieldExists(copyTo);
        &lt;span style=&quot;color: olive;&quot;&gt;IgnoreCopy &lt;/span&gt;ignoreCopy = &lt;span style=&quot;color: navy; font-weight: bold;&quot;&gt;null&lt;/span&gt;;
        &lt;span style=&quot;color: navy; font-weight: bold;&quot;&gt;try &lt;/span&gt;{&lt;/pre&gt;
&lt;pre style=&quot;background-color: white; color: black; font-family: &#39;DejaVu Sans Mono&#39;; font-size: 9.0pt;&quot;&gt;&lt;span style=&quot;color: red;&quot;&gt;            // check if the field exists in the target class.&lt;/span&gt;&amp;nbsp;&lt;/pre&gt;
&lt;pre style=&quot;background-color: white; color: black; font-family: &#39;DejaVu Sans Mono&#39;; font-size: 9.0pt;&quot;&gt;          &amp;nbsp;&lt;span style=&quot;color: navy; font-weight: bold;&quot;&gt;if &lt;/span&gt;(fieldNames.contains(fieldName)) {&lt;/pre&gt;
&lt;pre style=&quot;background-color: white; color: black; font-family: &#39;DejaVu Sans Mono&#39;; font-size: 9.0pt;&quot;&gt;&lt;span style=&quot;color: red;&quot;&gt;                // retrieve the field with the name&lt;/span&gt;&amp;nbsp;&lt;/pre&gt;
&lt;pre style=&quot;background-color: white; color: black; font-family: &#39;DejaVu Sans Mono&#39;; font-size: 9.0pt;&quot;&gt;                field = copyTo.getClass().getDeclaredField(fieldName);&lt;/pre&gt;
&lt;pre style=&quot;background-color: white; color: black; font-family: &#39;DejaVu Sans Mono&#39;; font-size: 9.0pt;&quot;&gt;                &lt;span style=&quot;color: red;&quot;&gt;// retrieve the annotation from the field&lt;/span&gt;
                ignoreCopy = field.getAnnotation(&lt;span style=&quot;color: olive;&quot;&gt;IgnoreCopy&lt;/span&gt;.&lt;span style=&quot;color: navy; font-weight: bold;&quot;&gt;class&lt;/span&gt;);
            }
        } &lt;span style=&quot;color: navy; font-weight: bold;&quot;&gt;catch &lt;/span&gt;(NoSuchFieldException e) {
            e.printStackTrace();
        }        &lt;span style=&quot;color: navy; font-weight: bold;&quot;&gt;return  &lt;/span&gt;ignoreCopy != &lt;span style=&quot;color: navy; font-weight: bold;&quot;&gt;null&lt;/span&gt;;
}

&lt;span style=&quot;color: red;&quot;&gt;&lt;span style=&quot;font-style: italic;&quot;&gt;/**&lt;/span&gt;&lt;span style=&quot;font-style: italic;&quot;&gt; * creates a list that has all the fieldnames in it.&lt;/span&gt;&lt;span style=&quot;font-style: italic;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style=&quot;background-color: white; color: black; font-family: &#39;DejaVu Sans Mono&#39;; font-size: 9.0pt;&quot;&gt;&lt;span style=&quot;color: red;&quot;&gt;&lt;span style=&quot;font-style: italic;&quot;&gt;* &lt;/span&gt;&lt;span style=&quot;font-style: italic; font-weight: bold;&quot;&gt;@param &lt;/span&gt;&lt;span style=&quot;font-style: italic; font-weight: bold;&quot;&gt;copyTo &lt;/span&gt;&lt;span style=&quot;font-style: italic;&quot;&gt;the target class&lt;/span&gt;&lt;span style=&quot;font-style: italic;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style=&quot;background-color: white; color: black; font-family: &#39;DejaVu Sans Mono&#39;; font-size: 9.0pt;&quot;&gt;&lt;span style=&quot;color: red;&quot;&gt;&lt;span style=&quot;font-style: italic;&quot;&gt;* &lt;/span&gt;&lt;span style=&quot;font-style: italic; font-weight: bold;&quot;&gt;@return &lt;/span&gt;&lt;span style=&quot;font-style: italic;&quot;&gt;a list that has all the fieldnames in it&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: grey; font-style: italic;&quot;&gt;&lt;span style=&quot;color: red;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style=&quot;background-color: white; color: black; font-family: &#39;DejaVu Sans Mono&#39;; font-size: 9.0pt;&quot;&gt;&lt;span style=&quot;color: grey; font-style: italic;&quot;&gt;&lt;span style=&quot;color: red;&quot;&gt;*/&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: navy; font-weight: bold;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style=&quot;background-color: white; color: black; font-family: &#39;DejaVu Sans Mono&#39;; font-size: 9.0pt;&quot;&gt;&lt;span style=&quot;color: navy; font-weight: bold;&quot;&gt;private &lt;/span&gt;List&amp;lt;String&amp;gt; checkFieldExists(Object copyTo) {
    List&amp;lt;String&amp;gt; fieldNames = &lt;span style=&quot;color: navy; font-weight: bold;&quot;&gt;new &lt;/span&gt;ArrayList&amp;lt;String&amp;gt;();
    Field[] fields = copyTo.getClass().getDeclaredFields();
    &lt;span style=&quot;color: navy; font-weight: bold;&quot;&gt;for &lt;/span&gt;(Field field1: fields) {
        fieldNames.add(field1.getName());
    }
    &lt;span style=&quot;color: navy; font-weight: bold;&quot;&gt;return &lt;/span&gt;fieldNames;
}
&amp;nbsp;&lt;/pre&gt;
&lt;pre style=&quot;background-color: white; color: black; font-family: &#39;DejaVu Sans Mono&#39;; font-size: 9.0pt;&quot;&gt;&lt;/pre&gt;
&lt;h4 style=&quot;background-color: white; color: black; font-family: &amp;quot;DejaVu Sans Mono&amp;quot;; font-size: 9pt; text-align: center;&quot;&gt;
Conclusion&lt;/h4&gt;
&lt;div style=&quot;background-color: white; color: black; font-family: &amp;quot;DejaVu Sans Mono&amp;quot;; font-size: 9pt; text-align: left;&quot;&gt;
The choice to be made is more of a philosophic one. Is it worth to add some more reflection to the project at hand. I think the decision is to use it where it is useful. If it can save you writing and maintaining miles of boring code my advice would be to do it. In many cases it allready happens. So think about and work this out for your self. The code to build this is short and simple.&lt;/div&gt;
&lt;div style=&quot;background-color: white; color: black; font-family: &amp;quot;DejaVu Sans Mono&amp;quot;; font-size: 9pt; text-align: left;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;background-color: white; color: black; font-family: &amp;quot;DejaVu Sans Mono&amp;quot;; font-size: 9pt; text-align: left;&quot;&gt;
The original source code can be downloaded&amp;nbsp; &lt;a href=&quot;https://sourceforge.net/p/beancopy/code/ci/master/tarball&quot;&gt;here&lt;/a&gt;&lt;/div&gt;
&lt;div style=&quot;background-color: white; color: black; font-family: &amp;quot;DejaVu Sans Mono&amp;quot;; font-size: 9pt; text-align: left;&quot;&gt;
The jar file can ben downloaded&amp;nbsp; &lt;a href=&quot;http://sourceforge.net/projects/beancopy/files/BeanCopy-1.0.jar/download&quot;&gt;here&lt;/a&gt;&lt;/div&gt;
&lt;div style=&quot;background-color: white; color: black; font-family: &amp;quot;DejaVu Sans Mono&amp;quot;; font-size: 9pt; text-align: left;&quot;&gt;
Have fun!&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;background-color: white; color: black; font-family: &amp;quot;DejaVu Sans Mono&amp;quot;; font-size: 9pt; text-align: left;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;background-color: white; color: black; font-family: &amp;quot;DejaVu Sans Mono&amp;quot;; font-size: 9pt; text-align: left;&quot;&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://pieterroskam.blogspot.com/feeds/2216903216918000570/comments/default' title='Reacties posten'/><link rel='replies' type='text/html' href='http://pieterroskam.blogspot.com/2015/12/a-bit-of-reflection.html#comment-form' title='0 reacties'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2919956819843973860/posts/default/2216903216918000570'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2919956819843973860/posts/default/2216903216918000570'/><link rel='alternate' type='text/html' href='http://pieterroskam.blogspot.com/2015/12/a-bit-of-reflection.html' title='A bit of Reflection'/><author><name>java by experience</name><uri>http://www.blogger.com/profile/07404653852761857615</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2919956819843973860.post-4672430358344437549</id><published>2015-02-10T03:28:00.001-08:00</published><updated>2015-02-10T03:28:02.397-08:00</updated><title type='text'>Sorting data</title><content type='html'>&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;b&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;font-family: &amp;quot;Times New Roman&amp;quot;,&amp;quot;serif&amp;quot;; font-size: 13.5pt; mso-ansi-language: EN-US;&quot;&gt;Introduction:&lt;/span&gt;&lt;/b&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;font-family: &amp;quot;Times New Roman&amp;quot;,&amp;quot;serif&amp;quot;; font-size: 13.5pt; mso-ansi-language: EN-US;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span lang=&quot;EN-US&quot; style=&quot;font-family: &amp;quot;Times New Roman&amp;quot;,&amp;quot;serif&amp;quot;; font-size: 13.5pt; mso-ansi-language: EN-US;&quot;&gt;In the issue I had at hand we needed to sort the data to create a
matrix. So actually we needed to morph a list to a matrix form.&amp;nbsp;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;b&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;font-family: &amp;quot;Times New Roman&amp;quot;,&amp;quot;serif&amp;quot;; font-size: 13.5pt; mso-ansi-language: EN-US;&quot;&gt;The problems:&lt;/span&gt;&lt;/b&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;font-family: &amp;quot;Times New Roman&amp;quot;,&amp;quot;serif&amp;quot;; font-size: 13.5pt; mso-ansi-language: EN-US;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span lang=&quot;EN-US&quot; style=&quot;font-family: &amp;quot;Times New Roman&amp;quot;,&amp;quot;serif&amp;quot;; font-size: 13.5pt; mso-ansi-language: EN-US;&quot;&gt;At first hand I was thinking about using the states of the data to
figure out where in the matrix it should find its place. As soon I made a
drawing about my idea, I stopped working at it. I needed to create a complex
structure with a lot of if statements. I understood that, if I choose this way
I might run into a lot of bugs. I needed to think harder.&amp;nbsp;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;b&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;font-family: &amp;quot;Times New Roman&amp;quot;,&amp;quot;serif&amp;quot;; font-size: 13.5pt; mso-ansi-language: EN-US;&quot;&gt;The solution:&lt;/span&gt;&lt;/b&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;font-family: &amp;quot;Times New Roman&amp;quot;,&amp;quot;serif&amp;quot;; font-size: 13.5pt; mso-ansi-language: EN-US;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span lang=&quot;EN-US&quot; style=&quot;font-family: &amp;quot;Times New Roman&amp;quot;,&amp;quot;serif&amp;quot;; font-size: 13.5pt; mso-ansi-language: EN-US;&quot;&gt;I turned the whole idea around and looked at it from the other side.
Instead of creating the matrix directly from the list I could something like a
pre-sort. The next question obvisiouly would be: How the hell do I do that? The
answer was actually quite simple looking back at the issue. I took a
LinkedhashMap and a Treemap. I made sure that the query returned everything
sorted by date.&amp;nbsp;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span lang=&quot;EN-US&quot; style=&quot;font-family: &amp;quot;Times New Roman&amp;quot;,&amp;quot;serif&amp;quot;; font-size: 13.5pt; mso-ansi-language: EN-US;&quot;&gt;In the LinkedHashmap I used as a key the date and the Treemap. The
LinkedHashmap keeps things in order of incoming. So it kept the order of the
query I created by date. The second ordering would be by currency &amp;nbsp;where the payment was in done. &amp;nbsp;This I
used as a key in the TreeMap together with the rest of the object. The Treemap
sorts on aliphatic or numeric order using the black and red sorting
algorithm.&amp;nbsp;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span lang=&quot;EN-US&quot; style=&quot;font-family: &amp;quot;Times New Roman&amp;quot;,&amp;quot;serif&amp;quot;; font-size: 13.5pt; mso-ansi-language: EN-US;&quot;&gt;Now All I had to do was write a double loop for both of the maps and put
the data I needed in place.&amp;nbsp;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;b&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;font-family: &amp;quot;Times New Roman&amp;quot;,&amp;quot;serif&amp;quot;; font-size: 13.5pt; mso-ansi-language: EN-US;&quot;&gt;Conclusion:&lt;/span&gt;&lt;/b&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;font-family: &amp;quot;Times New Roman&amp;quot;,&amp;quot;serif&amp;quot;; font-size: 13.5pt; mso-ansi-language: EN-US;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span lang=&quot;EN-US&quot; style=&quot;font-family: &amp;quot;Times New Roman&amp;quot;,&amp;quot;serif&amp;quot;; font-size: 13.5pt; mso-ansi-language: EN-US;&quot;&gt;Sometimes it is better to make that drawing and have a better look at
what you need to-do. I believe that part is the greatest joy in my job. Create
something that gives me the proud feeling.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span lang=&quot;EN-US&quot; style=&quot;font-family: &amp;quot;Times New Roman&amp;quot;,&amp;quot;serif&amp;quot;; font-size: 13.5pt; mso-ansi-language: EN-US;&quot;&gt;Have fun!&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://pieterroskam.blogspot.com/feeds/4672430358344437549/comments/default' title='Reacties posten'/><link rel='replies' type='text/html' href='http://pieterroskam.blogspot.com/2015/02/sorting-data.html#comment-form' title='0 reacties'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2919956819843973860/posts/default/4672430358344437549'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2919956819843973860/posts/default/4672430358344437549'/><link rel='alternate' type='text/html' href='http://pieterroskam.blogspot.com/2015/02/sorting-data.html' title='Sorting data'/><author><name>java by experience</name><uri>http://www.blogger.com/profile/07404653852761857615</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2919956819843973860.post-2272730355731734247</id><published>2015-01-30T02:55:00.001-08:00</published><updated>2015-01-30T03:09:11.991-08:00</updated><title type='text'>saving passwords the save way</title><content type='html'>&lt;b&gt;Introduction:&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;
Every time I search on security matters, I always find the things to prevent attacks from the outside. These issues are important there is no doubt about that. But the one issue that kept running around my mind was one of the jobs where they got into your database. That is the place where an unwanted visitor should stay away. One of the last resort solutions to prevent this unwanted visitor to steal your customer data is to hash the passwords and encrypt the data in that database. The downside of this technique is that most of the encrypting and hashing methods all ready have white papers. So the only thing is: that buys you a bit more time before they got to your data.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Part of the solution:&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
I did not solve the whole case of steeling data yet. I did found away to store passwords strongly protected in my database. The solution is quite simple: don&#39;t store the real password in the database but an abstraction of that password. Every character has an ASCII number changing the characters in the password into numbers gives you the possibility to calculate with them like this:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
double key = 0;&lt;br /&gt;
char[] passwordChars= password.toCharArray();&lt;br /&gt;
for (char keyPart : passwordChars) {&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; key += Character.getNumericValue(keyPart);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Now you have a nummeric value of a password. How far you will calculate this is upto you.&lt;br /&gt;
The next question is ofcourse what to do with a number. The simple thing is that you can allready store this number into the database and you have an abstraction of the password. But the fun is to push it a bit further. You can create an hashmap that has a double as a key and a String as a value.&lt;br /&gt;
With the calculated number you get the string value out of the database. and store that as a password.&lt;br /&gt;
&lt;br /&gt;
Something like this:&lt;br /&gt;
private Map&amp;lt;Double, String&amp;gt; falsePasswords = new HashMap&amp;lt;Double, String&amp;gt;();&lt;br /&gt;
and fill it with nice long strings with a lot of weird characters:&lt;br /&gt;
falsePasswords.put(1.0, &quot;*(_)((UIiuyuUITYFTYR%R&amp;amp;$%&amp;amp;%tituyutyr867987yuyuiyo8&amp;amp;)*0&quot;);&lt;br /&gt;
I would make this a lon list of false passwords and create a calculation on the password that gives a good range of false passwords. &lt;br /&gt;
&lt;br /&gt;
To make it look like a real password you can hash it and make the unwanted visitor think that he can decrypt all your passwords.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Conclusion:&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;
The solution to most of the problems are not that hard. In this case a simple calculation and a hashmap brought the solution.&lt;br /&gt;
&lt;br /&gt;
Have fun!</content><link rel='replies' type='application/atom+xml' href='http://pieterroskam.blogspot.com/feeds/2272730355731734247/comments/default' title='Reacties posten'/><link rel='replies' type='text/html' href='http://pieterroskam.blogspot.com/2015/01/introduction-every-time-i-search-on.html#comment-form' title='0 reacties'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2919956819843973860/posts/default/2272730355731734247'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2919956819843973860/posts/default/2272730355731734247'/><link rel='alternate' type='text/html' href='http://pieterroskam.blogspot.com/2015/01/introduction-every-time-i-search-on.html' title='saving passwords the save way'/><author><name>java by experience</name><uri>http://www.blogger.com/profile/07404653852761857615</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2919956819843973860.post-1407404180981051541</id><published>2015-01-12T06:40:00.001-08:00</published><updated>2016-01-26T05:20:46.611-08:00</updated><title type='text'>Spring-boot rest/jpa full blown</title><content type='html'>&lt;b&gt;Introduction&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;
For a while I was looking for a suiting solution where I could use spring rest services combined with the Spring/JPA repositories. What I actual was looking for was a query driven rest service where I did not had to convert one bean to another. This awfull boilerplate code and is a maintainance nightmare.&lt;br /&gt;
&lt;br /&gt;
After a lot of searching I ran into Spring-boot where the got a couple of steps further than I was looking for. After studying it for a while I got used to their ideas and must say I like them.&lt;br /&gt;
&lt;br /&gt;
While I was searching I ran into a lot of examples but none of them was showing me how to deal with spring-boot in a professional and serious mather. So i picked up a lot from the&amp;nbsp;&lt;a href=&quot;http://docs.spring.io/spring-boot/docs/current-SNAPSHOT/reference/htmlsingle/#boot-features-external-config-application-property-files&quot;&gt;reference guide&lt;/a&gt;&amp;nbsp;and put the pieces of the puzzle together.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;The configuration&lt;/b&gt;&lt;br /&gt;
I build the whole story in Maven for the gradle fans have a look at the reference guide. There is fully explained howto do it in gradle.&lt;br /&gt;
&lt;br /&gt;
The basiscs of spring-boot is the simple fact that they provide you with a super pom for maven where you can cherry pick the parts you really like to use. Here are the cherries I picked from that tree:&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;&lt;b&gt;The project pom&amp;nbsp;&lt;/b&gt;&lt;/i&gt;&lt;br /&gt;
&amp;lt;project xmlns=&quot;http://maven.apache.org/POM/4.0.0&quot; xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;xsi:schemaLocation=&quot;http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd&quot;&amp;gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;lt;parent&amp;gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;artifactId&amp;gt;abstractservice&amp;lt;/artifactId&amp;gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;groupId&amp;gt;com.purat.services&amp;lt;/groupId&amp;gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;version&amp;gt;1.0-SNAPSHOT&amp;lt;/version&amp;gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;lt;/parent&amp;gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;lt;modelVersion&amp;gt;4.0.0&amp;lt;/modelVersion&amp;gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;lt;artifactId&amp;gt;userservice&amp;lt;/artifactId&amp;gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;lt;packaging&amp;gt;jar&amp;lt;/packaging&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;lt;properties&amp;gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;tomcat.version&amp;gt;8.0.3&amp;lt;/tcat.version&amp;gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;!-- use UTF-8 for everything --&amp;gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;project.build.sourceEncoding&amp;gt;UTF-8&amp;lt;/project.build.sourceEncoding&amp;gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;project.reporting.outputEncoding&amp;gt;UTF-8&amp;lt;/project.reporting.outputEncoding&amp;gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;start-class&amp;gt;com.purat.Application&amp;lt;/start-class&amp;gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;spring-boot-version&amp;gt;1.1.10.RELEASE&amp;lt;/spring-boot-version&amp;gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;lt;/properties&amp;gt;&lt;br /&gt;
&lt;span style=&quot;color: red;&quot;&gt;// &lt;b&gt;The super pom provided by spring-boot&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;lt;parent&amp;gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;groupId&amp;gt;org.springframework.boot&amp;lt;/groupId&amp;gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;artifactId&amp;gt;spring-boot-starter-parent&amp;lt;/artifactId&amp;gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;version&amp;gt;1.1.10.RELEASE&amp;lt;/version&amp;gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;lt;/parent&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;lt;dependencies&amp;gt;&lt;br /&gt;
&lt;span style=&quot;color: red;&quot;&gt;&lt;b&gt;// these are the depedency to deliver all the&amp;nbsp;necessary jpa libraries to&amp;nbsp;approach&amp;nbsp;the database.&amp;nbsp;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;dependency&amp;gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;groupId&amp;gt;org.springframework.boot&amp;lt;/groupId&amp;gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;artifactId&amp;gt;spring-boot-starter-data-jpa&amp;lt;/artifactId&amp;gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;/dependency&amp;gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;dependency&amp;gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;groupId&amp;gt;org.springframework.boot&amp;lt;/groupId&amp;gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;artifactId&amp;gt;spring-boot-starter-jdbc&amp;lt;/artifactId&amp;gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;/dependency&lt;br /&gt;
&lt;span style=&quot;color: red;&quot;&gt;&lt;b&gt;//This is the library to deliver all the necassary rest libraries. To create for example your own endpoints&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;dependency&amp;gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;groupId&amp;gt;org.springframework.boot&amp;lt;/groupId&amp;gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;artifactId&amp;gt;spring-boot-starter-data-rest&amp;lt;/artifactId&amp;gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;/dependency&amp;gt;&lt;br /&gt;
&lt;span style=&quot;color: red;&quot;&gt;&lt;b&gt;//This is the library that gives us the web application part.&amp;nbsp;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;dependency&amp;gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;groupId&amp;gt;org.springframework.boot&amp;lt;/groupId&amp;gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;artifactId&amp;gt;spring-boot-starter-web&amp;lt;/artifactId&amp;gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;/dependency&amp;gt;&lt;br /&gt;
&lt;span style=&quot;color: red;&quot;&gt;&lt;b&gt;//This is the library that gives us the production-ready parts. For more details look at&amp;nbsp;&lt;a href=&quot;http://docs.spring.io/spring-boot/docs/current-SNAPSHOT/reference/htmlsingle/#production-ready&quot;&gt;boot-starter-actuator&lt;/a&gt;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;dependency&amp;gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;groupId&amp;gt;org.springframework.boot&amp;lt;/groupId&amp;gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;artifactId&amp;gt;spring-boot-starter-actuator&amp;lt;/artifactId&amp;gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;/dependency&amp;gt;&lt;br /&gt;
&lt;span style=&quot;color: red;&quot;&gt;&lt;b&gt;//For the database I used postgress.&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;dependency&amp;gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;groupId&amp;gt;postgresql&amp;lt;/groupId&amp;gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;artifactId&amp;gt;postgresql&amp;lt;/artifactId&amp;gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;version&amp;gt;9.0-801.jdbc4&amp;lt;/version&amp;gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;/dependency&amp;gt;&lt;br /&gt;
&lt;span style=&quot;color: red;&quot;&gt;// &lt;b&gt;For handling the getters and setters I used lombock.&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;dependency&amp;gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;groupId&amp;gt;org.projectlombok&amp;lt;/groupId&amp;gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;artifactId&amp;gt;lombok&amp;lt;/artifactId&amp;gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;version&amp;gt;1.12.6&amp;lt;/version&amp;gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;scope&amp;gt;compile&amp;lt;/scope&amp;gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;/dependency&amp;gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;lt;/dependencies&amp;gt; &amp;nbsp; &amp;lt;build&amp;gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;pluginManagement&amp;gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;plugins&amp;gt;&lt;br /&gt;
&lt;span style=&quot;color: red;&quot;&gt;&lt;b&gt;//This plugin is responsible for the kind of packaging you desire. You can choose &amp;nbsp;a war or a jar&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: red;&quot;&gt;&lt;b&gt;This plugin will build it with the desired content. &amp;nbsp;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;b&gt;&lt;span style=&quot;color: red;&quot;&gt;To deploy a war file there are still a couple of steps to take. You can find the description for that here:&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;a href=&quot;http://docs.spring.io/spring-boot/docs/current/reference/html/howto-traditional-deployment.html&quot;&gt;traditional deployment&lt;/a&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;plugin&amp;gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;groupId&amp;gt;org.springframework.boot&amp;lt;/groupId&amp;gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;artifactId&amp;gt;spring-boot-maven-plugin&amp;lt;/artifactId&amp;gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;/plugin&amp;gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;plugin&amp;gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;groupId&amp;gt;org.apache.maven.plugins&amp;lt;/groupId&amp;gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;artifactId&amp;gt;maven-compiler-plugin&amp;lt;/artifactId&amp;gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;version&amp;gt;3.1&amp;lt;/version&amp;gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;configuration&amp;gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;source&amp;gt;1.8&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;target&amp;gt;1.8&amp;lt;/target&amp;gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;/configuration&amp;gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;/plugin&amp;gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;/plugins&amp;gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;/pluginManagement&amp;gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;lt;/build&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;lt;repositories&amp;gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;repository&amp;gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;id&amp;gt;spring-releases&amp;lt;/id&amp;gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;name&amp;gt;Spring Releases&amp;lt;/name&amp;gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;url&amp;gt;https://repo.spring.io/libs-release&amp;lt;/url&amp;gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;/repository&amp;gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;repository&amp;gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;id&amp;gt;org.jboss.repository.releases&amp;lt;/id&amp;gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;name&amp;gt;JBoss Maven Release Repository&amp;lt;/name&amp;gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;url&amp;gt;https://repository.jboss.org/nexus/content/repositories/releases&amp;lt;/url&amp;gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;/repository&amp;gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;lt;/repositories&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;lt;pluginRepositories&amp;gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;pluginRepository&amp;gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;id&amp;gt;spring-releases&amp;lt;/id&amp;gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;name&amp;gt;Spring Releases&amp;lt;/name&amp;gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;url&amp;gt;https://repo.spring.io/libs-release&amp;lt;/url&amp;gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;/pluginRepository&amp;gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;lt;/pluginRepositories&amp;gt;&lt;br /&gt;
&amp;lt;/project&amp;gt;&lt;br /&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b&gt;&lt;i&gt;The Application class and application.properties&lt;/i&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b&gt;&lt;i&gt;&lt;br /&gt;&lt;/i&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
Despite of what you see on the internet I like to keep the Application class to a bare minimum. We need this baby only to start the project up after we build a war or a jar.&amp;nbsp;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
import org.springframework.boot.SpringApplication;&lt;/div&gt;
&lt;div&gt;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;&lt;/div&gt;
&lt;div&gt;
import org.springframework.context.ConfigurableApplicationContext;&lt;/div&gt;
&lt;div&gt;
import org.springframework.context.annotation.ComponentScan;&lt;/div&gt;
&lt;div&gt;
import org.springframework.context.annotation.Configuration;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
/**&lt;/div&gt;
&lt;div&gt;
&amp;nbsp;* Created by compurat on 1/11/15.&lt;/div&gt;
&lt;div&gt;
&amp;nbsp;*/&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;color: red;&quot;&gt;&lt;b&gt;//&lt;span style=&quot;background-color: white; font-family: &amp;quot;dejavu serif&amp;quot; , &amp;quot;georgia&amp;quot; , &amp;quot;times new roman&amp;quot; , &amp;quot;times&amp;quot; , serif; font-size: 14px; line-height: 19.6px;&quot;&gt;Indicates that a class declares one or more&amp;nbsp;&lt;/span&gt;&lt;a href=&quot;http://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/context/annotation/Bean.html&quot; style=&quot;background-color: white; font-family: &amp;quot;dejavu serif&amp;quot; , &amp;quot;georgia&amp;quot; , &amp;quot;times new roman&amp;quot; , &amp;quot;times&amp;quot; , serif; font-size: 14px; line-height: 19.6px; text-decoration: none;&quot; title=&quot;annotation in org.springframework.context.annotation&quot;&gt;&lt;code style=&quot;font-family: &#39;DejaVu Sans Mono&#39;, monospace; line-height: 1.4em; margin-top: 8px; padding-top: 4px;&quot;&gt;@Bean&lt;/code&gt;&lt;/a&gt;&lt;span style=&quot;background-color: white; font-family: &amp;quot;dejavu serif&amp;quot; , &amp;quot;georgia&amp;quot; , &amp;quot;times new roman&amp;quot; , &amp;quot;times&amp;quot; , serif; font-size: 14px; line-height: 19.6px;&quot;&gt;&amp;nbsp;methods and may be processed by the Spring container to generate bean definitions and service requests for those beans at &lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;background-color: white; font-family: &amp;quot;dejavu serif&amp;quot; , &amp;quot;georgia&amp;quot; , &amp;quot;times new roman&amp;quot; , &amp;quot;times&amp;quot; , serif; font-size: 14px; line-height: 19.6px;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: red;&quot;&gt;runtime.&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
@Configuration&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;color: red;&quot;&gt;&lt;b&gt;// This annotation configures &amp;nbsp;and uses the standard beans that are on the classpath of the diverse libraries.&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
@EnableAutoConfiguration&lt;/div&gt;
&lt;div&gt;
&lt;b&gt;&lt;span style=&quot;color: red;&quot;&gt;&lt;span style=&quot;background-color: white; font-family: &amp;quot;dejavu serif&amp;quot; , &amp;quot;georgia&amp;quot; , &amp;quot;times new roman&amp;quot; , &amp;quot;times&amp;quot; , serif; font-size: 14px; line-height: 19.6px;&quot;&gt;//Configures component scanning directives for use with @&lt;/span&gt;&lt;a href=&quot;http://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/context/annotation/Configuration.html&quot; style=&quot;background-color: white; font-family: &amp;quot;dejavu serif&amp;quot; , &amp;quot;georgia&amp;quot; , &amp;quot;times new roman&amp;quot; , &amp;quot;times&amp;quot; , serif; font-size: 14px; line-height: 19.6px; text-decoration: none;&quot; title=&quot;annotation in org.springframework.context.annotation&quot;&gt;&lt;code style=&quot;font-family: &#39;DejaVu Sans Mono&#39;, monospace; line-height: 1.4em; margin-top: 8px; padding-top: 4px;&quot;&gt;Configuration&lt;/code&gt;&lt;/a&gt;&lt;span style=&quot;background-color: white; font-family: &amp;quot;dejavu serif&amp;quot; , &amp;quot;georgia&amp;quot; , &amp;quot;times new roman&amp;quot; , &amp;quot;times&amp;quot; , serif; font-size: 14px; line-height: 19.6px;&quot;&gt;&amp;nbsp;classes.&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
@ComponentScan&lt;/div&gt;
&lt;div&gt;
public class Application {&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; public static void main(String[] args) {&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;color: red;&quot;&gt;&lt;b&gt;//This is the only line you need to start up you application.&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ConfigurableApplicationContext context = SpringApplication.run(Application.class);&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; }&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
}&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b&gt;&lt;i&gt;The application.properties file under the resources folder:&lt;/i&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b&gt;&lt;i&gt;&lt;br /&gt;&lt;/i&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
The way this works, looks to me like the Wicket framework.&amp;nbsp;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;color: red;&quot;&gt;&lt;b&gt;//The configuration of the database&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;div&gt;
spring.datasource.url=jdbc:postgresql://localhost:5432/people&lt;/div&gt;
&lt;div&gt;
spring.datasource.username=Pieter&lt;/div&gt;
&lt;div&gt;
spring.datasource.password=Pieter01&lt;/div&gt;
&lt;div&gt;
spring.datasource.driver-class-name=org.postgresql.Driver&lt;/div&gt;
&lt;div&gt;
spring.jpa.database-platform=org.hibernate.dialect.PostgreSQLDialect&lt;/div&gt;
&lt;div&gt;
hibernate.hbm2ddl.auto=create-drop&lt;/div&gt;
&lt;div&gt;
spring.jpa.show-sql=true&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;color: red;&quot;&gt;&lt;b&gt;// Setting the end point properties give it an id,give the possibility to shut the endpoints down and sensitive is security wise. Does an endpoint need username and password to be approached.&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
endpoints.beans.id=springbeans&lt;/div&gt;
&lt;div&gt;
endpoints.beans.sensitive=false&lt;/div&gt;
&lt;div&gt;
endpoints.shutdown.enabled=true&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;color: red;&quot;&gt;&lt;b&gt;//Tomcat serverlog enabling and patterns.&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
server.tomcat.access-log-enabled=true&lt;/div&gt;
&lt;div&gt;
server.tomcat.access-log-pattern=%a asdasd&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;color: red;&quot;&gt;&lt;b&gt;The log file propeties.&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
logging.file= logging/userservice.log&lt;/div&gt;
&lt;div&gt;
logging.level.org.springframework.web: DEBUG&lt;/div&gt;
&lt;div&gt;
logging.level.org.hibernate: ERROR&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;
Basicly we now have ready to run spring-boot webservice with JPA. It does not work yet we still need to fill in the missing pieces here.&amp;nbsp;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b&gt;The application&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
Lets start with the rest endpoint. That is where it all begins. This is the profile endpoint and does not take any parameters in this case. But it give you an idea how an endpoint in spring-boot works:&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
import com.purat.data.People;&lt;/div&gt;
&lt;div&gt;
import com.purat.data.repository.PeopleRepository;&lt;/div&gt;
&lt;div&gt;
import org.springframework.beans.factory.annotation.Autowired;&lt;/div&gt;
&lt;div&gt;
import org.springframework.web.bind.annotation.RequestMapping;&lt;/div&gt;
&lt;div&gt;
import org.springframework.web.bind.annotation.RestController;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
/**&lt;/div&gt;
&lt;div&gt;
&amp;nbsp;* Created by compurat on 1/11/15.&lt;/div&gt;
&lt;div&gt;
&amp;nbsp;*/&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;color: red;&quot;&gt;&lt;b&gt;//Tells spring that this is obvious a rest controller&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
@RestController&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;color: red;&quot;&gt;&lt;b&gt;//Tells spring what the base url is.&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
@RequestMapping(&quot;peopleservice&quot;)&lt;/div&gt;
&lt;div&gt;
public class ProfileEndpoint {&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; @Autowired&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;color: red;&quot;&gt;&lt;b&gt;//spring/jpa repository to approsch the database&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; private&amp;nbsp;PeopleRepository&amp;nbsp;peopleRepository;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;color: red;&quot;&gt;&lt;b&gt;//Tells spring what the endpoint url is.&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; @RequestMapping(&quot;/profile&quot;)&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; public Person profile() {&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp;&lt;span style=&quot;color: red;&quot;&gt;&lt;b&gt;The jpa entity&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; Person person&amp;nbsp;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;color: red;&quot;&gt;&lt;b&gt;//The query parameter names are in the repository method name. in this case&amp;nbsp;&lt;/b&gt;&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;color: red;&quot;&gt;EmailadressAndPassword&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
=&amp;nbsp;peopleRepository.findByEmailadressAndPassword(&quot;pieter.roskam@gmail.com&quot;,&quot;Roskam01&quot;);&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;color: red;&quot;&gt;&lt;b&gt;If you Return the entity in the rest controller spring will underwater serialize the object to an json file.&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; return person;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; }&lt;/div&gt;
&lt;div&gt;
}&amp;nbsp;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
As second part I like to handle the jpa entity:&lt;/div&gt;
&lt;div&gt;
&lt;div&gt;
import lombok.Getter;&lt;/div&gt;
&lt;div&gt;
import lombok.Setter;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
import javax.persistence.Entity;&lt;/div&gt;
&lt;div&gt;
import javax.persistence.Id;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
/**&lt;/div&gt;
&lt;div&gt;
&amp;nbsp;* Created by compurat on 1/11/15.&lt;/div&gt;
&lt;div&gt;
&amp;nbsp;*/&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;color: red;&quot;&gt;&lt;b&gt;//Lombock getters and setters keep you code nice and clean.&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
@Getter&lt;/div&gt;
&lt;div&gt;
@Setter&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;color: red;&quot;&gt;&lt;b&gt;//What table to approach&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
@Entity(name=&quot;people&quot;)&lt;/div&gt;
&lt;div&gt;
public class&amp;nbsp;Person&amp;nbsp;{&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;color: red;&quot;&gt;&lt;b&gt;// the unique id and all the fields as named in the table.&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; @Id&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; private long id;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; private String firstname;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; private String lastname;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; private String address;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; private String housenumber;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; private String postalcode;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; private String city;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; private String telephone;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; private String verification;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; private String emailadress;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; private String password;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
}&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
As third and last part I would like to show the jpa repository:&lt;/div&gt;
&lt;div&gt;
&lt;div&gt;
package com.purat.data.repository;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
import com.purat.data.User;&lt;/div&gt;
&lt;div&gt;
import org.springframework.data.repository.CrudRepository;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;color: red;&quot;&gt;&lt;b&gt;The spring/jpa repository gives some benefits. For simple queries you can use the parameter names in the method, but for more complicated queries you can also use the&amp;nbsp;@Query&amp;nbsp;annotation to write a jql query .&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
public interface&amp;nbsp;PeopleRepository&amp;nbsp;extends CrudRepository&amp;lt;Person,Long&amp;gt; {&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; User findByEmailadressAndPassword(String emailadress, String password);&lt;/div&gt;
&lt;div&gt;
}&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b&gt;Conclusion&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
Spring-boot took a complete new road to developing and deploying rest services. The most interesting part is probably that you can have a rest service in a jar file. That was a mind boggle to me for a while. The secret lies in the fact that it is a self executing jar. While starting up your Application class it will also startup tomcat if you configured it right (dependencies and properties file).&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
The second part that might be of interest, is the fact that it looks like that the separation of tiers is gone. But if you look closely it is not:&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
1. The separation of the database is still intact because it is hidden behind the spring/jpa repositories. They are not reachable from the outside.&amp;nbsp;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
2. The entity bean seams to be exposed at the frontend but again that is not completely true. The bean will be serialized to a json file by Spring. That is the only visible thing on the outside.&amp;nbsp;The only one that should reach this service is the frontend. Which is also separate. &lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
I love the part that you can package a rest service into a jar. You put it somewhere on your server and start it with java -jar servicewhatever.jar. That will fire up everything you build for this rest service.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
have fun! &amp;nbsp;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://pieterroskam.blogspot.com/feeds/1407404180981051541/comments/default' title='Reacties posten'/><link rel='replies' type='text/html' href='http://pieterroskam.blogspot.com/2015/01/spring-boot-restjpa-full-blown.html#comment-form' title='0 reacties'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2919956819843973860/posts/default/1407404180981051541'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2919956819843973860/posts/default/1407404180981051541'/><link rel='alternate' type='text/html' href='http://pieterroskam.blogspot.com/2015/01/spring-boot-restjpa-full-blown.html' title='Spring-boot rest/jpa full blown'/><author><name>java by experience</name><uri>http://www.blogger.com/profile/07404653852761857615</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2919956819843973860.post-4269573779755773798</id><published>2014-10-26T14:06:00.002-07:00</published><updated>2014-10-28T05:31:17.137-07:00</updated><title type='text'>Execution Framework introduction</title><content type='html'>&lt;b&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;Introduction:&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/b&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;In the execution service there are many ways to do a trick I have been googling around and found a lot of words but none of them explains well what is what and why.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;b&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;Solvation:&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/b&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;Most of the executor service are obtained through the Executors class like:&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;strong style=&quot;background-color: white; border: 0px; color: #222222; line-height: 22.5px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&amp;nbsp;Executors.newCachedThreadPool();&lt;/strong&gt;&lt;span style=&quot;background-color: white; color: #222222; line-height: 22.5px;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white; color: #222222; line-height: 22.5px;&quot;&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;This threadpool provides you with the number of threads that you need. It reuses threads that come available again.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;strong style=&quot;background-color: white; border: 0px; color: #222222; line-height: 22.5px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Executors.newFixedThreadPool(10);&lt;/strong&gt;&lt;span style=&quot;background-color: white; color: #222222; line-height: 22.5px;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white; color: #222222; line-height: 22.5px;&quot;&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;This threadpool only provides you with the number of threads that you have declared 10 in my example.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;strong style=&quot;background-color: white; border: 0px; color: #222222; line-height: 22.5px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Executors.newSingleThreadExecutor();&lt;/strong&gt;&lt;span style=&quot;background-color: white; color: #222222; line-height: 22.5px;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white; color: #222222; line-height: 22.5px;&quot;&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;This threadpool contains one single thread and all given tasks will be executed in sequence.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white; color: #222222; line-height: 22.5px;&quot;&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;span style=&quot;color: #222222;&quot;&gt;&lt;span style=&quot;background-color: white; line-height: 22.5px;&quot;&gt;Except ofr the&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;strong style=&quot;background-color: white; border: 0px; color: #222222; line-height: 22.5px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;SingleThreadExecutor()&lt;/strong&gt;&lt;span style=&quot;background-color: white; border: 0px; color: #222222; line-height: 22.5px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&amp;nbsp;all of the others deal the same way if it becomes to lists. As soon you expose a list to one of the named threadpools the behaviour is as follows:&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white; border: 0px; color: #222222; line-height: 22.5px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;span style=&quot;background-color: white; border: 0px; color: #222222; line-height: 22.5px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Lets say we take a&amp;nbsp;&lt;/span&gt;&lt;strong style=&quot;background-color: white; border: 0px; color: #222222; line-height: 22.5px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;CachedThreadPool&lt;/strong&gt;&lt;span style=&quot;background-color: white; border: 0px; color: #222222; line-height: 22.5px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt; or a&amp;nbsp;&lt;/span&gt;&lt;strong style=&quot;background-color: white; border: 0px; color: #222222; line-height: 22.5px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;FixedThreadPool&lt;/strong&gt;&lt;span style=&quot;background-color: white; border: 0px; color: #222222; line-height: 22.5px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&amp;nbsp;we expose a list of elements to the executorservice initialized with one of the above named pools. &amp;nbsp;The first element of that is exposed for threading it will be spread over all the available threads. As soon the task is done, the next element of the list will use all of the threads. &amp;nbsp;This is a good thing if that is what you desire. But what if you want to share all the elements of the list shared over different threads. In other words every element of the list should be worked on at the same moment in parallel.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white; color: #222222; line-height: 22.5px;&quot;&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;This is where the only pool comes in that can do that is the ForkJoinPool (since java 7). &amp;nbsp;This pool is not obtained through the Executors class but is instanciated on its own like :&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
ForkJoinPool forkJoinPool = new ForkJoinPool(3); The constructor takes a int as argument to initialize the number of threads, 3 in my example. The ForkJoinPool uses the&amp;nbsp;&lt;span style=&quot;font-family: inherit;&quot;&gt;&amp;nbsp;work-stealing philosophy. This means that if a thread is running out of jobs, it will visit one of the&amp;nbsp;&lt;/span&gt;neighbor threads and see if he can help him out.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Conclusion:&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
If you want to work a single task in different threads the ExecutionService is what you need. If you need different tasks work in paralel the same time, you should use the ForkJoinPool.&lt;br /&gt;
&lt;br /&gt;
If you are using a version of Java lesser then 7, you can try this trick with google guava. I worked at this time with version 18.0 and that worked fine. Here is a piece of example code:&lt;br /&gt;
&lt;br /&gt;
//Java class&lt;br /&gt;
ExecutorService executorService = Executors.newCachedThreadPool();&lt;br /&gt;
&lt;div&gt;
//Guava class&lt;/div&gt;
&lt;div&gt;
ExecutionList executionList = new ExecutionList();&lt;/div&gt;
&lt;div&gt;
//code to execute&lt;/div&gt;
executionList.add( new myRunnable(), executorService);&lt;br /&gt;
executionList.execute();&lt;br /&gt;
&lt;br /&gt;
Have fun!</content><link rel='replies' type='application/atom+xml' href='http://pieterroskam.blogspot.com/feeds/4269573779755773798/comments/default' title='Reacties posten'/><link rel='replies' type='text/html' href='http://pieterroskam.blogspot.com/2014/10/execution-framework-introduction.html#comment-form' title='0 reacties'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2919956819843973860/posts/default/4269573779755773798'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2919956819843973860/posts/default/4269573779755773798'/><link rel='alternate' type='text/html' href='http://pieterroskam.blogspot.com/2014/10/execution-framework-introduction.html' title='Execution Framework introduction'/><author><name>java by experience</name><uri>http://www.blogger.com/profile/07404653852761857615</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2919956819843973860.post-7555050380033974982</id><published>2014-10-11T08:11:00.001-07:00</published><updated>2014-10-11T08:11:16.323-07:00</updated><title type='text'>reading method from stack</title><content type='html'>&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;b&gt;Introduction:&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;
One of my colleagues came up with the idea to setup logging through AOP. I always encourage ideas like that. This might set you on the wrong foot. This blog is not about how to deal with AOP. This little part is about how to read the method name from the stack so it can be written to a log.&lt;br /&gt;
&lt;br /&gt;
The difficulty came that certain classes should log the method name with a certain pattern and other method names not. This made it hard to solve with the patterns available in the Loggger settings.&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;
&lt;b&gt;The solution:&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
The idea sounds simple. I worked it a bit more out to be comply &amp;nbsp;to the open closed design way. Because what I learned in composite designing is that every object should interfere as less as possible with other objects. In other words, It should be as independent as possible. The only way to achieve this is to use reflection.&lt;br /&gt;
&lt;br /&gt;
There we open another discussion when and where should we use reflection. The fist rule I is simple If there is another solution that is as valid use that one. If there is not another valid option then use reflection. So why reflection in this matter?&lt;br /&gt;
&lt;br /&gt;
There are two ways to solve this:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;ol&gt;
&lt;li&gt;hardcode every method name also as a constant in the class that needs to log the method name.&lt;/li&gt;
&lt;li&gt;Use Reflection to get the name of the stack. &amp;nbsp;&amp;nbsp;&lt;/li&gt;
&lt;/ol&gt;
So this how we solved it:&lt;br /&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;div&gt;
String methodname = Thread.currentThread().getStackTrace()[1].getMethodName();&lt;/div&gt;
&lt;div&gt;
Logger.info(methodName);&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
The .currentThread() is a static method from Thread from which you can get the stack called in that Thread. In my example there was only one thread.&amp;nbsp;&lt;/div&gt;
&lt;div&gt;
The 1 refers to the position of the method you desire from the stack. The further back you want the higher this number becomes. The only bummer in this story is that you cannot obtain the names that have been given to the parameters of the required method. The jvm creates new instances of them and name them &amp;nbsp;like arg0, arg1 etc...&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b&gt;Conclusion:&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
Knowing what you are doing is very important. It also shows everytime that things in Java are not that hard ones you understand the concepts. This is something you probably not gonne use a lot but when you need it, it is handy.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
Have fun!&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://pieterroskam.blogspot.com/feeds/7555050380033974982/comments/default' title='Reacties posten'/><link rel='replies' type='text/html' href='http://pieterroskam.blogspot.com/2014/10/reading-method-from-stack.html#comment-form' title='0 reacties'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2919956819843973860/posts/default/7555050380033974982'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2919956819843973860/posts/default/7555050380033974982'/><link rel='alternate' type='text/html' href='http://pieterroskam.blogspot.com/2014/10/reading-method-from-stack.html' title='reading method from stack'/><author><name>java by experience</name><uri>http://www.blogger.com/profile/07404653852761857615</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2919956819843973860.post-5655494673935769639</id><published>2014-09-20T06:22:00.002-07:00</published><updated>2014-09-21T04:29:01.578-07:00</updated><title type='text'>Node.js reading json from rest service</title><content type='html'>&lt;b&gt;Introduction:&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
The concept of a java script server is in my opinion revolutionary because of the fact that frontend technology also can be separated from the backend as a specialism. But what good is the one without the other. Creating a presentation &amp;nbsp;is no good without data. But what good is data if we cannot present it. So in this matter &amp;nbsp;I would show you that it is possible to combine the best of both worlds. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;The solution:&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
In my previous &lt;a href=&quot;http://pieterroskam.blogspot.nl/2014/09/hello-world-with-nodejs.html&quot;&gt;post&lt;/a&gt; I described how to install a nodejs server and create an hello world application.&lt;br /&gt;
Because connecting to a rest service is a bit more complex we need to do some actions before we can start:&lt;br /&gt;
&lt;br /&gt;
create an folder for example rest-api&lt;br /&gt;
cd rest-api&lt;br /&gt;
&lt;br /&gt;
We need the superagent library:&lt;br /&gt;
npm install superagent@0.17.0 --save-dev&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;color: #444444;&quot;&gt;After this we can start building up the server:&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: red;&quot;&gt;// initializing the http package.&lt;/span&gt;&lt;br /&gt;
var http = require(&quot;http&quot;),&lt;br /&gt;
&lt;span style=&quot;color: red;&quot;&gt;//making the port available through a parameter&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
port = process.argv[2] || 8888;&lt;br /&gt;
&lt;span style=&quot;color: red;&quot;&gt;// initializing the superagent package&lt;/span&gt;&lt;br /&gt;
var superagent = require(&#39;superagent&#39;);&lt;br /&gt;
&lt;span style=&quot;color: red;&quot;&gt;// creating the http server&lt;/span&gt;&lt;br /&gt;
http.createServer(function(request, response) {&lt;br /&gt;
&lt;span style=&quot;color: red;&quot;&gt;//retrieving the rest url throught the superagent package&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; superagent.get(&#39;http://localhost:8080/hello&#39;)&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; .end(function(e, res){&lt;br /&gt;
&lt;span style=&quot;color: red;&quot;&gt;//writing the res.text response from the rest server to the response which is the browser client response.&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; response.write(res.text, &quot;binary&quot;);&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; response.end();&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; })&lt;br /&gt;
&lt;span style=&quot;color: red;&quot;&gt;//make the server listen to the port that is declared in my case 8090 or the standard port 8888&lt;/span&gt;&lt;br /&gt;
}).listen(parseInt(port, 10));&lt;br /&gt;
&lt;span style=&quot;color: red;&quot;&gt;//just a friendly console message.&lt;/span&gt;&lt;br /&gt;
console.log(&quot;Static file server running at\n &amp;nbsp;=&amp;gt; http://localhost:&quot; + port + &quot;/\nCTRL + C to shutdown&quot;);&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Conclusion:&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;
The world of javascript is not that different from the world of Java these days. There is this virtual machine, it is getting Object Oriented in a kind of way and you have to know your way in the library wilderness. This makes the gap between the two worlds smaller. There are still differences between the way of working between these kind of frontend technologies and Java as allways the devil is in the details.&lt;br /&gt;
&lt;br /&gt;
Have fun!&lt;br /&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://pieterroskam.blogspot.com/feeds/5655494673935769639/comments/default' title='Reacties posten'/><link rel='replies' type='text/html' href='http://pieterroskam.blogspot.com/2014/09/node-js-reading-json-from-rest-service.html#comment-form' title='0 reacties'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2919956819843973860/posts/default/5655494673935769639'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2919956819843973860/posts/default/5655494673935769639'/><link rel='alternate' type='text/html' href='http://pieterroskam.blogspot.com/2014/09/node-js-reading-json-from-rest-service.html' title='Node.js reading json from rest service'/><author><name>java by experience</name><uri>http://www.blogger.com/profile/07404653852761857615</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2919956819843973860.post-8341670375735923500</id><published>2014-09-05T04:43:00.002-07:00</published><updated>2014-09-09T13:26:03.721-07:00</updated><title type='text'>Hello world with node.js</title><content type='html'>&lt;b&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;Introduction:&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/b&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;In my previous post I wrote about the clean separation of concerns by using a javascript server like node.js. In the past I worked on a project where they used node.js but personally I never got involved. I wrote the backend part of the system where we used rest services that returned json as an answer for the node.js server (javascript can handle json).&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;So curiousity killed the cat but made man kind evolve. So I tried to set this up on my linux machine. Googled around a bit and found the answers to my questions.&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;b&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;Installation:&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/b&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;actually on linux it is pretty basic if you have git running:&lt;/span&gt;&lt;br /&gt;
&lt;div style=&quot;color: #3c3c3c; line-height: 18px;&quot;&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;b&gt;My attempt under debian:&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;ul&gt;
&lt;li&gt;&lt;span style=&quot;background-color: white; color: #3c3c3c; font-family: inherit; line-height: 18px;&quot;&gt;git clone --depth 1 git://github.com/joyent/node.git&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;background-color: white; color: #3c3c3c; font-family: inherit; line-height: 18px;&quot;&gt;cd node&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;background-color: white; color: #3c3c3c; font-family: inherit; line-height: 18px;&quot;&gt;git checkout v0.4.11&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;background-color: white; color: #3c3c3c; font-family: inherit; line-height: 18px;&quot;&gt;export &lt;/span&gt;&lt;a href=&quot;http://www.hongkiat.com/blog/out/freelancer&quot; rel=&quot;nofollow&quot; style=&quot;background-color: white; border: 0px; color: #133c9a; font-family: inherit; font-style: inherit; font-weight: inherit; line-height: 18px; margin: 0px; padding: 0px; vertical-align: baseline;&quot; target=&quot;_blank&quot;&gt;JOBS&lt;/a&gt;&lt;span style=&quot;background-color: white; color: #3c3c3c; font-family: inherit; line-height: 18px;&quot;&gt;=2&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;background-color: white; color: #3c3c3c; font-family: inherit; line-height: 18px;&quot;&gt;mkdir ~/local&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;background-color: white; color: #3c3c3c; font-family: inherit; line-height: 18px;&quot;&gt;./configure --prefix=$HOME/local/node&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;background-color: white; color: #3c3c3c; font-family: inherit; line-height: 18px;&quot;&gt;make&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;background-color: white; color: #3c3c3c; font-family: inherit; line-height: 18px;&quot;&gt;make install&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;background-color: white; color: #3c3c3c; font-family: inherit; line-height: 18px;&quot;&gt;echo &#39;export PATH=$HOME/local/node/bin:$PATH&#39; &amp;gt;&amp;gt; ~/.profile&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;background-color: white; color: #3c3c3c; font-family: inherit; line-height: 18px;&quot;&gt;echo &#39;export NODE_PATH=$HOME/local/node:$HOME/local/node/lib/node_modules&#39; &amp;gt;&amp;gt; ~/.profile&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;background-color: white; color: #3c3c3c; font-family: inherit; line-height: 18px;&quot;&gt;source ~/.profile&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;br /&gt;
&lt;div style=&quot;background-color: white; border: 0px; margin-bottom: 1.5em; margin-top: 1.5em; padding: 0px; vertical-align: baseline;&quot;&gt;
&lt;div style=&quot;color: #3c3c3c; line-height: 18px;&quot;&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;b&gt;My attempt under ubuntu:&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;line-height: 18px;&quot;&gt;
&lt;/div&gt;
&lt;ul style=&quot;color: #3c3c3c;&quot;&gt;
&lt;li&gt;sudo apt-get install curl&lt;/li&gt;
&lt;li&gt;curl -sL https://deb.nodesource.com/setup | sudo bash -&lt;/li&gt;
&lt;li&gt;sudo apt-get install nodejs&lt;/li&gt;
&lt;/ul&gt;
&lt;div&gt;
&lt;span style=&quot;color: red;&quot;&gt;(The path under ubuntu will bie /usr/bin/node)&lt;/span&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div style=&quot;color: #3c3c3c; line-height: 18px;&quot;&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;color: #3c3c3c; line-height: 18px;&quot;&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;After you done litterly this (take care of the $PATH ELEMENTS. You need to replace them with the real path where you put the node server).&amp;nbsp;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div style=&quot;background-color: white; border: 0px; color: #3c3c3c; line-height: 18px; margin-bottom: 1.5em; margin-top: 1.5em; padding: 0px; vertical-align: baseline;&quot;&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;after this you can create a test.js in any folder you like containing:&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;background-color: white; border: 0px; margin-bottom: 1.5em; margin-top: 1.5em; padding: 0px; vertical-align: baseline;&quot;&gt;
&lt;span style=&quot;color: red; font-family: inherit;&quot;&gt;&lt;span style=&quot;line-height: 18px;&quot;&gt;//require is the import in java&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;background-color: white; border: 0px; margin-bottom: 1.5em; margin-top: 1.5em; padding: 0px; vertical-align: baseline;&quot;&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;span style=&quot;color: #3c3c3c; line-height: 18px;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: #3c3c3c;&quot;&gt;&lt;span style=&quot;line-height: 18px;&quot;&gt;var http = require(&#39;http&#39;);&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;background-color: white; border: 0px; margin-bottom: 1.5em; margin-top: 1.5em; padding: 0px; vertical-align: baseline;&quot;&gt;
&lt;span style=&quot;color: #3c3c3c; line-height: 18px;&quot;&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;// Configure our HTTP server to respond with Hello World to all requests.&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;background-color: white; border: 0px; margin-bottom: 1.5em; margin-top: 1.5em; padding: 0px; vertical-align: baseline;&quot;&gt;
&lt;span style=&quot;color: red; font-family: inherit;&quot;&gt;&lt;span style=&quot;line-height: 18px;&quot;&gt;//creating the http server&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;background-color: white; border: 0px; margin-bottom: 1.5em; margin-top: 1.5em; padding: 0px; vertical-align: baseline;&quot;&gt;
&lt;span style=&quot;color: #3c3c3c; font-family: inherit;&quot;&gt;&lt;span style=&quot;line-height: 18px;&quot;&gt;var server = http.createServer(function (request, response) {&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;background-color: white; border: 0px; margin-bottom: 1.5em; margin-top: 1.5em; padding: 0px; vertical-align: baseline;&quot;&gt;
&lt;span style=&quot;color: red; font-family: inherit;&quot;&gt;&lt;span style=&quot;line-height: 18px;&quot;&gt;//bare writing to the response like in the old days with Java.&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;background-color: white; border: 0px; margin-bottom: 1.5em; margin-top: 1.5em; padding: 0px; vertical-align: baseline;&quot;&gt;
&lt;span style=&quot;color: #3c3c3c; font-family: inherit;&quot;&gt;&lt;span style=&quot;line-height: 18px;&quot;&gt;&amp;nbsp; response.writeHead(200, {&quot;Content-Type&quot;: &quot;text/plain&quot;});&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;background-color: white; border: 0px; margin-bottom: 1.5em; margin-top: 1.5em; padding: 0px; vertical-align: baseline;&quot;&gt;
&lt;span style=&quot;color: #3c3c3c; font-family: inherit;&quot;&gt;&lt;span style=&quot;line-height: 18px;&quot;&gt;&amp;nbsp; response.end(&quot;Hello World\n&quot;);&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;background-color: white; border: 0px; margin-bottom: 1.5em; margin-top: 1.5em; padding: 0px; vertical-align: baseline;&quot;&gt;
&lt;span style=&quot;color: #3c3c3c; font-family: inherit;&quot;&gt;&lt;span style=&quot;line-height: 18px;&quot;&gt;});&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;background-color: white; border: 0px; margin-bottom: 1.5em; margin-top: 1.5em; padding: 0px; vertical-align: baseline;&quot;&gt;
&lt;span style=&quot;font-family: inherit; line-height: 18px;&quot;&gt;&lt;span style=&quot;color: red;&quot;&gt;// Listen on port 8000, IP defaults to 127.0.0.1&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;background-color: white; border: 0px; margin-bottom: 1.5em; margin-top: 1.5em; padding: 0px; vertical-align: baseline;&quot;&gt;
&lt;span style=&quot;color: #3c3c3c; font-family: inherit;&quot;&gt;&lt;span style=&quot;line-height: 18px;&quot;&gt;server.listen(8090);&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;background-color: white; border: 0px; margin-bottom: 1.5em; margin-top: 1.5em; padding: 0px; vertical-align: baseline;&quot;&gt;
&lt;span style=&quot;color: red; font-family: inherit; line-height: 18px;&quot;&gt;// Put a friendly message on the terminal&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;background-color: white; border: 0px; margin-bottom: 1.5em; margin-top: 1.5em; padding: 0px; vertical-align: baseline;&quot;&gt;
&lt;span style=&quot;color: #3c3c3c; font-family: inherit;&quot;&gt;&lt;span style=&quot;line-height: 18px;&quot;&gt;console.log(&quot;Server running at http://127.0.0.1:8090/&quot;);&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;background-color: white; border: 0px; margin-bottom: 1.5em; margin-top: 1.5em; padding: 0px; vertical-align: baseline;&quot;&gt;
&lt;span style=&quot;color: #3c3c3c;&quot;&gt;&lt;span style=&quot;line-height: 18px;&quot;&gt;After you saved the file you have to tell nodejs that he has to start this application:&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;background-color: white; border: 0px; margin-bottom: 1.5em; margin-top: 1.5em; padding: 0px; vertical-align: baseline;&quot;&gt;
&lt;/div&gt;
&lt;ol&gt;
&lt;li&gt;&lt;span style=&quot;color: #3c3c3c; line-height: 18px;&quot;&gt;./node test.js in your console in the node directory&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;color: #3c3c3c; line-height: 18px;&quot;&gt;Start a browser on the desired port 8090 in my case&lt;/span&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;div&gt;
&lt;span style=&quot;color: #3c3c3c;&quot;&gt;&lt;span style=&quot;line-height: 18px;&quot;&gt;The result should be hello world on a snowy white page.&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;color: #3c3c3c;&quot;&gt;&lt;span style=&quot;line-height: 18px;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;color: #3c3c3c;&quot;&gt;&lt;span style=&quot;line-height: 18px;&quot;&gt;have fun!&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://pieterroskam.blogspot.com/feeds/8341670375735923500/comments/default' title='Reacties posten'/><link rel='replies' type='text/html' href='http://pieterroskam.blogspot.com/2014/09/hello-world-with-nodejs.html#comment-form' title='0 reacties'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2919956819843973860/posts/default/8341670375735923500'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2919956819843973860/posts/default/8341670375735923500'/><link rel='alternate' type='text/html' href='http://pieterroskam.blogspot.com/2014/09/hello-world-with-nodejs.html' title='Hello world with node.js'/><author><name>java by experience</name><uri>http://www.blogger.com/profile/07404653852761857615</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2919956819843973860.post-8997155189640042771</id><published>2014-09-02T01:08:00.001-07:00</published><updated>2014-09-04T03:54:37.811-07:00</updated><title type='text'>separating the frontend from the backend</title><content type='html'>&lt;b&gt;Introduction&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;
Through the years I seen a couple of application architectures. Some of them had the multi tier design but where &amp;nbsp;still one war file. I never seen that as a bad design. That was the best available way. The fun part of a way like that was that the architect had to defend the borders between the layers. That is where the weak point in this architecture lies. It is easy for a developer, for what ever reason, to cross the borders and start mixing the responsibilities of the different tiers. This is the first step of downgrading an well setup application to a kind of chaos architecture.&lt;br /&gt;
&lt;br /&gt;
As allways in time ideas improve. A couple of years ago we suddenly had SOA. The backend logic was pushed back into REST or SOAP services with a separate project that was the frontend. The downside of this architecture was, that the html code was still infected with tags from java frameworks. Fore example&lt;br /&gt;
JSF had is own XHTML and even the newer like Wicket have there own tags. The most Frontend guys dont like that. They know html and they dont want to know about all the java frameworks.&lt;br /&gt;
&lt;br /&gt;
The other downside of weaving the java frameworks into html is: that if the compagny decides that in some cases it should not be Java but something like PHP or Ruby etc... they still endup with a java frontend framework.&lt;br /&gt;
&lt;br /&gt;
Now we enter a time where the possibilities to separate the frontend from the backend in a sharper and smarter way. It is possible to run a frontend tier completely on a javascript based server like node.js. Here is a list of&amp;nbsp;&lt;a href=&quot;http://en.wikipedia.org/wiki/Comparison_of_server-side_JavaScript_solutions&quot;&gt;js solutions&lt;/a&gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;The architecture:&lt;/b&gt;&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjUYVUFTRqZf801sjGxZmhb3JvfxTsNmmjDE2nJRfomufrCYy-DAayzZe32WvBfpBBap5Z5zRp848OWPTOcZvFpFnPSfyTuoMv-r0GzHRQlEG31Vte5IZk1vPa-kgyf1rqp0fLQQoJrLeE/s1600/Node_Architecture.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjUYVUFTRqZf801sjGxZmhb3JvfxTsNmmjDE2nJRfomufrCYy-DAayzZe32WvBfpBBap5Z5zRp848OWPTOcZvFpFnPSfyTuoMv-r0GzHRQlEG31Vte5IZk1vPa-kgyf1rqp0fLQQoJrLeE/s1600/Node_Architecture.png&quot; height=&quot;298&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;b&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;/b&gt;

&lt;br /&gt;
Behind teh node js server part you can build as many java rest services as needed. Now we have a complete separation from the frontend and the backend. On the node.js server it is also possible to declare small html objects like textboxes or buttons etc...&lt;br /&gt;
&lt;br /&gt;
Conclusion:&lt;br /&gt;
&lt;br /&gt;
There are allready compagnies working on a application architecture like this or have in place. It requires to see the frontend as separate specialism and for that you need people that know how to deal with a frontend architecture like this. As a backend developer you have to let te responsibility for the frontend go and concentrate on what you can do actually the best backend development.&lt;br /&gt;
&lt;br /&gt;
Have fun!&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://pieterroskam.blogspot.com/feeds/8997155189640042771/comments/default' title='Reacties posten'/><link rel='replies' type='text/html' href='http://pieterroskam.blogspot.com/2014/09/separating-frontend-from-backend.html#comment-form' title='0 reacties'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2919956819843973860/posts/default/8997155189640042771'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2919956819843973860/posts/default/8997155189640042771'/><link rel='alternate' type='text/html' href='http://pieterroskam.blogspot.com/2014/09/separating-frontend-from-backend.html' title='separating the frontend from the backend'/><author><name>java by experience</name><uri>http://www.blogger.com/profile/07404653852761857615</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjUYVUFTRqZf801sjGxZmhb3JvfxTsNmmjDE2nJRfomufrCYy-DAayzZe32WvBfpBBap5Z5zRp848OWPTOcZvFpFnPSfyTuoMv-r0GzHRQlEG31Vte5IZk1vPa-kgyf1rqp0fLQQoJrLeE/s72-c/Node_Architecture.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2919956819843973860.post-3793047205069452740</id><published>2014-08-11T23:47:00.000-07:00</published><updated>2014-08-11T23:47:37.685-07:00</updated><title type='text'>From String to calculation</title><content type='html'>&lt;b&gt;Introduction:&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;
After the marshalling drill I have been thinking about how can we do small changes in xml without marshalling. The only other option I could come up with is xpath queries combined with element value changes. For primitive type changes this is a good idea but what if someone needs some complex calculations with a value from the xml file. Even this can be done.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;The solution:&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;
What I could think of was some kind of calculation template in a String something&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;color: red;&quot;&gt;//The numbers to calculate.&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; int number1 = 40;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; int number2 = 2;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;color: red;&quot;&gt;//Creating the javascript engine&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ScriptEngineManager mgr = new ScriptEngineManager();&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ScriptEngine engine = mgr.getEngineByName(&quot;JavaScript&quot;);&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;color: red;&quot;&gt;//The calculation template can be more complex&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; String calcuationTemplate = &quot;%d * %d&quot;;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; calcuationTemplate = String.format(calcuationTemplate, number1,number2);&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; try {&lt;br /&gt;
&lt;span style=&quot;color: red;&quot;&gt;//The actual calculation&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; System.out.println(engine.eval(calcuationTemplate));&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; } catch (ScriptException e) {&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; e.printStackTrace();&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;br /&gt;
&amp;nbsp; &amp;nbsp; }&lt;br /&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b&gt;The conclusion:&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
After some googling and trying I found that yet again this is pretty simple. With this I can do as much math I like in a very simple way. The only thing I still have to take care of is a difference between the numbers that have been given and the numbers that are retrieved from the xml file.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
have fun!&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://pieterroskam.blogspot.com/feeds/3793047205069452740/comments/default' title='Reacties posten'/><link rel='replies' type='text/html' href='http://pieterroskam.blogspot.com/2014/08/from-string-to-calculation.html#comment-form' title='0 reacties'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2919956819843973860/posts/default/3793047205069452740'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2919956819843973860/posts/default/3793047205069452740'/><link rel='alternate' type='text/html' href='http://pieterroskam.blogspot.com/2014/08/from-string-to-calculation.html' title='From String to calculation'/><author><name>java by experience</name><uri>http://www.blogger.com/profile/07404653852761857615</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2919956819843973860.post-3331376040283808493</id><published>2014-08-08T03:27:00.001-07:00</published><updated>2014-08-08T03:27:25.720-07:00</updated><title type='text'>replace diacritic characters </title><content type='html'>&lt;b&gt;Introduction:&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;
We had a request to remove all the&amp;nbsp;diacritic&lt;span style=&quot;background-color: white; color: #3a87ad; font-family: &#39;Helvetica Neue&#39;, Helvetica, Arial, sans-serif; font-size: 12px; line-height: 20px;&quot;&gt;&amp;nbsp;&lt;/span&gt;&amp;nbsp;from a String. As usual Java has a nice solution for this.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Solution:&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;
String str = &quot;ÚÝâ&quot;;&lt;br /&gt;
&lt;br /&gt;
String nfdNormalizedString = Normalizer.normalize(str, Normalizer.Form.NFD);&lt;br /&gt;
Pattern pattern = Pattern .compile(&quot;\\p{InCombiningDiacriticalMarks}+&quot;);&lt;br /&gt;
&lt;br /&gt;
System.out.println(pattern.matcher(nfdNormalizedString).replaceAll(&quot;&quot;));&lt;br /&gt;
&lt;br /&gt;
result:&amp;nbsp;UYa&lt;br /&gt;
&lt;br /&gt;
The Normalizer class according to the javadoc:&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;This class provides the method normalize which transforms Unicode&lt;br /&gt;
&amp;nbsp;text into an equivalent composed or decomposed form, allowing for easier&lt;br /&gt;
&amp;nbsp;sorting and searching of text.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;div&gt;
Normalizer.Form.NFD&lt;/div&gt;
&lt;div&gt;
This is an Enum that tells the Normalizer class what kind of normalisation you want there are:&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;div&gt;
&lt;span style=&quot;color: red;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;/**&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;color: red;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;* Canonical decomposition.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;color: red;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;*/&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; NFD,&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;color: red;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; /**&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;color: red;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;* Canonical decomposition, followed by canonical composition.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;color: red;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;*/&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; NFC,&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;color: red;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; /**&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;color: red;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;* Compatibility decomposition.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;color: red;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;*/&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; NFKD,&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;color: red;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; /**&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;color: red;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;* Compatibility decomposition, followed by canonical composition.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;color: red;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;*/&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; NFKC&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
The NFD variant decomposes the Ú in U and &#39; this makes it possible to do a regular expression like&amp;nbsp;&lt;/div&gt;
&lt;div&gt;
Pattern pattern = Pattern .compile(&quot;\\p{InCombiningDiacriticalMarks}+&quot;);&lt;br /&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
At last but not least the question we had was: what in heavens name is \\p{InCombiningDiacriticalMarks}&lt;/div&gt;
&lt;div&gt;
This answer we found at stackoverflow:&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;code style=&quot;background: rgb(238, 238, 238); border: 0px; font-family: Consolas, Menlo, Monaco, &#39;Lucida Console&#39;, &#39;Liberation Mono&#39;, &#39;DejaVu Sans Mono&#39;, &#39;Bitstream Vera Sans Mono&#39;, &#39;Courier New&#39;, monospace, serif; font-size: 14px; line-height: 17.804800033569336px; margin: 0px; padding: 1px 5px; vertical-align: baseline; white-space: pre-wrap;&quot;&gt;\p{InCombiningDiacriticalMarks}&lt;/code&gt;&lt;span style=&quot;background-color: white; font-family: Arial, &#39;Liberation Sans&#39;, &#39;DejaVu Sans&#39;, sans-serif; font-size: 14px; line-height: 17.804800033569336px;&quot;&gt;&amp;nbsp;is a Unicode block property. In JDK7, you will be able to write it using the two-part notation&amp;nbsp;&lt;/span&gt;&lt;code style=&quot;background: rgb(238, 238, 238); border: 0px; font-family: Consolas, Menlo, Monaco, &#39;Lucida Console&#39;, &#39;Liberation Mono&#39;, &#39;DejaVu Sans Mono&#39;, &#39;Bitstream Vera Sans Mono&#39;, &#39;Courier New&#39;, monospace, serif; font-size: 14px; line-height: 17.804800033569336px; margin: 0px; padding: 1px 5px; vertical-align: baseline; white-space: pre-wrap;&quot;&gt;\p{Block=CombiningDiacriticalMarks}&lt;/code&gt;&lt;span style=&quot;background-color: white; font-family: Arial, &#39;Liberation Sans&#39;, &#39;DejaVu Sans&#39;, sans-serif; font-size: 14px; line-height: 17.804800033569336px;&quot;&gt;, which may be clearer to the reader. It is documented&amp;nbsp;&lt;/span&gt;&lt;a href=&quot;http://www.unicode.org/reports/tr44/#Properties&quot; style=&quot;background: rgb(255, 255, 255); border: 0px; color: #4a6b82; cursor: pointer; font-family: Arial, &#39;Liberation Sans&#39;, &#39;DejaVu Sans&#39;, sans-serif; font-size: 14px; line-height: 17.804800033569336px; margin: 0px; padding: 0px; text-decoration: none; vertical-align: baseline;&quot;&gt;here in UAX#44: “The Unicode Character Database”&lt;/a&gt;&lt;span style=&quot;background-color: white; font-family: Arial, &#39;Liberation Sans&#39;, &#39;DejaVu Sans&#39;, sans-serif; font-size: 14px; line-height: 17.804800033569336px;&quot;&gt;.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b&gt;Conclusion:&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
The code we build today is just a tip of the iceberg. The functionality that the Normalizer can bring is much more. I hope in the future I can do some other stuff with this.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
Have fun!&amp;nbsp;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://pieterroskam.blogspot.com/feeds/3331376040283808493/comments/default' title='Reacties posten'/><link rel='replies' type='text/html' href='http://pieterroskam.blogspot.com/2014/08/replace-diacritic-characters.html#comment-form' title='0 reacties'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2919956819843973860/posts/default/3331376040283808493'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2919956819843973860/posts/default/3331376040283808493'/><link rel='alternate' type='text/html' href='http://pieterroskam.blogspot.com/2014/08/replace-diacritic-characters.html' title='replace diacritic characters '/><author><name>java by experience</name><uri>http://www.blogger.com/profile/07404653852761857615</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2919956819843973860.post-4627679657585694821</id><published>2014-08-05T03:51:00.000-07:00</published><updated>2014-08-05T12:49:43.339-07:00</updated><title type='text'>open closed Marshalling with Jaxb</title><content type='html'>&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;b&gt;Introduction&lt;/b&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
One of the things we had to tackle this week was some marshalling issue with a zillion small xml files. The feast of legacy. It was a very depressing thought to create separate marshalling objects for each of them. That Idea popped faster out of my head then in. After some thinking we came up with a component that could do all of the xml files&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;b&gt;The solution&lt;/b&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
The idea I came up with is very simple it is base on Jaxb marshalling which is quit powerfull in the way that the code you need to write is very small. Also the speed of marshalling and unmarshalling is quit fast.&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
To get this to work you need the following dependencies:&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&amp;lt;dependencies&amp;gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;lt;dependency&amp;gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;groupId&amp;gt;javax.xml.bind&amp;lt;/groupId&amp;gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;artifactId&amp;gt;jaxb-api&amp;lt;/artifactId&amp;gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;version&amp;gt;2.1&amp;lt;/version&amp;gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;lt;/dependency&amp;gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;lt;dependency&amp;gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;groupId&amp;gt;com.sun.xml.bind&amp;lt;/groupId&amp;gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;artifactId&amp;gt;jaxb-impl&amp;lt;/artifactId&amp;gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;version&amp;gt;2.1&amp;lt;/version&amp;gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;lt;/dependency&amp;gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;lt;dependency&amp;gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;groupId&amp;gt;org.projectlombok&amp;lt;/groupId&amp;gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;artifactId&amp;gt;lombok&amp;lt;/artifactId&amp;gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;version&amp;gt;1.14.4&amp;lt;/version&amp;gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;lt;/dependency&amp;gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;lt;dependency&amp;gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;groupId&amp;gt;junit&amp;lt;/groupId&amp;gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;artifactId&amp;gt;junit&amp;lt;/artifactId&amp;gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;version&amp;gt;4.11&amp;lt;/version&amp;gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;lt;/dependency&amp;gt;&lt;br /&gt;
&lt;span style=&quot;color: red;&quot;&gt;&amp;nbsp; &amp;nbsp;//This one you only need when you want to use xpath queries&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;lt;dependency&amp;gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;groupId&amp;gt;org.eclipse.persistence&amp;lt;/groupId&amp;gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;artifactId&amp;gt;eclipselink&amp;lt;/artifactId&amp;gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;version&amp;gt;2.5.0&amp;lt;/version&amp;gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;lt;/dependency&amp;gt;&lt;br /&gt;
&amp;lt;/dependencies&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The one and only class for marshalling and unmarshalling:&lt;br /&gt;
&lt;br /&gt;
package nl.lostlemon.Marshal;&lt;br /&gt;
&lt;br /&gt;
import javax.xml.bind.JAXBContext;&lt;br /&gt;
import javax.xml.bind.JAXBException;&lt;br /&gt;
import javax.xml.bind.Marshaller;&lt;br /&gt;
import javax.xml.bind.PropertyException;&lt;br /&gt;
import javax.xml.bind.Unmarshaller;&lt;br /&gt;
import javax.xml.stream.XMLInputFactory;&lt;br /&gt;
import javax.xml.stream.XMLStreamException;&lt;br /&gt;
import javax.xml.stream.XMLStreamReader;&lt;br /&gt;
import java.io.ByteArrayOutputStream;&lt;br /&gt;
import java.io.InputStream;&lt;br /&gt;
&lt;br /&gt;
/&lt;span style=&quot;color: red;&quot;&gt;/The Type is to make it possible to instanciate this class with different marshalling beans.&lt;/span&gt;&lt;br /&gt;
public class Marshalling&amp;lt;T&amp;gt; {&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&lt;span style=&quot;color: red;&quot;&gt; &amp;nbsp; // Notice that T is the return typed bean. The xm is an inputStream. Jaxb can deal with that. It improves &amp;nbsp; &amp;nbsp; &amp;nbsp; performance&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: red;&quot;&gt;&amp;nbsp;&lt;/span&gt; &amp;nbsp; public T unMarshall(final InputStream xmlStream, final Class clazz) {&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; T value = null;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; try {&lt;br /&gt;
&lt;span style=&quot;color: red;&quot;&gt;//create an unmarshaller&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Unmarshaller unmarshal = JAXBContext.newInstance(clazz).createUnmarshaller();&lt;br /&gt;
&lt;span style=&quot;color: red;&quot;&gt;//read the xml input stream into Jaxb&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; XMLStreamReader reader = XMLInputFactory.newInstance().createXMLStreamReader(xmlStream);&lt;br /&gt;
&lt;span style=&quot;color: red;&quot;&gt;//marshall the xml file into a JavaBean&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; value = (T)unmarshal.unmarshal(reader, clazz).getValue();&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; } catch (JAXBException e) {&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; e.printStackTrace();&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; } catch (XMLStreamException e) {&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; e.printStackTrace();&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; return value;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; }&lt;br /&gt;
&lt;span style=&quot;color: red;&quot;&gt;//Notice that the parameter is also The T of type.&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; public ByteArrayOutputStream marshal(final T type) {&lt;br /&gt;
&lt;span style=&quot;color: red;&quot;&gt;//Create the return type for this method.&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ByteArrayOutputStream outputStream = new ByteArrayOutputStream();&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; try {&lt;br /&gt;
&lt;span style=&quot;color: red;&quot;&gt;//Create a marshaller&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Marshaller marshaller = JAXBContext.newInstance(type.getClass()).createMarshaller();&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);&lt;br /&gt;
&lt;span style=&quot;color: red;&quot;&gt;//Create the xml in the form of an outputstream to boost performance&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; marshaller.marshal(type, outputStream);&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; } catch (PropertyException e1) {&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; e1.printStackTrace();&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; } catch (JAXBException e1) {&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; e1.printStackTrace();&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; return &amp;nbsp;outputStream;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; }&lt;br /&gt;
}&lt;br /&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
Running the following tests:&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;color: red;&quot;&gt;//This test uses the BookBean with an xml containing a single book.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; @Test&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; public void testUnmarshallingXpath() {&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; InputStream inputStream = this.getClass().getResourceAsStream(&quot;testSingle.xml&quot;);&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Marshalling&amp;lt;SingleBookBean&amp;gt; marshalling = new Marshalling&amp;lt;SingleBookBean&amp;gt;();&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; SingleBookBean bookBean = marshalling.unMarshall(inputStream,SingleBookBean.class);&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Assert.assertTrue(bookBean.getTitle() != null);&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; }&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;color: red;&quot;&gt;// The BookBean the&amp;nbsp;@Getter and @Setter is from Lombok.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;color: red;&quot;&gt;// Take care of the&amp;nbsp;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;div&gt;
&lt;span style=&quot;color: red;&quot;&gt;@XmlRootElement(name = &quot;book&quot;)&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;color: red;&quot;&gt;@XmlAccessorType(XmlAccessType.FIELD) These are the identifiers to tell JaxB what to do. The&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: red;&quot;&gt;XmlRootElement refers to the xml rootelement in the xml file.&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;div&gt;
@Getter&lt;/div&gt;
&lt;div&gt;
@Setter&lt;/div&gt;
&lt;div&gt;
@XmlRootElement(name = &quot;book&quot;)&lt;/div&gt;
&lt;div&gt;
@XmlAccessorType(XmlAccessType.FIELD)&lt;/div&gt;
&lt;div&gt;
public class BookBean {&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &lt;span style=&quot;color: red;&quot;&gt;// These are the exact same names as the xml Elements&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; private String author;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; private String title;&lt;/div&gt;
&lt;div&gt;
}&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;color: red;&quot;&gt;//The single xml file:&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&amp;lt;book&amp;gt;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;lt;title&amp;gt;witches abroad&amp;lt;/title&amp;gt;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;lt;author&amp;gt;Terry Pratchet&amp;lt;/author&amp;gt;&lt;/div&gt;
&lt;div&gt;
&amp;lt;/book&amp;gt;&lt;/div&gt;
&lt;div&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;color: red;&quot;&gt;//This test is using the books bean with an xml containing multiple books.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; @Test&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; public void testUnmarshallingList() {&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; long start = Calendar.getInstance().getTimeInMillis();&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; InputStream inputStream = this.getClass().getResourceAsStream(&quot;test.xml&quot;);&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Marshalling&amp;lt;Books&amp;gt; marshalling = new Marshalling();&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Books books = marshalling.unMarshall(inputStream,Books.class);&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; //Assert.assertTrue(books.getBookBeans().size() == 3);&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; long stop = Calendar.getInstance().getTimeInMillis();&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; long elapsedTime = (stop-start);&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; System.out.println(&quot;number of elements &quot; + books.getBookBeans().size() + &quot; elapsed time &quot; + elapsedTime + &quot; ms&quot;);&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; }&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;span style=&quot;color: red;&quot;&gt;// The Books bean based on the same principle as the BookBean.&lt;/span&gt;&lt;br /&gt;
@XmlRootElement(name = &quot;catalog&quot;)&lt;br /&gt;
@XmlAccessorType(XmlAccessType.FIELD)&lt;br /&gt;
public class Books {&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; @Getter&lt;br /&gt;
&amp;nbsp; &amp;nbsp; @Setter&lt;br /&gt;
&amp;nbsp; &amp;nbsp; @XmlElement(name = &quot;book&quot;, type = BookBean.class)&lt;br /&gt;
&amp;nbsp; &amp;nbsp; private List&amp;lt;BookBean&amp;gt; bookBeans;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;color: red;&quot;&gt;//the multiple books xml file:&lt;/span&gt;&lt;br /&gt;
&amp;lt;catalog&amp;gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;lt;book id=&quot;bk101&quot;&amp;gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;author&amp;gt;Gambardella, Matthew&amp;lt;/author&amp;gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;title&amp;gt;XML Developer&#39;s Guide&amp;lt;/title&amp;gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;genre&amp;gt;Computer&amp;lt;/genre&amp;gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;price&amp;gt;44.95&amp;lt;/price&amp;gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;publish_date&amp;gt;2000-10-01&amp;lt;/publish_date&amp;gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;description&amp;gt;An in-depth look at creating applications&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; with XML.&amp;lt;/description&amp;gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;lt;/book&amp;gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;lt;book id=&quot;bk102&quot;&amp;gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;author&amp;gt;Ralls, Kim&amp;lt;/author&amp;gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;title&amp;gt;Midnight Rain&amp;lt;/title&amp;gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;genre&amp;gt;Fantasy&amp;lt;/genre&amp;gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;price&amp;gt;5.95&amp;lt;/price&amp;gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;publish_date&amp;gt;2000-12-16&amp;lt;/publish_date&amp;gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;description&amp;gt;A former architect battles corporate zombies,&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; an evil sorceress, and her own childhood to become queen&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; of the world.&amp;lt;/description&amp;gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;lt;/book&amp;gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;lt;book id=&quot;bk103&quot;&amp;gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;author&amp;gt;Corets, Eva&amp;lt;/author&amp;gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;title&amp;gt;Maeve Ascendant&amp;lt;/title&amp;gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;genre&amp;gt;Fantasy&amp;lt;/genre&amp;gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;price&amp;gt;5.95&amp;lt;/price&amp;gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;publish_date&amp;gt;2000-11-17&amp;lt;/publish_date&amp;gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;description&amp;gt;After the collapse of a nanotechnology&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; society in England, the young survivors lay the&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; foundation for a new society.&amp;lt;/description&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;lt;/book&amp;gt;&lt;br /&gt;
&lt;div&gt;
&amp;lt;/catalog&amp;gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;color: red;&quot;&gt;//The marshalling test with the books bean&lt;/span&gt;:&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; @Test&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; public void testMarshallingList() {&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Books books = new Books();&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; List&amp;lt;BookBean&amp;gt; bookBeans = new ArrayList&amp;lt;BookBean&amp;gt;();&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; for(int i=0;i&amp;lt;100000;i++) {&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; BookBean bookBean = new BookBean();&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; bookBean.setAuthor(&quot;J.R.R Tolkien&quot;);&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; bookBean.setTitle(&quot;The hobbit&quot;);&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; bookBeans.add(bookBean);&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; books.setBookBeans(bookBeans);&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; long start = Calendar.getInstance().getTimeInMillis();&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Marshalling&amp;lt;Books&amp;gt; marshalling = new Marshalling&amp;lt;Books&amp;gt;();&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;
}&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;div&gt;
&lt;span style=&quot;color: red;&quot;&gt;// The marshalling test with the BookBean.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp;@Test&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; public void testMarshalling() {&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; BookBean bookBean = new BookBean();&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; bookBean.setAuthor(&quot;Terry Pratchet&quot;);&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; bookBean.setTitle(&quot;Witches abroad&quot;);&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Marshalling&amp;lt;BookBean&amp;gt; marshalling = new Marshalling&amp;lt;BookBean&amp;gt;();&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; String xml = marshalling.marshal(bookBean).toString();&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; }&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b&gt;Conclusion:&amp;nbsp;&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
Using Java typing in combination with a usefull library in the open closed principal, saves you a lot of code writing and maintainance. I had real pleassure to write in such a small piece of code so much power.&amp;nbsp;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
Have fun!&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://pieterroskam.blogspot.com/feeds/4627679657585694821/comments/default' title='Reacties posten'/><link rel='replies' type='text/html' href='http://pieterroskam.blogspot.com/2014/08/open-closed-marshalling-with-jaxb.html#comment-form' title='0 reacties'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2919956819843973860/posts/default/4627679657585694821'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2919956819843973860/posts/default/4627679657585694821'/><link rel='alternate' type='text/html' href='http://pieterroskam.blogspot.com/2014/08/open-closed-marshalling-with-jaxb.html' title='open closed Marshalling with Jaxb'/><author><name>java by experience</name><uri>http://www.blogger.com/profile/07404653852761857615</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2919956819843973860.post-869668289314575231</id><published>2014-06-24T01:37:00.000-07:00</published><updated>2014-06-25T05:01:15.681-07:00</updated><title type='text'>Email Validation</title><content type='html'>&lt;b&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;Introduction&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/b&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;I was strugling with the apache commons email validator. This litle baby was not working according the specs they gave me. After a while I gave up on that and descided against my own rules to build it myself. What I mean with against my own rules is: Dont build if it is out there in a proper library. But in this case I had an exception.&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;The best way to solve this issue was to use a regular expression. Not my favorite but mighty handy when you need them.&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;b&gt;Solution&lt;/b&gt;:&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;The scary part:&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;For those who have no experience with R.E. this might look like cursing in a comic :).&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&quot;^[_A-Za-z0-9-\\+]+(\\.[_A-Za-z0-9-]+)*@[A-Za-z0-9-]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]+)$&quot;;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;Lets analyze this:&lt;/span&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;First lets have a look at the structure and later on we spill some information about the details.&lt;/span&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;The first thing you might notice in the structure are blocks like these [_A-Za-z0-9-\\+]+&lt;/span&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;the A-Z, a-z or 0-9 this means that it contains an character in capitals (A-Z), or in non-capitals(a-z)&lt;/span&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;or digits from 0-9. if the notation is like:&lt;/span&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;[_A-Za-z0-9]&lt;/span&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;It will only search for one character each.&lt;/span&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;if you add a +&amp;nbsp;it means iterate till you can find no more.&lt;/span&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;if you add {2} or {2,5} instead of a + it means only 2 characters or from 2 to 5 characters.&lt;/span&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;In the case of the email validator you also need one .(dot) and one&amp;nbsp;@ as you can see they are not followed by the annotations I described to iterate for more.&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;Some of the details:&lt;/span&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;^ the carrot sign before the brackets means &quot;Starts with&quot; So in this case It can be a multiple underscores, characters or numbers.&lt;/span&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;The ^ inside the brackets means not like [^A-Z] everything but capitals.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;The * is the same as&amp;nbsp;+ &amp;nbsp;occurs 1 or more times (iteration).&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;The $ checks if the end of line is following.&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;Conclusion:&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;It still looks like cursing in a comic or something that gives you an headache. But it is the way forward if you want to check a string on patterns. This whole&amp;nbsp;&lt;/span&gt;exercise is useless without execution. So you still need to use the Pattern and Matcher class (Examples all over the internet).&lt;br /&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;Or use the String.matches method. Will do two.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;Have fun!&amp;nbsp;&lt;/span&gt;</content><link rel='replies' type='application/atom+xml' href='http://pieterroskam.blogspot.com/feeds/869668289314575231/comments/default' title='Reacties posten'/><link rel='replies' type='text/html' href='http://pieterroskam.blogspot.com/2014/06/email-validation.html#comment-form' title='0 reacties'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2919956819843973860/posts/default/869668289314575231'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2919956819843973860/posts/default/869668289314575231'/><link rel='alternate' type='text/html' href='http://pieterroskam.blogspot.com/2014/06/email-validation.html' title='Email Validation'/><author><name>java by experience</name><uri>http://www.blogger.com/profile/07404653852761857615</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2919956819843973860.post-2376278506799025605</id><published>2014-06-09T03:34:00.001-07:00</published><updated>2014-06-09T03:34:46.584-07:00</updated><title type='text'>scraping html with selenium server</title><content type='html'>&lt;b&gt;Introduction:&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;
In this case I &amp;nbsp;tried to create a server that is capable of getting the values from an html file. The first part what is needed I describe here.&lt;br /&gt;
&lt;br /&gt;
The first part is of course to get the html from the url. This part you can do with Selenium Server, this is an java library which integrates selenium into the virtual machine. This is actual not the hardest part. The hardest part I am working currently namely to get crappy html a bit xml compliant.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;The example:&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;
public class Scraper {&lt;br /&gt;
&amp;nbsp; &amp;nbsp; private static &amp;nbsp;final String BROWSER = &quot;*firefox&quot;;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; private static &amp;nbsp;final String SERVER = &quot;localhost&quot;;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; private static &amp;nbsp;final int PORT = 4444;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; private static final String SLASHES = &quot;//&quot;;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; private static final String SLASH = &quot;/&quot;;&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; private DefaultSelenium selenium;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; private String url;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; public Scraper(String url) {&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; this.url = url;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; }&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; public void startScraper() {&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; //&lt;span style=&quot;color: red;&quot;&gt;This is to separate the server from the page where you want to start&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; int startPosition = url.indexOf(SLASHES) &amp;nbsp;+ SLASHES.length();&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; //&lt;span style=&quot;color: red;&quot;&gt;this turns http://google.nl/search into google.nl/search&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; String tmpUrl = url.substring(startPosition);&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; int endPosition = tmpUrl.indexOf(SLASH);&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; //&lt;span style=&quot;color: red;&quot;&gt;this turns http://google.nl/search into google.nl&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; String baseUrl = url.substring(0, endPosition + startPosition);&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;//&lt;span style=&quot;color: red;&quot;&gt;this turns http://google.nl/search into&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: red;&quot;&gt;/search&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; String pageUrl = url.substring(endPosition + startPosition, url.length());&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; //&lt;span style=&quot;color: red;&quot;&gt;instanciate selenium with a port, your browser and the baseUrl&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; selenium = new DefaultSelenium(SERVER, PORT, BROWSER, baseUrl);&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; try {&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; //&lt;span style=&quot;color: red;&quot;&gt;instanciate the selenium server&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; SeleniumServer server = new SeleniumServer();&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; server.start();&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; selenium.start();&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; //&lt;span style=&quot;color: red;&quot;&gt;open the page you like search in this example&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; selenium.open(pageUrl);&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; } catch (Exception e) {&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; e.printStackTrace();&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;br /&gt;
&amp;nbsp; &amp;nbsp; }&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp;//&lt;span style=&quot;color: red;&quot;&gt;This method is the first part for xml compliancy.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: red;&quot;&gt;&amp;nbsp; &amp;nbsp;&lt;/span&gt;//&lt;span style=&quot;color: red;&quot;&gt;In my case the data I want is allways in the body.&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; public String createHTmlOutPutStream () {&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; String htmlSource = selenium.getHtmlSource();&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; int start = htmlSource.indexOf(&quot;&amp;lt;body&quot;);&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; int stop = htmlSource.indexOf(&quot;&amp;lt;/body&amp;gt;&quot;) + 7 ;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; htmlSource = htmlSource.substring(start,stop);&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; return htmlSource;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; }&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; // &lt;span style=&quot;color: red;&quot;&gt;This method fills every textfield if you know the name&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; public void populateTextField(String fieldName, String text) {&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; selenium.type(fieldName, text);&lt;br /&gt;
&amp;nbsp; &amp;nbsp;}&lt;br /&gt;
&amp;nbsp; &lt;br /&gt;
&amp;nbsp; &amp;nbsp;// &lt;span style=&quot;color: red;&quot;&gt;This method clicks the button for you&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; public void clickButton(String buttonName) {&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; selenium.click(buttonName);&lt;br /&gt;
&amp;nbsp; &amp;nbsp; }&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; // &lt;span style=&quot;color: red;&quot;&gt;This method runs through every option in a dropdown list.&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; public void chooseDropDownAll(String dropDownName) {&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; String[] options = &amp;nbsp;selenium.getSelectOptions(&quot;dropDownName&quot;);&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; for (String option : options) {&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; selenium.select(&quot;dropDownName&quot;, option);&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;br /&gt;
&amp;nbsp; &amp;nbsp; }&lt;br /&gt;
&amp;nbsp; &amp;nbsp; // &lt;span style=&quot;color: red;&quot;&gt;This method only picks one option in the dropdown list.&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; public void chooseDropDownSpecific(String dropDownName, String optionName) {&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; selenium.select(&quot;dropDownName&quot;, optionName);&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Conclusion:&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;
With those two libraries:&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;lt;dependency&amp;gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;groupId&amp;gt;org.seleniumhq.selenium&amp;lt;/groupId&amp;gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;artifactId&amp;gt;selenium-firefox-driver&amp;lt;/artifactId&amp;gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;version&amp;gt;2.42.0&amp;lt;/version&amp;gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;/dependency&amp;gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;dependency&amp;gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;groupId&amp;gt;org.seleniumhq.selenium&amp;lt;/groupId&amp;gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;artifactId&amp;gt;selenium-server&amp;lt;/artifactId&amp;gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;version&amp;gt;2.42.0&amp;lt;/version&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;you will be capable of doing this trick. This only a small set of possibilities to discover.&lt;br /&gt;
You should try it, the next thing what I want to do is to write a test that does the login and the first search for me on the project I am working on right now. This because I like programming and not logging in :).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Have fun!</content><link rel='replies' type='application/atom+xml' href='http://pieterroskam.blogspot.com/feeds/2376278506799025605/comments/default' title='Reacties posten'/><link rel='replies' type='text/html' href='http://pieterroskam.blogspot.com/2014/06/scraping-html-with-selenium-server.html#comment-form' title='0 reacties'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2919956819843973860/posts/default/2376278506799025605'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2919956819843973860/posts/default/2376278506799025605'/><link rel='alternate' type='text/html' href='http://pieterroskam.blogspot.com/2014/06/scraping-html-with-selenium-server.html' title='scraping html with selenium server'/><author><name>java by experience</name><uri>http://www.blogger.com/profile/07404653852761857615</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2919956819843973860.post-7349784744143648186</id><published>2014-05-04T07:47:00.001-07:00</published><updated>2014-05-04T08:20:51.396-07:00</updated><title type='text'>Jpa another way of persisting</title><content type='html'>&lt;b&gt;Introduction:&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
To deal with persistence in Java is getting less complicated by the tools that are being offered to us. The complication lies in the fact what to choose and what kind of strategy should you choose. In my previous blog I opened the doors to JPA which i denied to exist for a couple of years. &quot;Just another Hibernate&quot; was my defense. Looking at it from a historical point of view, My thoughts where based on some points. Hibernate was there together with toplnk and EJB to deal with ORM before JPA. These three tools where the bases for the reference called JPA. At last I opened that small and started being interested in JPA. I have to admit it is getting to me. I really like the way the things have been setup. A lot of people that tried to explain to me that JPA gave more freedom, have been shot by me as evangelists. The fun part of the story is, that not there preaching but a project that was using JPA brought me the light.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;The example:&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;
There are a couple of ways to deal with persistence in JPA. The most easy and fun one are repositories. I have them on my list to be study. But for now there is SQL, HQL (hibernate) and JQL (jpa). Sql gives you the straight forward way to acces an database something select * from customers or update customers set name = &#39;john doe&#39; where id = 1 should look familiair. In JQL this looks pretty much the same but you are not talking to the database but to the objects that are representing the database in the application called entities.&lt;br /&gt;
&lt;br /&gt;
So we have a simple Java pojo for customers with a customer name (I like it simple :)):&lt;br /&gt;
Lets use Lombok for fun:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
public class Customer {&lt;br /&gt;
&lt;br /&gt;
@Id&lt;br /&gt;
@GeneratedValue&lt;br /&gt;
@Getter&lt;br /&gt;
@Setter&lt;br /&gt;
private long id;&lt;br /&gt;
&lt;span style=&quot;color: red;&quot;&gt;//lombok annotations.&lt;/span&gt;&lt;br /&gt;
@Getter&lt;br /&gt;
@Setter&lt;br /&gt;
private String name;&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;
}&lt;br /&gt;
&lt;br /&gt;
//&lt;span style=&quot;color: red;&quot;&gt;Now we make it persistable:&lt;/span&gt;&lt;br /&gt;
@Entity&lt;br /&gt;
&lt;span style=&quot;color: red;&quot;&gt;//the table to point to the name is not mandotory if the class has the same name as the database table.&lt;/span&gt;&lt;br /&gt;
@Table(name=&quot;customer&quot;)&lt;br /&gt;
public class Customer {&lt;br /&gt;
&lt;br /&gt;
@Id&lt;br /&gt;
@GeneratedValue&lt;br /&gt;
@Getter&lt;br /&gt;
@Setter&lt;br /&gt;
private long id;&lt;br /&gt;
&lt;span style=&quot;color: red;&quot;&gt;//lombok annotations.&lt;/span&gt;&lt;br /&gt;
@Getter&lt;br /&gt;
@Setter&lt;br /&gt;
&lt;span style=&quot;color: red;&quot;&gt;@Column //you could also use the name attribute if the column name in the table difffers from the class &lt;/span&gt;//member name.&lt;br /&gt;
private String name;&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;
}&lt;br /&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
if JPA is configured correctly this class is coupled to the table now by the ORM of JPA.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
But now my customers are hooked up with the products they bought from me That is going to give me an N to N relation ship. 1 customer can buy multiple products and 1 product could been bought by multiple customers. An N to N relation ship can only achieved through a coupling table in the database. &amp;nbsp;It would be really annoying if the represenation of your class model should be one on one with the database. This means that you would need to model all your coupling tables which yo are not going to need to present your data.&amp;nbsp;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
One of the things we can do is Model it with&amp;nbsp;@named queries in JPA That would look something like this:&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
@Entity&lt;br /&gt;
&lt;span style=&quot;color: red;&quot;&gt;//the table to point to the name is not mandotory if the class has the same name as the database table.&lt;/span&gt;&lt;br /&gt;
@Table(name=&quot;customer&quot;)&lt;br /&gt;
//&lt;span style=&quot;color: red;&quot;&gt;The JPA named query&lt;/span&gt;&lt;br /&gt;
@NamedQuery(name = &quot;selectPrdFromCustomer&quot; , query = &quot;select c.products from Customers c where c.id = ?1 &quot;) })&lt;br /&gt;
public class Customer {&lt;br /&gt;
&lt;br /&gt;
private long id;&lt;br /&gt;
&lt;span style=&quot;color: red;&quot;&gt;//lombok annotations.&lt;/span&gt;&lt;br /&gt;
@Getter&lt;br /&gt;
@Setter&lt;br /&gt;
&lt;span style=&quot;color: red;&quot;&gt;@Column //you could also use the name attribute if the column name in the table difffers from the class&amp;nbsp;&lt;/span&gt;//member name.&lt;br /&gt;
private String name;&lt;br /&gt;
&lt;span style=&quot;color: red;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;color: red;&quot;&gt;//lombok annotations.&lt;/span&gt;&lt;br /&gt;
@Getter&lt;br /&gt;
@Setter&lt;br /&gt;
&lt;div&gt;
&lt;div&gt;
//&lt;span style=&quot;color: red;&quot;&gt;ManyToMany is the equilevant for N to N cascading all means get all the data you can on all the levels allowed.&amp;nbsp;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
@ManyToMany(cascade = CascadeType.ALL)&lt;/div&gt;
&lt;div&gt;
//&lt;span style=&quot;color: red;&quot;&gt;The CUSTOMER_PRODUCT table is the coupling table. The join collumn is the collumn where the id from this class should couple with. the inverseJoinColum is the id of the products where it should couple to.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
@JoinTable(name = &quot;CUSTOMER_PRODUCT&quot;, joinColumns = @JoinColumn(name = &quot;product_id&quot;), inverseJoinColumns = @JoinColumn(name = &quot;id&quot;))&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;
Private List&amp;lt;Products&amp;gt; products&lt;/div&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;
}&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
At this point you can that a normal sql query has been handled on Entity level. The interesting part is that this sql query is separated on two different places. The named query is taking responsibility for the selecting part while the ManyToMany and the JoinTable is taking the responsibility for the coupling part.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
As last you can create an PersistenceController or manager and that would need to do something like this:&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
Public PersistenceController {&lt;/div&gt;
&lt;div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; @PersistenceContext&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; private EntityManager em;&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;
@Setter&lt;/div&gt;
&lt;div&gt;
@Getter&lt;/div&gt;
&lt;div&gt;
private long customerId;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
public List&amp;lt;String getProductNames() {&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
public List&amp;lt;String&amp;gt; product name =&amp;nbsp;em.createNamedQuery(&quot;selectPrdFromCustomer&quot;).setParameter(1, customerId).getSingleResult();&lt;/div&gt;
&lt;div&gt;
//&lt;span style=&quot;color: red;&quot;&gt;The getSingleResult is only applicable if you really want to have one result instead of an list but then the type of the method should be also String and not al list.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
}&lt;/div&gt;
&lt;div&gt;
}&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b&gt;Conclusion:&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
Ones you know how to deal with persistence like this it is easy. But to learn it can give you a bad hadache. It is worth the effort That is for sure. Just try the example that has been given and have FUN!&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://pieterroskam.blogspot.com/feeds/7349784744143648186/comments/default' title='Reacties posten'/><link rel='replies' type='text/html' href='http://pieterroskam.blogspot.com/2014/05/jpa-another-way-of-persisting.html#comment-form' title='0 reacties'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2919956819843973860/posts/default/7349784744143648186'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2919956819843973860/posts/default/7349784744143648186'/><link rel='alternate' type='text/html' href='http://pieterroskam.blogspot.com/2014/05/jpa-another-way-of-persisting.html' title='Jpa another way of persisting'/><author><name>java by experience</name><uri>http://www.blogger.com/profile/07404653852761857615</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2919956819843973860.post-1339663440832311145</id><published>2014-04-26T08:18:00.002-07:00</published><updated>2014-04-26T08:18:38.716-07:00</updated><title type='text'>peristence future arrived</title><content type='html'>&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;b&gt;Introduction:&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;
Traditionally Java and databases have been on friends. &amp;nbsp;Starting with the java persistence libraries where soon enough we could use prepared statements to secure the way we queried the database. After that the world of Java &amp;nbsp;was shocked with the birth of ORM toolings. These babies really decoupled the whole data tier from the rest and saved a lot of work. Implementations of &amp;nbsp;JPA and Eclipse (Top) link helped the word easy up the way of persistence. &amp;nbsp; That the future is allways one step away is common knowledge these days. But in some cases the future allready catched up with me before I realize this. m&lt;br /&gt;
In the case of JPA repositories that happened. I figured this technique out the last couple of weeks and I am already in love with it. They pushed things a little bit further then my imagination would go. It is not Star trek yet but still quite impressive.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;The concept:&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;
The Idea behind this to diminish the boiler plate coding further. The benefits of this I can bring down to two points:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;ol&gt;
&lt;li&gt;After configuring this right which is a bit more work, the coding comes down to allmost nothing.&lt;/li&gt;
&lt;li&gt;Because of the fact that the persistence part is mostly configuration, the repositories them selves can (not necessarily) function as a complete database tier. &amp;nbsp;&lt;/li&gt;
&lt;/ol&gt;
The configuration is a combination between JPA and spring in my example. There might be other implementations out there where I don&#39;t have knowledge of.&lt;br /&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b&gt;The configuration:&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
The configuration I set up is a mix of spring and maven:&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
Maven pom &amp;nbsp;part:&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;lt;properties&amp;gt;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;spring.version&amp;gt;4.0.3.RELEASE&amp;lt;/spring.version&amp;gt;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;lt;/properties&amp;gt;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&amp;lt;dependencies&amp;gt;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;dependency&amp;gt;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;groupId&amp;gt;com.jolbox&amp;lt;/groupId&amp;gt;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;artifactId&amp;gt;bonecp&amp;lt;/artifactId&amp;gt;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;version&amp;gt;0.8.0.RELEASE&amp;lt;/version&amp;gt;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;/dependency&amp;gt;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;dependency&amp;gt;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;groupId&amp;gt;org.springframework&amp;lt;/groupId&amp;gt;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;artifactId&amp;gt;spring-beans&amp;lt;/artifactId&amp;gt;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;version&amp;gt;${spring.version}&amp;lt;/version&amp;gt;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;/dependency&amp;gt;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;dependency&amp;gt;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;groupId&amp;gt;org.springframework&amp;lt;/groupId&amp;gt;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;artifactId&amp;gt;spring-core&amp;lt;/artifactId&amp;gt;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;version&amp;gt;${spring.version}&amp;lt;/version&amp;gt;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;/dependency&amp;gt;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;dependency&amp;gt;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;groupId&amp;gt;org.springframework&amp;lt;/groupId&amp;gt;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;artifactId&amp;gt;spring-context-support&amp;lt;/artifactId&amp;gt;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;version&amp;gt;${spring.version}&amp;lt;/version&amp;gt;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;/dependency&amp;gt;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;dependency&amp;gt;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;groupId&amp;gt;org.springframework&amp;lt;/groupId&amp;gt;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;artifactId&amp;gt;spring-context&amp;lt;/artifactId&amp;gt;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;version&amp;gt;${spring.version}&amp;lt;/version&amp;gt;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;/dependency&amp;gt;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;dependency&amp;gt;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;groupId&amp;gt;org.springframework&amp;lt;/groupId&amp;gt;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;artifactId&amp;gt;spring-jdbc&amp;lt;/artifactId&amp;gt;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;version&amp;gt;${spring.version}&amp;lt;/version&amp;gt;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;/dependency&amp;gt;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;dependency&amp;gt;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;groupId&amp;gt;org.springframework&amp;lt;/groupId&amp;gt;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;artifactId&amp;gt;spring-orm&amp;lt;/artifactId&amp;gt;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;version&amp;gt;${spring.version}&amp;lt;/version&amp;gt;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;/dependency&amp;gt;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;dependency&amp;gt;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;groupId&amp;gt;org.springframework&amp;lt;/groupId&amp;gt;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;artifactId&amp;gt;spring-tx&amp;lt;/artifactId&amp;gt;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;version&amp;gt;${spring.version}&amp;lt;/version&amp;gt;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;/dependency&amp;gt;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;!-- Spring MVC --&amp;gt;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;dependency&amp;gt;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;groupId&amp;gt;org.springframework&amp;lt;/groupId&amp;gt;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;artifactId&amp;gt;spring-web&amp;lt;/artifactId&amp;gt;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;version&amp;gt;${spring.version}&amp;lt;/version&amp;gt;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;/dependency&amp;gt;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;dependency&amp;gt;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;groupId&amp;gt;org.springframework&amp;lt;/groupId&amp;gt;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;artifactId&amp;gt;spring-webmvc&amp;lt;/artifactId&amp;gt;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;version&amp;gt;${spring.version}&amp;lt;/version&amp;gt;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;/dependency&amp;gt;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;dependency&amp;gt;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;groupId&amp;gt;cglib&amp;lt;/groupId&amp;gt;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;artifactId&amp;gt;cglib&amp;lt;/artifactId&amp;gt;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;version&amp;gt;2.2.2&amp;lt;/version&amp;gt;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;/dependency&amp;gt;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;!-- Spring Data JPA --&amp;gt;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;dependency&amp;gt;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;groupId&amp;gt;org.springframework.data&amp;lt;/groupId&amp;gt;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;artifactId&amp;gt;spring-data-jpa&amp;lt;/artifactId&amp;gt;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;version&amp;gt;1.5.1.RELEASE&amp;lt;/version&amp;gt;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;/dependency&amp;gt;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;dependency&amp;gt;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;groupId&amp;gt;org.springframework&amp;lt;/groupId&amp;gt;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;artifactId&amp;gt;spring-test&amp;lt;/artifactId&amp;gt;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;version&amp;gt;${spring.version}&amp;lt;/version&amp;gt;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;/dependency&amp;gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;!-- Hibernate --&amp;gt;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;dependency&amp;gt;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;groupId&amp;gt;org.hibernate&amp;lt;/groupId&amp;gt;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;artifactId&amp;gt;hibernate-core&amp;lt;/artifactId&amp;gt;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;version&amp;gt;4.3.4.Final&amp;lt;/version&amp;gt;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;/dependency&amp;gt;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;dependency&amp;gt;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;groupId&amp;gt;postgresql&amp;lt;/groupId&amp;gt;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;artifactId&amp;gt;postgresql&amp;lt;/artifactId&amp;gt;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;version&amp;gt;9.0-801.jdbc4&amp;lt;/version&amp;gt;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;/dependency&amp;gt;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;dependency&amp;gt;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;groupId&amp;gt;org.hibernate&amp;lt;/groupId&amp;gt;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;artifactId&amp;gt;hibernate-entitymanager&amp;lt;/artifactId&amp;gt;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;version&amp;gt;4.3.5.Final&amp;lt;/version&amp;gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;color: red;&quot;&gt;//could not load the JPA from here so I did it separate.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;exclusions&amp;gt;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;exclusion&amp;gt;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;groupId&amp;gt;javax.transaction&amp;lt;/groupId&amp;gt;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;artifactId&amp;gt;jta&amp;lt;/artifactId&amp;gt;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;/exclusion&amp;gt;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;/exclusions&amp;gt;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;/dependency&amp;gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;color: red;&quot;&gt;//The jpa libary that is needed for hibernate.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;dependency&amp;gt;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;groupId&amp;gt;javax.transaction&amp;lt;/groupId&amp;gt;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;artifactId&amp;gt;jta&amp;lt;/artifactId&amp;gt;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;version&amp;gt;1.1&amp;lt;/version&amp;gt;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;lt;/dependency&amp;gt;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;lt;dependency&amp;gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
the persistence xml which needs to be placed in src/main/resources/META-INF.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;div&gt;
&amp;lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&amp;gt;&lt;/div&gt;
&lt;div&gt;
&amp;lt;persistence xmlns=&quot;http://java.sun.com/xml/ns/persistence&quot;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;xsi:schemaLocation=&quot;http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd&quot;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;version=&quot;2.0&quot;&amp;gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;lt;persistence-unit name=&quot;dataSource&quot; transaction-type=&quot;RESOURCE_LOCAL&quot;&amp;gt;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;description&amp;gt;&amp;lt;&lt;span style=&quot;color: red;&quot;&gt;YOUR DESCRIPTION&lt;/span&gt;&amp;gt;&amp;lt;/description&amp;gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;class&amp;gt;com.shops.data.info.CustomerInfo&amp;lt;/class&amp;gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;properties&amp;gt;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;property name=&quot;javax.persistence.jdbc.driver&quot; &amp;nbsp; value=&quot;org.postgresql.Driver&quot; /&amp;gt;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;property name=&quot;javax.persistence.jdbc.url&quot; &amp;nbsp; &amp;nbsp; &amp;nbsp;value=&quot;jdbc:postgresql://localhost:5432/shops&quot; /&amp;gt;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;property name=&quot;javax.persistence.jdbc.user&quot; &amp;nbsp; &amp;nbsp; value=&quot;&amp;lt;&lt;span style=&quot;color: red;&quot;&gt;USERNAME&lt;/span&gt;&amp;gt;&quot; /&amp;gt;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;property name=&quot;javax.persistence.jdbc.password&quot; value=&quot;&amp;lt;&lt;span style=&quot;color: red;&quot;&gt;PASSWORD&lt;/span&gt;&amp;gt;&quot; /&amp;gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
//&lt;span style=&quot;color: red;&quot;&gt;optional parameters.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;property name=&quot;hibernate.show_sql&quot; &amp;nbsp; &amp;nbsp; value=&quot;true&quot; /&amp;gt;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;property name=&quot;hibernate.hbm2ddl.auto&quot; value=&quot;create&quot; /&amp;gt;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;/properties&amp;gt;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;lt;/persistence-unit&amp;gt;&lt;/div&gt;
&lt;div&gt;
&amp;lt;/persistence&amp;gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
The spring context file:&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;div&gt;
&amp;lt;beans xmlns=&quot;http://www.springframework.org/schema/beans&quot;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;xmlns:jpa=&quot;http://www.springframework.org/schema/data/jpa&quot;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;xsi:schemaLocation=&quot;http://www.springframework.org/schema/beans&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; http://www.springframework.org/schema/beans/spring-beans.xsd&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; http://www.springframework.org/schema/data/jpa&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; http://www.springframework.org/schema/data/jpa/spring-jpa.xsd&quot;&amp;gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;lt;jpa:repositories base-package=&quot;&lt;span style=&quot;color: red;&quot;&gt;THE REPOSITORY PACKAGE&lt;/span&gt;&quot;/&amp;gt;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;lt;bean id=&quot;dataSource&quot; class=&quot;org.springframework.jdbc.datasource.DriverManagerDataSource&quot;&amp;gt;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;property name=&quot;driverClassName&quot; value=&quot;org.postgresql.Driver&quot;/&amp;gt;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;property name=&quot;url&quot; value=&quot;jdbc:postgresql://localhost:5432/&amp;lt;&lt;span style=&quot;color: red;&quot;&gt;YOURDATABASE&lt;/span&gt;&amp;gt;&quot;/&amp;gt;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;property name=&quot;username&quot; value=&quot;&amp;lt;&lt;span style=&quot;color: red;&quot;&gt;USERNAME&lt;/span&gt;&amp;gt;&quot;/&amp;gt;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;property name=&quot;password&quot; value=&quot;&lt;span style=&quot;color: red;&quot;&gt;PASSWORD&lt;/span&gt;&quot;/&amp;gt;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;lt;/bean&amp;gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;lt;bean id=&quot;jpaVendorAdapter&quot; class=&quot;org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter&quot;&amp;gt;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;property name=&quot;showSql&quot; value=&quot;true&quot;/&amp;gt;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;property name=&quot;generateDdl&quot; value=&quot;true&quot;/&amp;gt;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;property name=&quot;database&quot; value=&quot;POSTGRESQL&quot;/&amp;gt;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;lt;/bean&amp;gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;lt;bean id=&quot;entityManagerFactory&quot; class=&quot;org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean&quot;&amp;gt;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;property name=&quot;dataSource&quot; ref=&quot;dataSource&quot;/&amp;gt;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;property name=&quot;jpaVendorAdapter&quot; ref=&quot;jpaVendorAdapter&quot;/&amp;gt;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;!-- spring based scanning for entity classes--&amp;gt;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;property name=&quot;packagesToScan&quot; value=&quot;&amp;lt;&lt;span style=&quot;color: red;&quot;&gt;THE D.O. PACKAGE&lt;/span&gt;&amp;gt;&quot;/&amp;gt;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;lt;/bean&amp;gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;lt;bean id=&quot;transactionManager&quot; class=&quot;org.springframework.orm.jpa.JpaTransactionManager&quot;/&amp;gt;&lt;/div&gt;
&lt;div&gt;
&amp;lt;/beans&amp;gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
The repository part:&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
You can have multiple repositories. How to deal with the number of repositories depends completely on the fact how you want to deal delete with your data.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
Here is al single example:&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
import com.my.web.shop.dataobjects.CustomerInfo;&lt;/div&gt;
&lt;div&gt;
import org.springframework.data.jpa.repository.JpaRepository;&lt;/div&gt;
&lt;div&gt;
import org.springframework.stereotype.Repository;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
import javax.transaction.Transactional;&lt;/div&gt;
&lt;div&gt;
import java.util.List;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
@Repository&lt;/div&gt;
&lt;div&gt;
@Transactional&lt;/div&gt;
&lt;div&gt;
interface CustomerRepository extends JpaRepository&amp;lt;CustomerInfo, Long &amp;gt; {&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; public List&amp;lt;CustomerInfo&amp;gt; findBy&lt;span style=&quot;color: red;&quot;&gt;Emailadress&lt;/span&gt;An&lt;span style=&quot;color: red;&quot;&gt;dPassword&lt;/span&gt;(String email, String password);&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; public List&amp;lt;CustomerInfo&amp;gt; findBy&lt;span style=&quot;color: red;&quot;&gt;Emailadress&lt;/span&gt;(String email);&lt;/div&gt;
&lt;div&gt;
}&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
In this litle piece of code you find some astonishing things first of all after creating this interface, I did not create an implementation. Creating your own repository is not necessary in the most cases. As a matter of fact if you create an Repository on your own, you be at the point where we would start writing this extra boiler plate code we done for years.&amp;nbsp;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
Under water this interface is hooked up with the CrudRepository of Spring. This baby gives you allmost everything you need. All the basic database actions as select, update, delete and insert are there. &amp;nbsp; &amp;nbsp;&lt;/div&gt;
&lt;div&gt;
The second part you might find different is the naming of the methods. This is actually one of the most amazing parts. In the name of the method you declare the fields which you want to use in your sql statement. The parameters represent the values. So the first method would build under water: where emailAdress = &quot;a@b.nl&quot; and password = &quot;myPassword.&quot;. If you have a big query the name of your method would become very long. Luckily there is another way to deal with queries. The &lt;span style=&quot;color: red;&quot;&gt;@Query &lt;/span&gt;annotation helps to solve this problem. It could look something like this:&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
//&lt;span style=&quot;color: red;&quot;&gt;The D.O. for the myShop customers.&lt;/span&gt; &amp;nbsp;&lt;/div&gt;
&lt;div&gt;
&lt;div&gt;
@Entity&lt;/div&gt;
&lt;div&gt;
@Table(name = &quot;customers&quot;)&lt;/div&gt;
&lt;div&gt;
public class CustomerInfo implements Serializable{&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; @Id&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; @GeneratedValue&lt;/div&gt;
&lt;div&gt;
&amp;nbsp;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;private long id;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; @Column&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; private String emailadress;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; @Column&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; private String password;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;@Id&lt;/div&gt;
&lt;div&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;public Long getId() {&lt;/div&gt;
&lt;div&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;return id;&lt;/div&gt;
&lt;div&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;}&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;public String getPassword() {&lt;/div&gt;
&lt;div&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;return password;&lt;/div&gt;
&lt;div&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;}&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;public void setId(Long id) {&lt;/div&gt;
&lt;div&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;this.id = id;&lt;/div&gt;
&lt;div&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;}&lt;/div&gt;
&lt;div&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;public void setPassword(String password) {&lt;/div&gt;
&lt;div&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;this.password = password;&lt;/div&gt;
&lt;div&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;}&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; public String getEmailadress() {&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; return emailadress;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; }&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; public void setEmailadress(String emailadress) {&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; this.emailadress = emailadress;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; }&lt;/div&gt;
&lt;div&gt;
}&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
// &lt;span style=&quot;color: red;&quot;&gt;The D.O that couples that couples the customer to &amp;nbsp;the test data. And contains the test data.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;div&gt;
@Entity&lt;/div&gt;
&lt;div&gt;
@Table(name = &quot;test&quot;)&lt;/div&gt;
&lt;div&gt;
public class Test implements Serializable {&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; @Id&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; @GeneratedValue&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; private long id;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; @Column&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; private String label;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; @Column(name = &quot;customer_id&quot;)&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; private long customersId;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; @OneToMany()&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; @JoinColumn(name=&quot;id&quot;)&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; private List&amp;lt;CustomerInfo&amp;gt; customerInfo;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp;public long getId() {&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; return id;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; }&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; public void setId(long id) {&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; this.id = id;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; }&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; public String getLabel() {&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; return label;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; }&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; public void setLabel(String label) {&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; this.label = label;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; }&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; public long getCustomersId() {&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; return customersId;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; }&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; public void setCustomersId(long customersId) {&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; this.customersId = customersId;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; }&lt;/div&gt;
&lt;div&gt;
}&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
//&lt;span style=&quot;color: red;&quot;&gt;The test data repository&lt;/span&gt;&amp;nbsp;&lt;/div&gt;
&lt;div&gt;
&lt;div&gt;
import com.shops.data.info.Test;&lt;/div&gt;
&lt;div&gt;
import org.springframework.data.jpa.repository.JpaRepository;&lt;/div&gt;
&lt;div&gt;
import org.springframework.data.jpa.repository.Query;&lt;/div&gt;
&lt;div&gt;
import org.springframework.stereotype.Repository;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
import javax.transaction.Transactional;&lt;/div&gt;
&lt;div&gt;
import java.util.List;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
/**&lt;/div&gt;
&lt;div&gt;
&amp;nbsp;* Created by compurat on 4/19/14.&lt;/div&gt;
&lt;div&gt;
&amp;nbsp;*/&lt;/div&gt;
&lt;div&gt;
@Repository&lt;/div&gt;
&lt;div&gt;
@Transactional&lt;/div&gt;
&lt;div&gt;
interface TestRepository extends JpaRepository&amp;lt;Test, Long &amp;gt; {&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; @Query(&quot;SELECT t.label FROM Test t &amp;nbsp;left join t.customerInfo c &amp;nbsp;where t.id=(?1)&quot;)&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; public String findById(long id);&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
}&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
As you can see the findById method is not acting on the method name and the parameter value but will act on the&amp;nbsp;@Query that we put on top of it. &amp;nbsp;The last part of the query works in a simular way as we know with PreparedStatement. The questionmark tells the compiler this a placeholder an d the number tells which parameter in line it needs to pickup. In this case we only have one parameter. Not enough space for a mistake :).&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
There is another piece that might have caught your eye. There is a join in this query. It took me a while to figure out how that worked. The secret lies &amp;nbsp;in &amp;nbsp;the simple fact that you have to divide the join over two places.&amp;nbsp;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;ol&gt;
&lt;li&gt;&lt;div&gt;
&amp;nbsp; &amp;nbsp; @OneToMany()&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; @JoinColumn(name=&quot;id&quot;)&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; private List&amp;lt;CustomerInfo&amp;gt; customerInfo; defines this part of the join. It tells: listen there is a join coming up. In this case it is a OneToMany but it can also be @ManyToMany or&amp;nbsp;@OneToOne. The&amp;nbsp;@JoinColumn tells to connect to a certainfield in the CustomerInfo class.&amp;nbsp;&lt;/div&gt;
&lt;/li&gt;
&lt;li&gt;&lt;div&gt;
The &amp;nbsp;left join t.customerInfo c &amp;nbsp;in the&amp;nbsp;@Query part tells to actually execute the join. As you might notice the ON part from sql is not translated here. That is one of the parts That still puzzles me.How is it known to couple to? For the rest As allways as you understand the concept You find out it was not as hard as you expected first.&amp;nbsp;&lt;/div&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;div&gt;
Conclusion:&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
The concept itself and the amazement it gave me leveled up the steepness for me to understand it. But now I am happy I gave it time and picked up the things I allready know now. The concept to me is still a bit futuristic. But the fact it is here and I love to use it. The power of this is amazing.&amp;nbsp;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
Have fun!&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://pieterroskam.blogspot.com/feeds/1339663440832311145/comments/default' title='Reacties posten'/><link rel='replies' type='text/html' href='http://pieterroskam.blogspot.com/2014/04/peristence-future-arrived.html#comment-form' title='0 reacties'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2919956819843973860/posts/default/1339663440832311145'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2919956819843973860/posts/default/1339663440832311145'/><link rel='alternate' type='text/html' href='http://pieterroskam.blogspot.com/2014/04/peristence-future-arrived.html' title='peristence future arrived'/><author><name>java by experience</name><uri>http://www.blogger.com/profile/07404653852761857615</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2919956819843973860.post-6083981244378147344</id><published>2014-03-25T08:12:00.001-07:00</published><updated>2014-03-25T08:12:29.526-07:00</updated><title type='text'>Test with Wicket and Spring</title><content type='html'>&lt;b&gt;Introduction:&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
I started working with Wicket and as a Java developer I like the concept. I think when there are really front end developers working, it is harder to defend the fact that you want to use wicket. Wicket brings it own html notations. Most frontenders are not keen on that. For working with Wicket there is a very good starting point:&amp;nbsp;&lt;a href=&quot;https://wicket.apache.org/guide/guide/single.pdf&quot;&gt;the wicket free guide&lt;/a&gt;. The interesting part starts when you are about to use DI and Wicket. Setting that up is not to hard The web.xml should look like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;web-app&amp;gt;&lt;br /&gt;
&amp;nbsp; &amp;lt;display-name&amp;gt;MyApp&amp;lt;/display-name&amp;gt;&lt;br /&gt;
&amp;nbsp; &amp;lt;filter&amp;gt;&lt;br /&gt;
&amp;nbsp; &lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&amp;lt;filter-name&amp;gt;MyAppFilter&amp;lt;/filter-name&amp;gt;&lt;br /&gt;
&amp;nbsp; &lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&amp;lt;filter-class&amp;gt;org.apache.wicket.protocol.http.WicketFilter&amp;lt;/filter-class&amp;gt;&lt;br /&gt;
&amp;nbsp; &lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&amp;lt;init-param&amp;gt;&lt;br /&gt;
&amp;nbsp; &lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;&amp;lt;param-name&amp;gt;applicationClassName&amp;lt;/param-name&amp;gt;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;&amp;lt;param-value&amp;gt;com.my.app.MyApp&amp;lt;/param-value&amp;gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&amp;lt;/init-param&amp;gt;&lt;br /&gt;
&amp;nbsp; &amp;lt;/filter&amp;gt;&lt;br /&gt;
&amp;nbsp; &amp;lt;filter-mapping&amp;gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;lt;filter-name&amp;gt;MyAppFilter&amp;lt;/filter-name&amp;gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;lt;url-pattern&amp;gt;/*&amp;lt;/url-pattern&amp;gt;&lt;br /&gt;
&amp;nbsp; &amp;lt;/filter-mapping&amp;gt;&lt;br /&gt;
&amp;lt;/web-app&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For maven just get the latest version of wicket and spring and you be up and running in no time.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;The problem:&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;
The thing i ran into was the part where I wanted to start testing with Wicket using some DI to deal with some Classes which otherwise would end up in a very complex design. So the thing I cooked up after reading a lot of examples on the internet that didn&#39;t work.&lt;br /&gt;
&lt;br /&gt;
The spring test config in src/test/resources:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&amp;gt;&lt;br /&gt;
&amp;lt;beans xmlns=&quot;http://www.springframework.org/schema/beans&quot;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;xmlns:context=&quot;http://www.springframework.org/schema/context&quot;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;xsi:schemaLocation=&quot;http://www.springframework.org/schema/beans&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;http://www.springframework.org/schema/beans/spring-beans-2.5.xsd&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;http://www.springframework.org/schema/context&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;http://www.springframework.org/schema/context/spring-context-2.5.xsd&quot;&amp;gt;&lt;br /&gt;
&amp;nbsp;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&amp;lt;bean id=&quot;classa&quot; class=&quot;com.myapp.ClassA&quot;&amp;gt;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&amp;lt;/bean&amp;gt;&lt;br /&gt;
&amp;nbsp;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&amp;lt;bean id=&quot;classb&quot;&amp;nbsp;class=&quot;com.myapp.ClassB&quot;&amp;gt;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&amp;lt;/bean&amp;gt;&lt;br /&gt;
&amp;nbsp;&amp;lt;bean id=&quot;wicketApplication&quot; class=&quot;com.myapp.MyWicketApp&quot;&amp;gt;&lt;br /&gt;
&amp;lt;/bean&amp;gt;&lt;br /&gt;
&amp;lt;/beans&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The Junit test:&lt;br /&gt;
&lt;br /&gt;
@RunWith(SpringJUnit4ClassRunner.class)&lt;br /&gt;
@ContextConfiguration(locations = { &quot;classpath:myApp-test-context.xml&quot; })&lt;br /&gt;
public class LoginTest {&lt;br /&gt;
&lt;div&gt;
&lt;div&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;private WicketTester wicketTester;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;@Inject&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;span style=&quot;color: red;&quot;&gt; &amp;nbsp; // this stub is inheriting from an abstract class which is enhiriting from the wicket&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: red;&quot;&gt;WebApplication otherwise I cannot DI with the same type.&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: red;&quot;&gt;The real app is also inheriting from&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;color: red;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;that abstract class&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;private AmyApp myAppStub;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;@Before&lt;/div&gt;
&lt;div&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;public void init() {&lt;/div&gt;
&lt;div&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;wicketTester = new WicketTester(myAppStub);&lt;/div&gt;
&lt;div&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;}&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;
}&lt;/div&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;
The mock Application:&lt;br /&gt;
&lt;br /&gt;
public class&amp;nbsp;MyAppStub&amp;nbsp;extends&amp;nbsp;AmyApp&amp;nbsp;{&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;private final ApplicationContextMock applicationContextMock = new ApplicationContextMock();&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: red;&quot;&gt;&amp;nbsp;//injecting the classes from the test context.&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;@Inject&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;private ClassA classa;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;@Inject&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;private ClassB classb;&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;protected ApplicationContextMock getApplicationContextMock() {&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;return applicationContextMock;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;}&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;@Override&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;public Class&amp;lt;? extends Page&amp;gt; getHomePage() {&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;// TODO Auto-generated method stub&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;return null;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;}&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;@Override&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;public void init() {&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; /&lt;span style=&quot;color: red;&quot;&gt;/Adding the injected classes to the context mock so they will be used during testing.&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;applicationContextMock.putBean(&quot;classa&quot;,&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;    &lt;/span&gt;classa);&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;applicationContextMock.putBean(&quot;classb&quot;,&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;    &lt;/span&gt;classb);&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: red;&quot;&gt;//adding the applicationmock to spring&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;getComponentInstantiationListeners().add(&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;    &lt;/span&gt;new SpringComponentInjector(this, applicationContextMock));&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;}&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Conclusion:&lt;br /&gt;
&lt;br /&gt;
After I figured out how this baby works it is not that hard anymore to test with wicket. All you have to do is figure out the right pieces of the puzzle. In all the other examples the same pieces where missing.&lt;br /&gt;
&lt;br /&gt;
I hope This helps.&lt;br /&gt;
&lt;br /&gt;
Have Fun!&lt;br /&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://pieterroskam.blogspot.com/feeds/6083981244378147344/comments/default' title='Reacties posten'/><link rel='replies' type='text/html' href='http://pieterroskam.blogspot.com/2014/03/test-with-wicket-and-spring.html#comment-form' title='0 reacties'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2919956819843973860/posts/default/6083981244378147344'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2919956819843973860/posts/default/6083981244378147344'/><link rel='alternate' type='text/html' href='http://pieterroskam.blogspot.com/2014/03/test-with-wicket-and-spring.html' title='Test with Wicket and Spring'/><author><name>java by experience</name><uri>http://www.blogger.com/profile/07404653852761857615</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry></feed>