tag:blogger.com,1999:blog-51222332508474111722023-11-15T22:19:37.415-08:00Ivaylo Zashev's Blogizashevhttp://www.blogger.com/profile/18165262775786095949noreply@blogger.comBlogger4125tag:blogger.com,1999:blog-5122233250847411172.post-69125995958225767922015-12-11T10:14:00.000-08:002016-01-05T09:18:02.845-08:00BGJUG event: Algorithms and Data Structures. Searching and Sorting in JavaWhat a long title! Well done, guys (I've copied it from <a href="https://jug.bg/events/algorithms-and-data-structures-searching-and-sorting-in-java/" target="_blank">jug.bg event list</a>) :D<br />
Actually Our official unofficial blogger <a href="https://mihail.stoynov.com/about/" target="_blank">Mihail Stoynov</a> was absent on this session and I issued myself to write this blog post, because I reckon that every event of our jug has to be documented. <br />
OK. Lets go on.<br />
The session was essentially productive. It's topic was searching and sorting algorithms alongside Java Data Structures API. The speaker, Petar Petrov, started with basic aspects of algorithms e.g. how to test your algorithms, and how to choose the best algorithms as of testing results. I will not reintroduce the whole session because its <span lang="en">unnecessary and incorrect. <br />It's important to point out that this session was really vital not only for Java developers, but for people facing up such kind of tasks every day at work. And lets say it loud: <br /><a href="https://jug.bg/en/" target="_blank"><br /><b>BGJUG</b></a><b> organise talks with topics essential for whole software community!!!<br /> </b><br />After a small break the talk continued with more advanced discussions for Java Collections API and "When to use this data structure and when other....". Active role took some of attendees, I mean <a href="http://blog.dmitryalexandrov.net/" target="_blank">Mitia</a> and of course <a href="http://gochev.blogspot.bg/" target="_blank">Nayden</a>. </span><br />
<span lang="en">That discussions extracted the hidden importance of the number 47 but I didn't get anything from this conversations :D !!!<br />In this discussions realised that a lot of people are waiting for primitives in generics and value types in Java. </span><span lang="en"><span lang="en">Of course</span>, there are some pictures, snapped by Mitia, <a href="https://twitter.com/ivan_stefanov" target="_blank">Ivan</a> and me:</span><br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgLB1mMVwDyW5NtuzSjHvUsGBmo3G4jtjktU72DMu8FjjCQuv27bry0t8Rwuk0RZC83FNSGWOIepeVo9_rjFmoUvm9kOMNERuTw4uJ0R3mQK8p9E2BJ93rJBpBFgIsTA4DvwjDfDSIv/s1600/algo-event1.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="180" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgLB1mMVwDyW5NtuzSjHvUsGBmo3G4jtjktU72DMu8FjjCQuv27bry0t8Rwuk0RZC83FNSGWOIepeVo9_rjFmoUvm9kOMNERuTw4uJ0R3mQK8p9E2BJ93rJBpBFgIsTA4DvwjDfDSIv/s320/algo-event1.jpg" width="320" /></a></div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgpjemtJUbm2Mu0JhApWeXdRiOfmmEQ_rk76ThcTgVwrX7QkMcU2odZ9jVgqDiClhA8HW89Ju5i_-sM_MXry6TQ1sCliZyRGbhdBhRC_y_4OwZQfeuJzb0Mw9FPzEI7bFb6BMWi8ZPQ/s1600/algo-event3.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="240" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgpjemtJUbm2Mu0JhApWeXdRiOfmmEQ_rk76ThcTgVwrX7QkMcU2odZ9jVgqDiClhA8HW89Ju5i_-sM_MXry6TQ1sCliZyRGbhdBhRC_y_4OwZQfeuJzb0Mw9FPzEI7bFb6BMWi8ZPQ/s320/algo-event3.jpg" width="320" /></a></div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiD7wsM7e5TlBR-qO0p9g1n-4y2HZhNVhmrTBL1lLYt1UV9_p5cI1uJfRrPI1fPVDZFIir5new13hTl5KMCBaiOtV41QKJM2M51e1U5gpEJSBmSZajk2-W2Yx8Kw1OdDeqRy-8TpABV/s1600/algo-event2.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="180" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiD7wsM7e5TlBR-qO0p9g1n-4y2HZhNVhmrTBL1lLYt1UV9_p5cI1uJfRrPI1fPVDZFIir5new13hTl5KMCBaiOtV41QKJM2M51e1U5gpEJSBmSZajk2-W2Yx8Kw1OdDeqRy-8TpABV/s320/algo-event2.jpg" width="320" /></a></div>
<br />izashevhttp://www.blogger.com/profile/18165262775786095949noreply@blogger.com0tag:blogger.com,1999:blog-5122233250847411172.post-10090651052329636172015-09-07T03:18:00.002-07:002015-12-22T11:02:15.030-08:00Contact me<br />
E-mail: ivaylo.em.zashev@gmail.com<br />
twitter: <a href="https://twitter.com/ivaylo_zashev" target="_blank">@ivaylo_zashev</a>izashevhttp://www.blogger.com/profile/18165262775786095949noreply@blogger.com0tag:blogger.com,1999:blog-5122233250847411172.post-57418004344747986402015-09-06T07:01:00.001-07:002016-12-19T12:03:21.281-08:00How to deploy spring boot on wildFly ASFew weeks ago I faced an issue of deploying spring boot application on wildFly application server. After achieve most of you ordinary routine task usually you say "I'm so relived that I get rid of this! Lets go ahead on next issues." But that's not the point an open source geek would stay with. Based on this, I was urged to write this blog post by one of our <a href="http://java-bg.org/en/" target="_blank">BGJUG</a> guys <a href="http://gochev.blogspot.bg/" target="_blank">Nayden Gochev</a>.<br />
<br />
Actually this task is not so difficult to be achieve but you have to know what components need a spring boot web application. <br />
After few hours roaming around github public repositories with help of <a href="http://blog.dmitryalexandrov.net/" target="_blank">Mitia Alexandrov</a> other <a href="http://java-bg.org/en/" target="_blank">jug</a> geek we came across a solution to deploy spring boot on wildFly AS.<br />
<br />
On this blog post we will code a simple spring boot web service that is available by the following github repo: <a href="https://github.com/IvayloZashev/spring-restful-ws-example" target="_blank">https://github.com/IvayloZashev/spring-restful-ws-example.</a><br />
<br />
Pre-overview of the application:<br />
<ul>
<li>maven as a built tool</li>
<li>simple business logic in beans annotated with <a href="http://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/stereotype/Service.html" target="_blank">@Service</a></li>
<li><a href="http://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/web/bind/annotation/RestController.html" target="_blank">@RestController</a> beans which will process http requests</li>
<li>starter class annotated with <a href="http://docs.spring.io/spring-boot/docs/current/api/org/springframework/boot/autoconfigure/SpringBootApplication.html" target="_blank">@SpringBootApplication</a></li>
</ul>
Lets start with the <a href="https://github.com/IvayloZashev/spring-restful-ws-example/blob/master/pom.xml" target="_blank">pom.xml</a> file. <br />
We will focus on the important elements only so at first time is the element<br />
<pre style="background-image: URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjO6LcyeMjGT2c3XzP3ep0ZFmfpfrB8qq7UEIv6GvjiQRmoGsapJg6YYKKNokOLLqPyjorr6h_TE5h-4ist2D2lmNLmDNA4dw23TD87usLpJWWU3U0rwyJpf03sIJaSAYHylSiZeBxXgF7l/s320/codebg.gif); background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;"><code style="color: black; word-wrap: normal;"> <packaging>war</packaging>
</code></pre>
<br />
Spring boot is distributed with embedded Tomcat web container and that's why the default packaging composes jar file. We are deploying on wildFly so you have to add this element to your pom.<br />
<br />
After that you should add the parent project:<br />
<pre style="background-image: URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjO6LcyeMjGT2c3XzP3ep0ZFmfpfrB8qq7UEIv6GvjiQRmoGsapJg6YYKKNokOLLqPyjorr6h_TE5h-4ist2D2lmNLmDNA4dw23TD87usLpJWWU3U0rwyJpf03sIJaSAYHylSiZeBxXgF7l/s320/codebg.gif); background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;"><code style="color: black; word-wrap: normal;"> <parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.3.2.RELEASE</version>
</parent>
</code></pre>
<br />
This element adds most of the dependencies that spring boot needs at compile time.<br />
<br />
In Dependencies section we have:<br />
<pre style="background-image: URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjO6LcyeMjGT2c3XzP3ep0ZFmfpfrB8qq7UEIv6GvjiQRmoGsapJg6YYKKNokOLLqPyjorr6h_TE5h-4ist2D2lmNLmDNA4dw23TD87usLpJWWU3U0rwyJpf03sIJaSAYHylSiZeBxXgF7l/s320/codebg.gif); background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;"><code style="color: black; word-wrap: normal;"> <dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion>
</exclusions>
</dependency>
</code></pre>
<br />
Dependency with artifact id spring-boot-starter-web initializes the web context of the spring boot application and provides web api of spring boot framework.<br />
The version of this dependency is not explicitly defined because we are extending version from the parent dependency.<br />
<b><br />And here comes the big point...</b><br />
Exclusion of dependency with artifact id spring-boot-starter-tomacat is needed because we will deploy the war file on wildFly. If this exclusion is missed you will get the exception with code "<b>JBAS014671: Failed services</b>". <br />
Which means that Tomcat API class <a href="https://tomcat.apache.org/tomcat-8.0-doc/api/org/apache/tomcat/websocket/server/WsServerContainer.html" target="_blank">WsServerContainer</a> cannot be cast to wildFly API class <a href="http://undertow.io/javadoc/1.2.x/io/undertow/websockets/jsr/ServerWebSocketContainer.html" target="_blank">ServerWebSocketContainer</a>. And deployment processe interupts with above error.<br />
<br />
And finally we need:<br />
<pre style="background-image: URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjO6LcyeMjGT2c3XzP3ep0ZFmfpfrB8qq7UEIv6GvjiQRmoGsapJg6YYKKNokOLLqPyjorr6h_TE5h-4ist2D2lmNLmDNA4dw23TD87usLpJWWU3U0rwyJpf03sIJaSAYHylSiZeBxXgF7l/s320/codebg.gif); background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;"><code style="color: black; word-wrap: normal;"> <dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
</dependency>
</code></pre>
to transmit http requests in controller layer.<br />
<br />
Lets move on to Java code. Before start coding anything you should create a package in project's java directory (<a href="https://github.com/IvayloZashev/spring-restful-ws-example/tree/master/src/main/java" target="_blank">src/main/java/</a>). If you miss this you're likely to get the console output warning message: <b><br />Your ApplicationContext is unlikely to start due to a @ComponentScan of the default package.</b><br />
And, Yes, your application won't start.<br />
<br />
We have several model entities that represents basic arithmetic operations over two integer numbers: <a href="https://github.com/IvayloZashev/spring-restful-ws-example/blob/master/src/main/java/calculator/SumEntity.java" target="_blank">sum</a>, <a href="https://github.com/IvayloZashev/spring-restful-ws-example/blob/master/src/main/java/calculator/SubtractEntity.java" target="_blank">subtract</a>, <a href="https://github.com/IvayloZashev/spring-restful-ws-example/blob/master/src/main/java/calculator/MultiplyEntity.java" target="_blank">multiply</a> and to dive into http requests <a href="https://github.com/IvayloZashev/spring-restful-ws-example/blob/master/src/main/java/calculator/Figures.java" target="_blank">all-in-one</a>. <br />
Business logic for the entities are implemented in bean named <a href="https://github.com/IvayloZashev/spring-restful-ws-example/blob/master/src/main/java/calculator/FiguresService.java" target="_blank">FiguresService</a> annotated with <a href="http://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/stereotype/Service.html" target="_blank">@Service</a>. <br />
When you play with spring framework inversion of control it's a good practice to use autowiring by static field e.g NAME because spring autowires faster by static field rather than by class.<br />
<br />
And here comes the long waited bean annotated with <a href="http://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/web/bind/annotation/RestController.html" target="_blank">@RestController</a> which will intercept http requests to the server. The source code for this bean is available <a href="https://github.com/IvayloZashev/spring-restful-ws-example/blob/master/src/main/java/calculator/FiguresController.java" target="_blank">here</a>. <br />
@RestController annotation is available since spring 4.0 release. This annotation is annotated itself by <a href="http://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/stereotype/Controller.html" target="_blank">@Controller</a> and <a href="http://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/web/bind/annotation/ResponseBody.html" target="_blank">@ResponseBody</a>.<br />
In this controller we are autowiring bean named FiguresService by NAME
<br />
<pre style="background-image: URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjO6LcyeMjGT2c3XzP3ep0ZFmfpfrB8qq7UEIv6GvjiQRmoGsapJg6YYKKNokOLLqPyjorr6h_TE5h-4ist2D2lmNLmDNA4dw23TD87usLpJWWU3U0rwyJpf03sIJaSAYHylSiZeBxXgF7l/s320/codebg.gif); background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;"><code style="color: black; word-wrap: normal;"> @Autowired
@Qualifier(FiguresService.NAME)
FiguresService figuresService; </code></pre>
<br />
We are assigning parameters to the request by <a href="http://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/web/bind/annotation/RequestParam.html" target="_blank">@RequestParam</a> but there are alternatives as well e.g <a href="http://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/web/bind/annotation/PathVariable.html" target="_blank">@PathVariable</a> and <a href="http://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/web/bind/annotation/RequestBody.html" target="_blank">@RequestBody.</a><br />
<br />
In the class with main method we have the following code:<br />
<pre style="background-image: URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjO6LcyeMjGT2c3XzP3ep0ZFmfpfrB8qq7UEIv6GvjiQRmoGsapJg6YYKKNokOLLqPyjorr6h_TE5h-4ist2D2lmNLmDNA4dw23TD87usLpJWWU3U0rwyJpf03sIJaSAYHylSiZeBxXgF7l/s320/codebg.gif); background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;"><code style="color: black; word-wrap: normal;"> @SpringBootApplication
@ComponentScan
public class Application extends SpringBootServletInitializer {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
</code></pre>
<br />
Here is the second big point in this application. Our Application class extends class <a href="http://docs.spring.io/autorepo/docs/spring-boot/1.1.1.RELEASE/api/org/springframework/boot/context/web/SpringBootServletInitializer.html" target="_blank">SpringBootServletInitializer</a><code class="literal">. </code>By doing this we are producing support for spring servlet and configuring our application to be launched by the servlet container, in our case wildFly AS. And as we see from the API docs is needed to build a war file and deploy it.<br />
<br />
And that's it :) You only have to build a war file and deploy it to your wildFly AS.izashevhttp://www.blogger.com/profile/18165262775786095949noreply@blogger.com0tag:blogger.com,1999:blog-5122233250847411172.post-11642746876478380112015-09-06T06:57:00.003-07:002017-07-11T13:37:29.377-07:00About me<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj3I18g5hhAm9D0XwXQ4ypfKYHpXzwuMKhgvp_XUA8rWrM1oKgoWGMJL8thdss9FJuaH49oSsYHRxqC8EhJ3iHJ_BGGAZrMVFygOrUq3tuL3qNBWScC1AVVTc83Pl1SL8PDjSHtZw5b/s1600/14725537_1334052246618611_740180525144133919_n.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="598" data-original-width="598" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj3I18g5hhAm9D0XwXQ4ypfKYHpXzwuMKhgvp_XUA8rWrM1oKgoWGMJL8thdss9FJuaH49oSsYHRxqC8EhJ3iHJ_BGGAZrMVFygOrUq3tuL3qNBWScC1AVVTc83Pl1SL8PDjSHtZw5b/s320/14725537_1334052246618611_740180525144133919_n.jpg" width="320" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<br />
With fewer words that I expected: My name is Ivaylo Zashev. I am computer engineer. I work for a company <a href="https://www.linkedin.com/company-beta/2041673/">Gopler</a> and I am passionate member of <a href="http://java.bg/en/" target="_blank">Bulgarian Java User Group</a>.izashevhttp://www.blogger.com/profile/18165262775786095949noreply@blogger.com0