tag:blogger.com,1999:blog-4414214580981943972024-03-18T11:09:30.061+02:00May the source be with you!Blog about the light side of the *.javajNaydenhttp://www.blogger.com/profile/04678280364638370213noreply@blogger.comBlogger45125tag:blogger.com,1999:blog-441421458098194397.post-23425779874783344302019-11-05T14:27:00.001+02:002023-05-12T13:24:08.284+03:00Moving away from Blogger/Blogspot for blogging<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhtF5BiWnV-sZCBfp5FDR-57mFM-SQepnTFeYN0sOGXcnrLY2JrllOz5SuhPMxAOet2KRrzWKs5p17oJzXHxOBupqZn7jwsK-k3nNWDaJAzvVvgE-c95I0SDrgX5s47KV5Y7eJ6hp2oTRY/s1600/uxuomi.jpg" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="1361" data-original-width="1400" height="388" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhtF5BiWnV-sZCBfp5FDR-57mFM-SQepnTFeYN0sOGXcnrLY2JrllOz5SuhPMxAOet2KRrzWKs5p17oJzXHxOBupqZn7jwsK-k3nNWDaJAzvVvgE-c95I0SDrgX5s47KV5Y7eJ6hp2oTRY/s400/uxuomi.jpg" width="400" /></a></div>
<b><br /></b>
<b><br /></b>
<b><span face=""helvetica neue" , "arial" , "helvetica" , sans-serif">Hello everyone,</span></b><br />
<span face=""helvetica neue" , "arial" , "helvetica" , sans-serif">in recent years I didn't have time to actually blog and the reason was not only the lack of time.</span><br />
<span face=""helvetica neue" , "arial" , "helvetica" , sans-serif">The real reason was that personal blogs are no longer this viable as ones were. In the current time, most people read medium or ghost or very development-aligned websites to get their content.</span><br />
<span face=""helvetica neue" , "arial" , "helvetica" , sans-serif"><br /></span>
<span face=""helvetica neue" , "arial" , "helvetica" , sans-serif">In the past years when this blog was created,<a href="http://dzone.com/" target="_blank"> dzone.com</a> was actually a blog aggregator, where you put your blog and people can vote for it, in a way similar to Reddit. </span><div><span face=""helvetica neue" , "arial" , "helvetica" , sans-serif"><u>It was <b>AWESOME</b></u> having a front and back page and the blog links having a lot of votes sometimes made it to the front page. There was RSS for both pages and it was so so awesome and <a href="http://javalobby.com/" target="_blank">Javalobby</a> was a forum back then. I don't know how these guys fcked up that much but shame. </span></div><div><br />
<span face=""helvetica neue" , "arial" , "helvetica" , sans-serif">Anyway, all is over ... dzone is completely different, javalobby doesn't exist and to have a personal blog and just rely only on your Twitter or Reddit presence is just too much work for a developer, after all we have to also develop... not promote ourselves all the time. </span><br /><span face=""helvetica neue" , "arial" , "helvetica" , sans-serif"><br /></span>
<span face=""helvetica neue" , "arial" , "helvetica" , sans-serif">So because of the reasons above I am archiving my blog.</span><br />
<span face=""helvetica neue" , "arial" , "helvetica" , sans-serif"><br /></span>
<span face=""helvetica neue" , "arial" , "helvetica" , sans-serif">I might post sometimes to <a href="http://dev.to/" target="_blank">http://dev.to</a> which I believe is the best medium alternative for developers blogging right now, it is basically Twitter and Reddit a like and you can follow me there at <a href="https://dev.to/gochev" target="_blank">https://dev.to/gochev</a> .</span><br />
<span face=""helvetica neue" , "arial" , "helvetica" , sans-serif"><br /></span><br />
<span face=""helvetica neue" , "arial" , "helvetica" , sans-serif">Also, my twitter is <a href="http://twitter.com/gochev" target="_blank">https://twitter.com/gochev</a> and my LinkedIn is <a href="https://linkedin.com/in/gochev " target="_blank">https://linkedin.com/in/gochev </a>we can keep in touch with me there as well.</span><br />
<span face=""helvetica neue" , "arial" , "helvetica" , sans-serif"><br /></span><br />
<span face=""helvetica neue" , "arial" , "helvetica" , sans-serif"><br /></span>
<span face=""helvetica neue" , "arial" , "helvetica" , sans-serif">So long and thanks for all the fish!</span><br />
<br />
<br /></div>jNaydenhttp://www.blogger.com/profile/04678280364638370213noreply@blogger.com0tag:blogger.com,1999:blog-441421458098194397.post-39889408504521531432019-11-04T13:35:00.002+02:002019-11-04T13:42:04.581+02:00NestJS + Mongo + Typegoose The current state of Mongo with NestJS ( and Node) .<br />
<br />
Currently you have 3 options to use Mongo with Node (and NestJS).<br />
<br />
1) <b>NestJS + Mongoose</b> where maybe the best tutorial I have found is here <a href="https://scotch.io/tutorials/building-a-modern-app-using-nestjs-mongodb-and-vuejs">https://scotch.io/tutorials/building-a-modern-app-using-nestjs-mongodb-and-vuejs</a> the issue is that I hate the fact I had to write the schema definitions and the typescript interfaces. If you are fine with writing everything 2 times ones the Schema and ones the Document as Typescript Interface maybe this is the best way to go.<br />
<br />
2) <b>NestJS</b><b> + TypeORM</b> where you can actually use TypeORM with MongoDB, however I do not recomment this if you want to learn more I would ask you to write this blog post <a href="https://medium.com/articode/typeorm-mongodb-review-8855903228b1">https://medium.com/articode/typeorm-mongodb-review-8855903228b1</a><br />
<br />
3)<b> </b><b>NestJS</b><b> + Typegoose</b> - basically what it does is it uses your domain objects to get the schema from them. And this is what this post is all about. There is a lot of documentation how you can achieve that, however I didn't like most of it, it just looked like too much code. On top of that ALL tutorials ALWAYS include using of a DTO class and I don't see a reason to use DTO classes at all in 99% of the cases.<br />
<br />
DTOs are great because of many reasons, but none of the tutorials on the internet actually explains why they want DTOs and in fact none of them need DTOs so I would like to write the most easy straightforward NEST + MongoDB + TypeGoose example.<br />
<br />
So first of all we will install nestjs cli, NestJS is very, very similar to Angular and even if you dont like angular trust me you will like NestJS. Great beginners tutorial for NestJS you can read here find <a href="https://scotch.io/tutorials/getting-started-with-nestjs">https://scotch.io/tutorials/getting-started-with-nestjs</a><br />
<br />
So lets start:<br />
<br />
<span style="font-family: "courier new" , "courier" , monospace;">npm i -g @nestjs/cli</span><br />
<br />
Then create a NestJS project.<br />
<br />
<span style="font-family: "courier new" , "courier" , monospace;">nest new nestjspoc-nest</span><br />
<br />
<span style="font-family: "courier new" , "courier" , monospace;">cd nestjspoc-nest</span><br />
<br />
// start the application using nodemon<br />
<span style="font-family: "courier new" , "courier" , monospace;">npm run start:dev</span><br />
<br />
open browser to localhost:3000 to verify hello world is displayed.<br />
<br />
Ok we will create a simple Service and Controller in a Module, lets say our applications will do something with Users and we will want UserModule which will hold the User domain objects, User services and user controllers.<br />
<br />
<span style="font-family: "courier new" , "courier" , monospace;">nest generate module user</span><br />
<br />
<span style="font-family: "courier new" , "courier" , monospace;">nest generate service user</span><br />
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span>
<span style="font-family: "courier new" , "courier" , monospace;">nest generate controller user</span><br />
<br />
<br />
Now you should have a folder which has UserModule, UserService and UserController.<br />
<br />
Which are almost empty.<br />
<br />
Nest we will use nestjs-typegoose because it just makes everything even easier.<br />
<br />
<span style="font-family: "courier new" , "courier" , monospace;">npm install --save nestjs-typegoose</span><br />
<br />
the typegoose has several peer dependencies so we need to install them as well. The two <b>nestjs</b> dependencies we already have but we need the other two.<br />
<pre style="background-color: white;"><pre><span style="color: #0000c0; font-family: "monaco";"><span style="font-size: 13.0667px;">"@typegoose/typegoose": "^6.0.0",
"@nestjs/common": "^6.3.1",
"@nestjs/core": "^6.3.1",
"mongoose": "^5.5.13"
</span></span></pre>
</pre>
Ones done your package.json should look like this:<br />
<pre style="background-color: white;"><span style="color: #000099; font-family: "monaco";"><span style="font-size: 13.0667px;">{
"name": "nestjspoc",
"version": "0.0.1",
"description": "",
"author": "",
"license": "MIT",
"scripts": {
"prebuild": "rimraf dist",
"build": "nest build",
"format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
"start": "nest start",
"start:dev": "nest start --watch",
"start:debug": "nest start --debug --watch",
"start:prod": "node dist/main",
"lint": "tslint -p tsconfig.json -c tslint.json",
"test": "jest",
"test:watch": "jest --watch",
"test:cov": "jest --coverage",
"test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand",
"test:e2e": "jest --config ./test/jest-e2e.json"
},
"dependencies": {
"@nestjs/common": "^6.7.2",
"@nestjs/core": "^6.7.2",
"@nestjs/platform-express": "^6.7.2",
<b>"nestjs-typegoose": "^7.0.0",</b>
"rimraf": "^3.0.0",
"rxjs": "^6.5.3",
<b> "@typegoose/typegoose": "^6.0.0",
"mongoose": "^5.5.13"</b>
},
"devDependencies": {
"@nestjs/cli": "^6.9.0",
"@nestjs/schematics": "^6.7.0",
"@nestjs/testing": "^6.7.1",
"@types/express": "^4.17.1",
"@types/jest": "^24.0.18",
"@types/node": "^12.7.5",
"@types/supertest": "^2.0.8",
"jest": "^24.9.0",
"prettier": "^1.18.2",
"supertest": "^4.0.2",
"ts-jest": "^24.1.0",
"ts-loader": "^6.1.1",
"ts-node": "^8.4.1",
"tsconfig-paths": "^3.9.0",
"tslint": "^5.20.0",
"typescript": "^3.6.3"
},
"jest": {
"moduleFileExtensions": [
"js",
"json",
"ts"
],
"rootDir": "src",
"testRegex": ".spec.ts$",
"transform": {
"^.+\\.(t|j)s$": "ts-jest"
},
"coverageDirectory": "./coverage",
"testEnvironment": "node"
}
}</span></span></pre>
The ones we added manually are in bold.<br />
<br />
Well this is the setup, let's write some code.<br />
<br />
Create your domain object user in a file user.ts for example :<br />
<br />
<span style="font-family: "courier new" , "courier" , monospace;">import {prop, Typegoose} from '@typegoose/typegoose';</span><br />
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span>
<span style="font-family: "courier new" , "courier" , monospace;">export class User extends Typegoose {</span><br />
<span style="font-family: "courier new" , "courier" , monospace;"> @prop()</span><br />
<span style="font-family: "courier new" , "courier" , monospace;"> name?: string;</span><br />
<span style="font-family: "courier new" , "courier" , monospace;">}</span><br />
<pre style="background-color: white; color: #333333; font-family: Monaco; font-size: 9.8pt;"><span style="color: #000099; font-weight: bold;">
</span></pre>
<pre style="background-color: white; color: #333333; font-family: Monaco; font-size: 9.8pt;"><span style="color: black; font-family: "times"; font-size: small; white-space: normal;">You see the @prop() yup you need this. You can learn more about validations and what you can do in the typegoose documentation.</span></pre>
<pre style="background-color: white; color: #333333; font-family: Monaco; font-size: 9.8pt;"><span style="color: black; font-family: "times"; font-size: small; white-space: normal;">
</span></pre>
<pre style="background-color: white; color: #333333; font-size: 9.8pt;"><span style="color: black; font-family: "times"; font-size: small; white-space: normal;">Then lets create or update our </span><span style="color: black; font-size: small; white-space: normal;"><span style="font-family: "courier new" , "courier" , monospace;">UserService</span></span><span style="color: black; font-family: "times"; font-size: small; white-space: normal;"> class.</span></pre>
<pre style="background-color: white; color: #333333; font-size: 9.8pt;"><span style="color: black; font-family: "times"; font-size: small; white-space: normal;">
</span></pre>
<pre style="background-color: white;"><span style="font-family: "courier new" , "courier" , monospace;"><span style="color: #333333;"><span style="font-size: 13.0667px;">import {Injectable} from '@nestjs/common';
import {User} from './domain/user';
import {InjectModel} from 'nestjs-typegoose';
import {ReturnModelType} from '@typegoose/typegoose';
@Injectable()
export class UserService {
constructor(@InjectModel(User) private readonly userModel: ReturnModelType<typeof user="">) {
}
async createUser() {
const user = new this.userModel();
user.name = 'test nestjs2';
return await user.save();
}
async createCustomUser(user: User) {
const createdUser = new this.userModel(user);
return await createdUser.save();
}
async listUsers(): Promise<user null=""> {
return await this.userModel.find().exec();
}
}</user></typeof></span></span><span style="color: #333333; font-size: 9.8pt;">
</span></span></pre>
<div>
<br /></div>
Ok the first magic here is <span style="background-color: white; color: #333333; font-family: "courier new" , "courier" , monospace; font-size: 13.0667px;">@InjectModel(User) private readonly userModel: ReturnModelType<typeof user=""> </typeof></span>, this will give us a userModel that we can use for our User type.<br />
<br />
The <span style="font-family: "courier new" , "courier" , monospace;">createCustomUser</span> and <span style="font-family: "courier new" , "courier" , monospace;">listUsers</span> I believe are clear..<br />
<br />
Next update our <span style="font-family: "courier new" , "courier" , monospace;">UserController</span>.<br />
<span style="font-family: "courier new" , "courier" , monospace;">import { Controller, Get } from '@nestjs/common';</span><br />
<span style="font-family: "courier new" , "courier" , monospace;">import { AppService } from './app.service';</span><br />
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span>
<span style="font-family: "courier new" , "courier" , monospace;">@Controller()</span><br />
<span style="font-family: "courier new" , "courier" , monospace;">export class AppController {</span><br />
<span style="font-family: "courier new" , "courier" , monospace;"> constructor(private readonly appService: AppService) {}</span><br />
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span>
<span style="font-family: "courier new" , "courier" , monospace;"> @Get()</span><br />
<span style="font-family: "courier new" , "courier" , monospace;"> getHello(): string {</span><br />
<span style="font-family: "courier new" , "courier" , monospace;"> return this.appService.getHello();</span><br />
<span style="font-family: "courier new" , "courier" , monospace;"> }</span><br />
<span style="font-family: "courier new" , "courier" , monospace;">}</span><br />
<div>
<br /></div>
<pre style="background-color: white; color: #333333; font-family: Monaco; font-size: 9.8pt;"></pre>
<div style="background-color: white; color: #333333;">
<span style="font-family: inherit;">Nothing fancy here, we just inject our Service and we call our two methods.</span></div>
<pre style="background-color: white; color: #333333; font-family: Monaco; font-size: 9.8pt;"></pre>
<pre style="background-color: white; color: #333333; font-family: Monaco; font-size: 9.8pt;"><span style="font-family: "times"; font-size: small; white-space: normal;">There are two fancy lines you need to add to your UserModule and AppModule </span></pre>
<pre style="background-color: white; color: #333333; font-family: Monaco; font-size: 9.8pt;"><span style="font-family: "times"; font-size: small; white-space: normal;">
</span></pre>
<pre style="background-color: white; color: #333333; font-family: Monaco; font-size: 9.8pt;"><span style="font-family: "times"; font-size: small; white-space: normal;">On the UserModule add as an imports teh value </span>TypegooseModule<span style="color: blue; font-size: 9.8pt; font-weight: bold;">.</span><span style="color: black; font-size: 9.8pt; font-style: italic;">forFeature</span><span style="color: #000099; font-size: 9.8pt; font-style: italic; font-weight: bold;">([</span><span style="font-size: 9.8pt; font-weight: bold;">User</span><span style="color: #000099; font-size: 9.8pt; font-style: italic; font-weight: bold;">]).</span></pre>
<pre style="background-color: white;"><span style="color: #333333; font-family: "monaco";"><span style="font-family: "courier new" , "courier" , monospace;">import { Module } from '@nestjs/common';</span></span><span style="color: #333333; font-family: "monaco";"><span style="font-family: "courier new" , "courier" , monospace;">import { UserController } from './user.controller';</span></span><span style="color: #333333; font-family: "monaco";"><span style="font-family: "courier new" , "courier" , monospace;">import { UserService } from './user.service';</span></span><span style="color: #333333; font-family: "monaco";"><span style="font-family: "courier new" , "courier" , monospace;">import {User} from './domain/user';</span></span><span style="color: #333333; font-family: "monaco";"><span style="font-family: "courier new" , "courier" , monospace;">import {TypegooseModule} from 'nestjs-typegoose';</span></span><span style="color: #333333; font-family: "monaco";"><span style="font-family: "courier new" , "courier" , monospace;">
</span></span><span style="color: #333333; font-family: "monaco";"><span style="font-family: "courier new" , "courier" , monospace;">@Module({</span></span><span style="color: #333333; font-family: "monaco";"><span style="font-family: "courier new" , "courier" , monospace;"> imports: [TypegooseModule.forFeature([User])],</span></span><span style="color: #333333; font-family: "monaco";"><span style="font-family: "courier new" , "courier" , monospace;"> controllers: [UserController],</span></span><span style="color: #333333; font-family: "monaco";"><span style="font-family: "courier new" , "courier" , monospace;"> providers: [UserService],</span></span><span style="color: #333333; font-family: "monaco";"><span style="font-family: "courier new" , "courier" , monospace;">})</span></span><span style="color: #333333; font-family: "monaco";"><span style="font-family: "courier new" , "courier" , monospace;">export class UserModule {}</span></span>
<span style="color: #333333; font-family: "monaco";"><span style="font-family: inherit;">
</span></span></pre>
<div>
<span style="font-family: inherit;"><br /></span></div>
<pre style="background-color: white;"><div style="color: #333333;">
<span style="font-family: inherit;">And on the AppModule just Configure TypeGoose MongoDB connection string together with your UserModule (which is already added by the CLI).</span></div>
<span style="color: #333333; font-family: "monaco";"><span style="font-size: 13.0667px;">
</span></span></pre>
<pre style="background-color: white;"><span style="color: #333333; font-family: "monaco";"><span style="font-family: "courier new" , "courier" , monospace; font-size: 13.0667px;">import {Module} from '@nestjs/common';
import {AppController} from './app.controller';
import {AppService} from './app.service';
import {UserModule} from './user/user.module';
import {TypegooseModule} from 'nestjs-typegoose';
@Module({
imports: [TypegooseModule.forRoot('mongodb://localhost:27017/nest'),
UserModule],
controllers: [AppController],
providers: [AppService],
})
export class AppModule {
}</span></span><span style="color: #333333; font-family: "monaco"; font-size: 9.8pt;">
</span></pre>
<div>
<br /></div>
<pre style="background-color: white; color: #333333; font-family: Monaco; font-size: 9.8pt;"><span style="font-family: "times"; font-size: small; white-space: normal;">
</span></pre>
And yes you need MongoDB to be running.<br />
<br />
Well that's it!<br />
<br />
Create a user:<br />
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span>
<span style="font-family: "courier new" , "courier" , monospace;">curl -X POST http://localhost:3000/user/createuser -H 'Content-Type: application/json' -d '{ "name": "Nayden Gochev" }'</span><br />
<br />
And you will receive<br />
<br />
<span style="font-family: "courier new" , "courier" , monospace;">{"_id":"5dc00795d9a25df587a1e5f9","name":"Nayden Gochev","__v":0}</span><br />
<br />
Also you can get the currently created users at any time :<br />
<br />
<span style="font-family: "courier new" , "courier" , monospace;">curl -X GET http://localhost:3000/user/listusers</span><br />
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span>
What else ? Validation ? Security and Tests of course ! :), all of this - next time ;) now was the nest time.<br />
<br />
the <b>full source code</b> can be download here:<br />
<a href="https://github.com/gochev/nest-js-poc-mongodb">https://github.com/gochev/nest-js-poc-mongodb</a><br />
<br />
About myself:<br />
I am a Java developer with a lot of Spring knowledge, but recently I had to write some JavaScript even if I don't want to, so maybe that explains why I like NestJS, and yes this done in Java and Spring is a lot easier <a href="https://github.com/gochev/spring-mvc-poc-mongodb">https://github.com/gochev/spring-mvc-poc-mongodb</a> but it is fun with NestJS right ? :)jNaydenhttp://www.blogger.com/profile/04678280364638370213noreply@blogger.com0tag:blogger.com,1999:blog-441421458098194397.post-12031457761692851532019-07-11T11:26:00.002+03:002019-07-11T11:26:16.737+03:00Use Multiple JVM versions on Mac OS and Linux<h2>
Linux</h2>
<br />
Download multiple Java versions and put them into /opt/ If you already have some JDK from ubuntu repo or etc not a big deal, just fix the paths bellow<br />
<br />
<ul>
<li>Register them as alternatives</li>
</ul>
<br />
<br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">sudo update-alternatives --install /usr/bin/java java /opt/java-8-oracle/bin/java 1081</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">sudo update-alternatives --install /usr/bin/java java /opt/sap-machine-jdk-11.0.3/bin/java 1080</span><br />
<br />
<br />
<ul>
<li>Edit your ~/.bashrc file</li>
</ul>
<br />
<br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">alias java11='sudo update-alternatives --set java /opt/sapmachine-jdk-11.0.3/bin/java;export JAVA_HOME=/opt/sapmachine-jdk-11.0.3/'</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">alias java8='sudo update-alternatives --set java /opt/java-8-oracle/bin/java;export JAVA_HOME=/usr/lib/java-8-oracle/'</span><br />
<br />
<br />
<ul>
<li>SAVE and start a new bash terminal</li>
</ul>
<br />
execute<br />
<br />
<span style="font-family: Courier New, Courier, monospace;"><span style="font-size: x-small;">java8</span> </span><span style="font-family: inherit;">to use java8</span><br />
<span style="font-family: Courier New, Courier, monospace;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace;"><span style="font-size: x-small;">java11</span> </span><span style="font-family: inherit;">to use java11</span><br />
<br />
the latest version you have set stays as system wide, but the JAVA_HOME is not :( you can put java8 or java11 as a last line in the bashrc but since it is sudo it will always require password when start and is not great ;(<br />
<br />
<h2>
Mac</h2>
<br />
<ul>
<li>Install homebrew, since it rox !</li>
</ul>
<br />
<br />
<ul>
<li>Install Oracle Java 8 or OpenJDK 8.</li>
</ul>
<br />
<br />
I recommend adoptopenjdk<br />
<br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">brew tap adoptopenjdk/openjdk</span><br />
<span style="font-size: x-small;"><br /></span>
<span style="font-size: x-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">brew search adoptopenjdk</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">brew cask install adoptopenjdk8</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">brew cask install adoptopenjdk11</span><br />
<br />
<br />
On mac since it RULZ you have a java_home executable (that changes and fixes both your path and your JAVA_HOME) , so the .bashrc changes are easy !<br />
<br />
<br />
<ul>
<li>Edit your ~/.bashrc file</li>
</ul>
<br />
<br />
<br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">export JAVA_8_HOME=$(/usr/libexec/java_home -v1.8)</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">export JAVA_11_HOME=$(/usr/libexec/java_home -v11)</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">alias java8='export JAVA_HOME=$JAVA_8_HOME'</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">alias java11='export JAVA_HOME=$JAVA_11_HOME'</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">java8</span><br />
<br />
Note: the latest execution of java8 is to make it system wide by default<br />
<br />
<br />
<ul>
<li>SAVE and start a new bash terminal</li>
</ul>
<br />
<br />
execute<br />
<br />
<span style="font-family: Courier New, Courier, monospace;"><span style="font-size: x-small;">java8</span> </span>to use java8<br />
<br />
<br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">java11</span> to use java11<br />
<br />
<h2>
<br />Windows</h2>
Use a normal OS or suffer :)jNaydenhttp://www.blogger.com/profile/04678280364638370213noreply@blogger.com0tag:blogger.com,1999:blog-441421458098194397.post-6783831882708571862019-04-11T10:52:00.001+03:002019-04-11T11:09:45.535+03:00Use Client Certificate Authentication with Java and RestTemplate<span style="font-family: "helvetica neue" , "arial" , "helvetica" , sans-serif; font-size: x-small;">As a follow up of the <a href="http://gochev.blogspot.com/2019/04/convert-pfx-certificate-to-jks-p12-crt.html">http://gochev.blogspot.com/2019/04/convert-pfx-certificate-to-jks-p12-crt.html</a> we now have a keystore and a truststore (if anyone needs) and we will use this keystore to send client side authentication using Spring's RestTemplate .</span><br />
<span style="font-family: "helvetica neue" , "arial" , "helvetica" , sans-serif; font-size: x-small;"><br /></span>
<span style="font-family: "helvetica neue" , "arial" , "helvetica" , sans-serif; font-size: x-small;">First copy your keystore.jks and truststore.jks in your classpath, no one wants absolute paths right ?:)</span><br />
<span style="font-family: "helvetica neue" , "arial" , "helvetica" , sans-serif; font-size: x-small;"><br /></span>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: x-small;"><span style="font-family: "helvetica neue" , "arial" , "helvetica" , sans-serif; font-size: xx-small;">Again a reminder </span><span style="background-color: white; color: #515151;">The difference between truststore and keystore if you are not aware is(quote from the</span><span style="background-color: white; color: #515151;"> </span><a href="http://download.oracle.com/javase/6/docs/technotes/guides/security/jsse/JSSERefGuide.html#RelsTM_KM" style="background-color: white; color: #6a6359; margin: 0px; outline: none; padding: 0px; text-decoration-line: none; transition: all 0.25s ease 0s;">JSSE ref guide</a>)<span style="background-color: white; color: #515151;">:</span><span style="background-color: white; color: #515151;"> </span></span><br />
<div style="background-color: white; border: 0px; box-sizing: inherit; clear: both; color: #242729; font-stretch: inherit; font-variant-east-asian: inherit; font-variant-numeric: inherit; line-height: inherit; margin: 0px 0px 1em; padding: 0px; vertical-align: baseline;">
<i style="margin: 0px; padding: 0px;"><span style="line-height: 30px !important; margin: 0px; padding: 0px;"><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: x-small;">TrustManager: Determines whether the remote authentication credentials (and thus the connection) should be trusted.</span></span></i></div>
<div style="background-color: white; border: 0px; box-sizing: inherit; clear: both; color: #242729; font-stretch: inherit; font-variant-east-asian: inherit; font-variant-numeric: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">
<i style="margin: 0px; padding: 0px;"><span style="line-height: 30px !important; margin: 0px; padding: 0px;"><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: x-small;">KeyManager: Determines which authentication credentials to send to the remote host.</span></span></i></div>
<span style="font-family: "helvetica neue" , "arial" , "helvetica" , sans-serif; font-size: x-small;"><br /></span>
<span style="font-family: "helvetica neue" , "arial" , "helvetica" , sans-serif; font-size: x-small;">The magic happens in the creation of SSLContext. Keep in mind the Spring Boot have a nice RestTemplateBuilder but I will not gonna use it, because someone of you might have an older version or like me, might just use a plain old amazing Spring.</span><br />
<span style="font-family: "helvetica neue" , "arial" , "helvetica" , sans-serif; font-size: x-small;"><br /></span>
<span style="font-family: "helvetica neue" , "arial" , "helvetica" , sans-serif; font-size: x-small;">If you <b>just</b> want to use the keystore:</span><br />
<span style="font-family: "helvetica neue" , "arial" , "helvetica" , sans-serif; font-size: x-small;"><br /></span>
<span style="font-family: "courier new" , "courier" , monospace; font-size: x-small;">final String allPassword = "123456";</span><br />
<span style="font-family: "courier new" , "courier" , monospace; font-size: x-small;">SSLContext sslContext = SSLContextBuilder</span><br />
<span style="font-family: "courier new" , "courier" , monospace; font-size: x-small;"> .create()</span><br />
<span style="font-family: "courier new" , "courier" , monospace; font-size: x-small;"> .loadKeyMaterial(ResourceUtils.getFile("classpath:keystore.jks"),</span><br />
<span style="font-family: "courier new" , "courier" , monospace; font-size: x-small;"> allPassword.toCharArray(), allPassword.toCharArray())</span><br />
<span style="font-size: x-small;"><span style="font-family: "courier new" , "courier" , monospace;"> </span><span style="font-family: "courier new" , "courier" , monospace;">.build();</span></span><br />
<br />
if you just want to use the truststore<br />
<br />
<span style="font-family: "courier new" , "courier" , monospace; font-size: x-small;">final String allPassword = "123456";</span><br />
<span style="font-family: "courier new" , "courier" , monospace; font-size: x-small;">SSLContext sslContext = SSLContextBuilder</span><br />
<span style="font-family: "courier new" , "courier" , monospace; font-size: x-small;"> .create()</span><br />
<span style="font-family: "courier new" , "courier" , monospace; font-size: x-small;"> .loadTrustMaterial(ResourceUtils.getFile("classpath:truststore.jks"), allPassword.toCharArray())</span><br />
<span style="font-family: "courier new" , "courier" , monospace; font-size: x-small;"> .build();</span><br />
<br />
<span style="font-family: "helvetica neue" , "arial" , "helvetica" , sans-serif; font-size: x-small;">I guess you know how to use both ;), if you want to IGNORE the truststore certificate checking and trust ALL certificates (might be handy for testing purposes and localhost)</span><br />
<br />
<span style="font-family: "courier new" , "courier" , monospace; font-size: x-small;">final String allPassword = "123456";</span><br />
<span style="font-family: "courier new" , "courier" , monospace; font-size: x-small;">TrustStrategy acceptingTrustStrategy = (X509Certificate[] chain, String authType) -> true;</span><br />
<span style="font-family: "courier new" , "courier" , monospace; font-size: x-small;">SSLContext sslContext = SSLContextBuilder</span><br />
<span style="font-family: "courier new" , "courier" , monospace; font-size: x-small;"> .create()</span><br />
<span style="font-family: "courier new" , "courier" , monospace; font-size: x-small;"> .loadTrustMaterial(ResourceUtils.getFile("classpath:truststore.jks"), allPassword.toCharArray())</span><br />
<span style="font-family: "courier new" , "courier" , monospace; font-size: x-small;"> .loadTrustMaterial(null, acceptingTrustStrategy) //accept all</span><br />
<span style="font-family: "courier new" , "courier" , monospace; font-size: x-small;"> .build();</span><br />
<br />
<br />
<span style="font-family: "helvetica neue" , "arial" , "helvetica" , sans-serif; font-size: x-small;">Ones you have the sslContext you simply do :</span><br />
<br />
<span style="font-family: "courier new" , "courier" , monospace; font-size: x-small;">HttpClient client = HttpClients.custom()</span><br />
<span style="font-family: "courier new" , "courier" , monospace; font-size: x-small;"> .setSSLContext(sslContext)</span><br />
<span style="font-family: "courier new" , "courier" , monospace; font-size: x-small;"> .build();</span><br />
<span style="font-family: "courier new" , "courier" , monospace; font-size: x-small;"><br /></span>
<span style="font-family: "courier new" , "courier" , monospace; font-size: x-small;">HttpComponentsClientHttpRequestFactory requestFactory =</span><br />
<span style="font-family: "courier new" , "courier" , monospace; font-size: x-small;"> new HttpComponentsClientHttpRequestFactory();</span><br />
<span style="font-family: "courier new" , "courier" , monospace; font-size: x-small;"><br /></span>
<span style="font-family: "courier new" , "courier" , monospace; font-size: x-small;">requestFactory.setHttpClient(client);</span><br />
<span style="font-family: "courier new" , "courier" , monospace; font-size: x-small;"><br /></span>
<span style="font-family: "courier new" , "courier" , monospace; font-size: x-small;">RestTemplate restTemplate = new RestTemplate(requestFactory);</span><br />
<span style="font-family: "courier new" , "courier" , monospace; font-size: x-small;"><br /></span>
<span style="font-family: "courier new" , "courier" , monospace; font-size: x-small;">return restTemplate;</span><br />
<pre></pre>
<span style="font-family: "helvetica neue" , "arial" , "helvetica" , sans-serif; font-size: x-small;">And Voala, now each time you make a get/post or exchange with your restTemplate you will send the client side certificate.<br />
<br />Full example (the "tests" version) that sends client side certificate and ignores the SSL certificate</span><br />
<pre></pre>
<pre style="background-color: white; color: #333333; font-family: 'Monaco'; font-size: 9.8pt;"><pre></pre>
</pre>
<span style="font-family: "courier new" , "courier" , monospace; font-size: x-small;">private RestTemplate getRestTemplateClientAuthentication()</span><br />
<span style="font-family: "courier new" , "courier" , monospace; font-size: x-small;"> throws IOException, UnrecoverableKeyException, CertificateException, NoSuchAlgorithmException,</span><br />
<span style="font-family: "courier new" , "courier" , monospace; font-size: x-small;"> KeyStoreException, KeyManagementException {</span><br />
<span style="font-family: "courier new" , "courier" , monospace; font-size: x-small;"><br /></span>
<span style="font-family: "courier new" , "courier" , monospace; font-size: x-small;"> final String allPassword = "123456";</span><br />
<span style="font-family: "courier new" , "courier" , monospace; font-size: x-small;"> TrustStrategy acceptingTrustStrategy = (X509Certificate[] chain, String authType) -> true;</span><br />
<span style="font-family: "courier new" , "courier" , monospace; font-size: x-small;"> SSLContext sslContext = SSLContextBuilder</span><br />
<span style="font-family: "courier new" , "courier" , monospace; font-size: x-small;"> .create()</span><br />
<span style="font-family: "courier new" , "courier" , monospace; font-size: x-small;"> .loadKeyMaterial(ResourceUtils.getFile("classpath:keystore.jks"),</span><br />
<span style="font-family: "courier new" , "courier" , monospace; font-size: x-small;"> allPassword.toCharArray(), allPassword.toCharArray())</span><br />
<span style="font-family: "courier new" , "courier" , monospace; font-size: x-small;">//.loadTrustMaterial(ResourceUtils.getFile("classpath:truststore.jks"), allPassword.toCharArray())</span><br />
<span style="font-family: "courier new" , "courier" , monospace; font-size: x-small;"> .loadTrustMaterial(null, acceptingTrustStrategy)</span><br />
<span style="font-family: "courier new" , "courier" , monospace; font-size: x-small;"> .build();</span><br />
<span style="font-family: "courier new" , "courier" , monospace; font-size: x-small;"><br /></span>
<span style="font-family: "courier new" , "courier" , monospace; font-size: x-small;"> HttpClient client = HttpClients.custom()</span><br />
<span style="font-family: "courier new" , "courier" , monospace; font-size: x-small;"> .setSSLContext(sslContext)</span><br />
<span style="font-family: "courier new" , "courier" , monospace; font-size: x-small;"> .build();</span><br />
<span style="font-family: "courier new" , "courier" , monospace; font-size: x-small;"><br /></span>
<span style="font-family: "courier new" , "courier" , monospace; font-size: x-small;"> HttpComponentsClientHttpRequestFactory requestFactory =</span><br />
<span style="font-family: "courier new" , "courier" , monospace; font-size: x-small;"> new HttpComponentsClientHttpRequestFactory();</span><br />
<span style="font-family: "courier new" , "courier" , monospace; font-size: x-small;"><br /></span>
<span style="font-family: "courier new" , "courier" , monospace; font-size: x-small;"> requestFactory.setHttpClient(client);</span><br />
<span style="font-family: "courier new" , "courier" , monospace; font-size: x-small;"><br /></span>
<span style="font-family: "courier new" , "courier" , monospace; font-size: x-small;"> RestTemplate restTemplate = new RestTemplate(requestFactory);</span><br />
<span style="font-family: "courier new" , "courier" , monospace; font-size: x-small;"><br /></span>
<span style="font-family: "courier new" , "courier" , monospace; font-size: x-small;"> return restTemplate;</span><br />
<span style="font-family: "courier new" , "courier" , monospace; font-size: x-small;">}</span><br />
<br />
<span style="font-family: "helvetica neue" , "arial" , "helvetica" , sans-serif; font-size: x-small;">Hope this is handy for someone :) Also this should be extremely handy if you integrate BNP Paribas Leasing : ) </span>jNaydenhttp://www.blogger.com/profile/04678280364638370213noreply@blogger.com0tag:blogger.com,1999:blog-441421458098194397.post-36509198886945106312019-04-11T10:23:00.003+03:002019-04-11T11:04:00.019+03:00Convert PFX certificate to JKS, P12, CRT <span style="font-family: "helvetica neue" , "arial" , "helvetica" , sans-serif;">I recently had to use a PFX certificate for client authentication (maybe another post will be coming) and for that reason I had to convert it to a Java keystore (JKS). </span><br />
<span style="font-family: "helvetica neue" , "arial" , "helvetica" , sans-serif;"><br /></span>
<span style="font-family: "helvetica neue" , "arial" , "helvetica" , sans-serif;">We will create BOTH a truststore and a keystore, because based on your needs you might need one or the other. </span><br />
<span style="font-family: "helvetica neue" , "arial" , "helvetica" , sans-serif;">The difference between truststore and keystore if you are not aware is(quote from the <a href="http://download.oracle.com/javase/6/docs/technotes/guides/security/jsse/JSSERefGuide.html#RelsTM_KM">JSSE ref guide</a>:
</span><br />
<div style="border: 0px; box-sizing: inherit; clear: both; color: #242729; font-size: 15px; font-stretch: inherit; font-variant-east-asian: inherit; font-variant-numeric: inherit; line-height: inherit; margin-bottom: 1em; padding: 0px; vertical-align: baseline;">
<i><span style="font-family: "helvetica neue" , "arial" , "helvetica" , sans-serif;"><br /></span></i></div>
<div style="border: 0px; box-sizing: inherit; clear: both; color: #242729; font-size: 15px; font-stretch: inherit; font-variant-east-asian: inherit; font-variant-numeric: inherit; line-height: inherit; margin-bottom: 1em; padding: 0px; vertical-align: baseline;">
<i><span style="font-family: "helvetica neue" , "arial" , "helvetica" , sans-serif;">TrustManager: Determines whether the remote authentication credentials (and thus the connection) should be trusted.</span></i></div>
<div style="border: 0px; box-sizing: inherit; clear: both; color: #242729; font-stretch: inherit; font-variant-east-asian: inherit; font-variant-numeric: inherit; line-height: inherit; padding: 0px; vertical-align: baseline;">
<i><span style="font-family: "helvetica neue" , "arial" , "helvetica" , sans-serif;">KeyManager: Determines which authentication credentials to send to the remote host.</span></i></div>
<div style="border: 0px; box-sizing: inherit; clear: both; color: #242729; font-size: 15px; font-stretch: inherit; font-variant-east-asian: inherit; font-variant-numeric: inherit; line-height: inherit; padding: 0px; vertical-align: baseline;">
<i><span style="font-family: "helvetica neue" , "arial" , "helvetica" , sans-serif;"><br /></span></i></div>
<div style="border: 0px; box-sizing: inherit; clear: both; font-stretch: inherit; font-variant-east-asian: inherit; font-variant-numeric: inherit; line-height: inherit; padding: 0px; vertical-align: baseline;">
<span style="font-family: "helvetica neue" , "arial" , "helvetica" , sans-serif;">Ok that's enough what you will need is openssl and Java 7+ ;) !</span></div>
<div style="border: 0px; box-sizing: inherit; clear: both; font-stretch: inherit; font-variant-east-asian: inherit; font-variant-numeric: inherit; line-height: inherit; padding: 0px; vertical-align: baseline;">
<span style="font-family: "helvetica neue" , "arial" , "helvetica" , sans-serif;"><br /></span></div>
<div style="border: 0px; box-sizing: inherit; clear: both; font-stretch: inherit; font-variant-east-asian: inherit; font-variant-numeric: inherit; line-height: inherit; padding: 0px; vertical-align: baseline;">
<span style="font-family: "helvetica neue" , "arial" , "helvetica" , sans-serif;">First let's generate a key from the pfx file, this key is later used for p12 keystore.</span></div>
<div style="border: 0px; box-sizing: inherit; clear: both; font-stretch: inherit; font-variant-east-asian: inherit; font-variant-numeric: inherit; line-height: inherit; padding: 0px; vertical-align: baseline;">
<br /></div>
<div style="border: 0px; box-sizing: inherit; clear: both; font-stretch: inherit; font-variant-east-asian: inherit; font-variant-numeric: inherit; line-height: inherit; padding: 0px; vertical-align: baseline;">
<b><span style="font-family: "courier new" , "courier" , monospace;">openssl pkcs12 -in example.pfx -nocerts -out </span><span style="font-family: "courier new" , "courier" , monospace;">example</span><span style="font-family: "courier new" , "courier" , monospace;">.key </span></b></div>
<div style="border: 0px; box-sizing: inherit; clear: both; font-stretch: inherit; font-variant-east-asian: inherit; font-variant-numeric: inherit; line-height: inherit; padding: 0px; vertical-align: baseline;">
<span style="font-family: "courier new" , "courier" , monospace;">Enter Import Password:</span></div>
<div style="border: 0px; box-sizing: inherit; clear: both; font-stretch: inherit; font-variant-east-asian: inherit; font-variant-numeric: inherit; line-height: inherit; padding: 0px; vertical-align: baseline;">
<span style="font-family: "courier new" , "courier" , monospace;">MAC verified OK</span></div>
<div style="border: 0px; box-sizing: inherit; clear: both; font-stretch: inherit; font-variant-east-asian: inherit; font-variant-numeric: inherit; line-height: inherit; padding: 0px; vertical-align: baseline;">
<span style="font-family: "courier new" , "courier" , monospace;">Enter PEM pass phrase:</span></div>
<div style="border: 0px; box-sizing: inherit; clear: both; font-stretch: inherit; font-variant-east-asian: inherit; font-variant-numeric: inherit; line-height: inherit; padding: 0px; vertical-align: baseline;">
<span style="font-family: "courier new" , "courier" , monospace;">Verifying - Enter PEM pass phrase:</span></div>
<div style="border: 0px; box-sizing: inherit; clear: both; color: #242729; font-family: Arial, "Helvetica Neue", Helvetica, sans-serif; font-size: 15px; font-stretch: inherit; font-variant-east-asian: inherit; font-variant-numeric: inherit; line-height: inherit; padding: 0px; vertical-align: baseline;">
<span style="color: black; font-family: "times"; font-size: small;"><br /></span></div>
<div style="border: 0px; box-sizing: inherit; clear: both; font-stretch: inherit; font-variant-east-asian: inherit; font-variant-numeric: inherit; line-height: inherit; padding: 0px; vertical-align: baseline;">
<span style="font-family: "helvetica neue" , "arial" , "helvetica" , sans-serif;">As shown here you will be asked for the password of the pfx file, later you will be asked to enter a PEM passphase lets for example use 123456 for everything here.</span></div>
<div style="border: 0px; box-sizing: inherit; clear: both; font-stretch: inherit; font-variant-east-asian: inherit; font-variant-numeric: inherit; line-height: inherit; padding: 0px; vertical-align: baseline;">
<span style="font-family: "helvetica neue" , "arial" , "helvetica" , sans-serif;">The second commands is almost the same but it is about nokey and a crt this time</span></div>
<div style="border: 0px; box-sizing: inherit; clear: both; font-stretch: inherit; font-variant-east-asian: inherit; font-variant-numeric: inherit; line-height: inherit; padding: 0px; vertical-align: baseline;">
<br /></div>
<div style="border: 0px; box-sizing: inherit; clear: both; font-stretch: inherit; font-variant-east-asian: inherit; font-variant-numeric: inherit; line-height: inherit; padding: 0px; vertical-align: baseline;">
<style type="text/css">
p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px 'Helvetica Neue'}
</style>
</div>
<div class="p1">
<b><span style="font-family: "courier new" , "courier" , monospace; font-size: small;">openssl pkcs12 -in </span><span style="font-family: "courier new" , "courier" , monospace; font-size: small;">example</span><span style="font-family: "courier new" , "courier" , monospace; font-size: small;">.pfx -clcerts -nokeys -out </span><span style="font-family: "courier new" , "courier" , monospace; font-size: small;">example</span><span style="font-family: "courier new" , "courier" , monospace; font-size: small;">.crt</span></b></div>
<div class="p1">
<span style="font-family: "courier new" , "courier" , monospace; font-size: small;">Enter Import Password:</span></div>
<div class="p1">
<span style="font-family: "courier new" , "courier" , monospace; font-size: small;">MAC verified OK</span></div>
<div class="p1">
<span style="font-family: "courier new" , "courier" , monospace; font-size: small;"><br /></span></div>
<div class="p1">
<span style="font-family: "helvetica neue" , "arial" , "helvetica" , sans-serif; font-size: small;">Now we have a key and and a crt file</span></div>
<div class="p1">
<span style="font-family: "helvetica neue" , "arial" , "helvetica" , sans-serif; font-size: small;">Next step is to create a truststore.</span></div>
<div class="p1">
<span style="font-family: "helvetica neue" , "arial" , "helvetica" , sans-serif; font-size: small;"><br /></span></div>
<div class="p1">
<b><span style="font-family: "courier new" , "courier" , monospace; font-size: small;">keytool -import -file </span><span style="font-family: "courier new" , "courier" , monospace; font-size: small;">example</span><span style="font-family: "courier new" , "courier" , monospace; font-size: small;">.crt -alias exampleCA -keystore truststore.jks</span></b></div>
<div class="p1">
<span style="font-family: "courier new" , "courier" , monospace; font-size: small;">Enter keystore password:</span></div>
<div class="p1">
<span style="font-family: "courier new" , "courier" , monospace; font-size: small;">Re-enter new password:</span></div>
<div class="p1">
<span style="font-family: "courier new" , "courier" , monospace; font-size: small;"></span></div>
<div class="p1">
<span style="font-family: "courier new" , "courier" , monospace; font-size: small;">Owner: CN=.....</span></div>
<div class="p1">
<span style="font-family: "courier new" , "courier" , monospace; font-size: small;">.......</span></div>
<div class="p1">
<span style="font-family: "courier new" , "courier" , monospace; font-size: small;">Trust this certificate? [no]: yes</span></div>
<div class="p1">
<span style="font-family: "courier new" , "courier" , monospace; font-size: small;"></span></div>
<div class="p1">
<span style="font-family: "courier new" , "courier" , monospace; font-size: small;">Certificate was added to keystore</span></div>
<div class="p1">
<span style="font-family: "courier new" , "courier" , monospace; font-size: small;"><br /></span></div>
<div class="p1">
<span style="font-family: "helvetica neue" , "arial" , "helvetica" , sans-serif; font-size: small;">As you can see here you just import this crt file into a jks truststore and set some password. For the question do you trust this certificate you say yes, so it is added in the truststore.</span></div>
<div class="p1">
<span style="font-family: "helvetica neue" , "arial" , "helvetica" , sans-serif; font-size: small;"><br /></span></div>
<div class="p1">
<span style="font-family: "helvetica neue" , "arial" , "helvetica" , sans-serif; font-size: small;">We are done if you only need a truststore. </span></div>
<div class="p1">
<span style="font-family: "helvetica neue" , "arial" , "helvetica" , sans-serif; font-size: small;">The last step(s) is to create a keystore</span></div>
<div class="p1">
<span style="font-family: "helvetica neue" , "arial" , "helvetica" , sans-serif; font-size: small;"><br /></span></div>
<div class="p1">
<b><span style="font-family: "courier new" , "courier" , monospace; font-size: small;">openssl pkcs12 -export -in </span><span style="font-family: "courier new" , "courier" , monospace; font-size: small;">example</span><span style="font-family: "courier new" , "courier" , monospace; font-size: small;">.crt -inkey </span><span style="font-family: "courier new" , "courier" , monospace; font-size: small;">example</span><span style="font-family: "courier new" , "courier" , monospace; font-size: small;">.key -certfile example.crt -name "examplecert" -out keystore.p12</span></b></div>
<div class="p1">
<span style="font-family: "courier new" , "courier" , monospace; font-size: small;">Enter pass phrase for example.key:</span></div>
<div class="p1">
<span style="font-family: "courier new" , "courier" , monospace; font-size: small;">Enter Export Password:</span></div>
<div class="p1">
</div>
<div class="p1">
<span style="font-family: "courier new" , "courier" , monospace; font-size: small;">Verifying - Enter Export Password:</span></div>
<div class="p1">
<span style="font-family: "courier new" , "courier" , monospace; font-size: small;"><br /></span></div>
<div class="p1">
<span style="font-family: "helvetica neue" , "arial" , "helvetica" , sans-serif; font-size: small;">This p12 keystore is enough in many cases, still if you need a JKS keystore you need one additional command</span></div>
<div class="p1">
<span style="font-family: "helvetica neue" , "arial" , "helvetica" , sans-serif; font-size: small;"><br /></span></div>
<div class="p1">
<span style="font-family: "courier new" , "courier" , monospace; font-size: small;"><b>keytool -importkeystore -srckeystore keystore.p12 -srcstoretype pkcs12 -destkeystore keystore.jks -deststoretype JKS</b></span></div>
<div class="p1">
<span style="font-family: "courier new" , "courier" , monospace; font-size: small;">Importing keystore keystore.p12 to keystore.jks...</span></div>
<div class="p1">
<span style="font-family: "courier new" , "courier" , monospace; font-size: small;">Enter destination keystore password:</span></div>
<div class="p1">
<span style="font-family: "courier new" , "courier" , monospace; font-size: small;">Re-enter new password:</span></div>
<div class="p1">
<span style="font-family: "courier new" , "courier" , monospace; font-size: small;">Enter source keystore password:</span></div>
<div class="p1">
<span style="font-family: "courier new" , "courier" , monospace; font-size: small;">Entry for alias examplecert successfully imported.</span></div>
<div class="p1">
<span style="font-family: "courier new" , "courier" , monospace; font-size: small;">Import command completed: 1 entries successfully imported, 0 entries failed or cancelled</span></div>
<div class="p1">
<span style="font-family: "courier new" , "courier" , monospace; font-size: small;"><br /></span></div>
<div class="p1">
<span style="font-family: "courier new" , "courier" , monospace; font-size: small;">Warning:</span></div>
<div class="p1">
</div>
<div class="p1">
<span style="font-family: "courier new" , "courier" , monospace; font-size: small;">The JKS keystore uses a proprietary format. It is recommended to migrate to PKCS12 which is an industry standard format using "keytool -importkeystore -srckeystore keystore.jks -destkeystore keystore.jks -deststoretype pkcs12".</span></div>
<div class="p1">
<span style="font-family: "courier new" , "courier" , monospace; font-size: small;"><br /></span></div>
<div class="p1">
<span style="font-family: "helvetica neue" , "arial" , "helvetica" , sans-serif; font-size: small;">That is all folks ! I hope this helps someone :) </span></div>
<div class="p1">
<span style="font-family: "helvetica neue" , "arial" , "helvetica" , sans-serif; font-size: small;"><br /></span></div>
<div class="p1">
<span style="font-family: "courier new" , "courier" , monospace; font-size: small;"><b>ls </b> </span></div>
<div class="p1">
<span style="font-family: "courier new" , "courier" , monospace; font-size: small;">example.pfx example.key keystore.p12</span></div>
<div class="p1">
<span style="font-family: "courier new" , "courier" , monospace; font-size: small;">example.crt keystore.jks truststore.jks</span></div>
<div class="p1">
</div>
<div class="p1">
<br /></div>
<div class="p1">
<span style="font-family: "helvetica neue" , "arial" , "helvetica" , sans-serif; font-size: small;">See you in <a href="https://gochev.blogspot.com/2019/04/use-client-certificate-authentication.html">post 2 how to use this keystore for client side authentication</a>. Also how to use the truststore if you need to use it.</span></div>
<div class="p1">
<span style="font-family: "helvetica neue" , "arial" , "helvetica" , sans-serif; font-size: small;"><br /></span></div>
jNaydenhttp://www.blogger.com/profile/04678280364638370213noreply@blogger.com0tag:blogger.com,1999:blog-441421458098194397.post-28449915474217948982019-02-26T12:09:00.000+02:002019-02-26T12:09:44.107+02:00Youtube video channel of the Bulgarian Java User GroupBad news everyone,<br />
as you already have noticed I do not have time to write blogs :(<br />
<br />
However I would recommend you to check and keep an eye on the youtube channel of the Bulgarian Java User Group (<a href="http://jug.bg/">http://jug.bg</a>) which is <a href="https://www.youtube.com/user/BulgarianJUG/" target="_blank">https://www.youtube.com/user/BulgarianJUG/</a><br />
<br />
You can enjoy all the jprime conference video recordings at <a href="https://www.youtube.com/user/BulgarianJUG/playlists">https://www.youtube.com/user/BulgarianJUG/playlists</a> but also checkout the videos tab since we have a lot of non jprime videos uploaded as well and maybe at some point you can even see me ;)<br />
<br />
<br />jNaydenhttp://www.blogger.com/profile/04678280364638370213noreply@blogger.com0tag:blogger.com,1999:blog-441421458098194397.post-73857344195951872382019-01-05T17:25:00.003+02:002019-01-05T17:26:00.748+02:00jPrime 2018 videos freely availableGood news everyone,<br />
<br />
the videos of jPrime 2018 are freely available at <a href="https://www.youtube.com/watch?v=xs3heuY21Z0&list=PLcqA4DRMgIYvGPZfrK0EcMxEQCrtSl9A3">https://www.youtube.com/watch?v=xs3heuY21Z0&list=PLcqA4DRMgIYvGPZfrK0EcMxEQCrtSl9A3</a><br />
<br />
Also in Youtube Bulgarian Java User Group channel you may find a lot of helpful Java related videos from jPrime 2017, 2016, 2015 or other Bulgarian Java User Group talks and activities : <a href="https://www.youtube.com/user/BulgarianJUG/">https://www.youtube.com/user/BulgarianJUG/</a><br />
<br />
Hope to see everyone of you at jPrime 2019 !<br />
Or some of the Bulgarian Java User Group (<a href="http://jug.bg/">jug.bg</a>) or java beer events (<a href="http://java.beer/">http://java.beer</a>)jNaydenhttp://www.blogger.com/profile/04678280364638370213noreply@blogger.com0tag:blogger.com,1999:blog-441421458098194397.post-58523331448008766592016-05-14T09:48:00.001+03:002017-07-26T16:53:12.419+03:00Bulgarian Java User Group in Java MagazineBulgarian Java User Group ( <a data-mce-href="http://jug.bg" href="http://jug.bg/" target="_blank">http://jug.bg</a> ) in Java Magazine.<br />
I am very happy that the Bulgarian Java User Group now is on a page at Java Magazine - <br />
<img data-mce-style="max-height: none; max-width: 100%;" data-position="3" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjKWxxvmKect9M7spLpUe7tMKwX_h9CHJ4S4-UBAQz1pgMqbbPma03M-hZJxr0BNc0GCDwZUOUaPy9xb5HeMTQFB9FiMwF0phEsATGELd_Ywal8_vfHj69AfntcjWdZ-f9czKuRnmqIJzY/I/ScreenShot2016-05-14at09.48.00.png" style="max-height: none; max-width: 100%;" /><br />
<a data-mce-href="http://www.javamagazine.mozaicreader.com/MarApr2016/Facebook#&pageSet=19&page=0&contentItem=0" href="http://www.javamagazine.mozaicreader.com/MarApr2016/Facebook#&pageSet=19&page=0&contentItem=0">http://www.javamagazine.mozaicreader.com/MarApr2016/Facebook#&pageSet=19&page=0&contentItem=0</a>jNaydenhttp://www.blogger.com/profile/04678280364638370213noreply@blogger.com0tag:blogger.com,1999:blog-441421458098194397.post-86476719670042633442015-10-05T15:31:00.001+03:002015-10-05T15:31:38.351+03:00jPrime videos 2015<p>JPrime 2015 videos are now available at <a href="http://jprime.io/nav/article/40" data-mce-href="http://jprime.io/nav/article/40">http://jprime.io/nav/article/40</a>.</p><p>jPrime is a one day conference with talks on Java, various languages on the JVM, mobile, web and best practices. <br>This year it was held on 27th May 2015 in Sofia Event Center. It's run by the Bulgarian Java User Group and backed by the biggest companies in the city. <br>jPrime features a combination of great international speakers along with the best presenters from Bulgaria and the Balkans. </p><p>More info for 2016 at http://jprime.io</p><p><br></p>jNaydenhttp://www.blogger.com/profile/04678280364638370213noreply@blogger.com0tag:blogger.com,1999:blog-441421458098194397.post-63594013146181771082015-09-23T15:26:00.001+03:002019-01-05T17:19:02.909+02:00Spring one 2gx conference reviewLast week I was able to visit the Spring One 4gx conference in Washington, D.C. SpringOne4gx is an annual conference made by Pivotal usually held in September each year but on different location in USA each time.<br />
<br />
I have to share that this was the BEST conference I have attended to in my whole life. The conference was taking place at Marriott Marquis which was a cool place, the only big minus was that it was extremely cold, but I believe this is an issue about US in general (very warm outside and cold inside - yes it was strange indeed).<br />
<br />
This was my first visit to USA so I had to say that I am not impressed, many poor peoples sleeping on the streets and at least 1 different crazy day each day (shooting with virtual rifle or talking to strangers and etc.) anyway if this is capitalism I don't like it.<br />
<br />
About the conference itself: the conference was in 4 days, the first day was mostly only, a keynote and registration + a diner. I have to say that the conference tickets was covering everything breakfast , lunch and diner and since I was there only 2 days more (one day for landing in Washington and 1 day leaving) I actually spend less then 100$. There was a keynote each day after the presentations (weird right?) but this turns out to be awesome since it was during or after diner and before the free sponsored drinks and was amazingly fun watching Josh Long and Dave Sawyer doing live coding while we eat.<br />
<img data-mce-style="margin-top: 5px; margin-right: 5px; margin-bottom: 5px; max-height: none; max-width: 100%;" data-position="3" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiyAhP2U1JIjkoIs6Hg0voU-bbh2xTUKj7lmB8PZzzjutiVbrvb1fS_kfCLI1jCh3WTidSD5LX0qozF7ew2F_P9QZCb8wBJ8V6lvl5Cmw9GUyIv3Dqa5kZ4HCgA2S7pJiQ-LsoePpMSdtE/I/thumb_IMG_0821_1024.jpg" style="margin-bottom: 5px; margin-right: 5px; margin-top: 5px; max-height: none; max-width: 100%;" /><br />
<br />
The conference had 9 streams, yes thats correct 9! Of course half of them were related to Groovy and Grails so I didn't visited any of them. The slots were 1 hour and 30 minutes long (a lot longer then the regular 45 minutes used in most conferences) and I have to say that I enjoyed this timing, since the presenter was able to show a lot more.<br />
<br />
There was no single presentation about what is new in XX, see our new product and so on ... 99% of the topics were about how to do something and 1% was about tricks when using something.<br />
<br />
The whole conference was concentrated a lot about Cloud and Micro services and well I do liked a lot of what I saw and defenatly will use Eureka at some point. (google for Service Discovery Eureka).<br />
<img data-mce-style="max-height: none; max-width: 100%;" data-position="3" height="768" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh901eScK-PVDc5cSc1dYzy8B_gtwuTn2IXjGZ7d5Yt88aag8vroB-P9o7HvSQguo8wDmJ8eCom3PmDg4EA9me1fajTuC3XP_5q1UUQDW0XfNZ7DgF5NzladdS-H5xiuZO28D1sBnCYYs4/I/thumb_IMG_0831_1024.jpg" style="max-height: none; max-width: 100%;" width="1024" />There were 2 presentations about JavaScript I think and of course they were shown with some sort of spring integration or spring boot backend etc. <br />
<br />
The keynote was EVERY night .. every night there was a keynote where, as I said, the live coding part was involving development of an application step by step.<br />
<br />
On the second day we had a presentations made by our Petar Tahchiev about building ecommerce with spring. How spring helped us, what was our issues, how to we fixed them and etc. of course 1 hour was not enoughh, but most people liked the presentation.<br />
<br />
Here is a photo of our great team:<br />
<img data-mce-style="margin-top: 5px; margin-right: 5px; margin-bottom: 5px; max-height: none; max-width: 100%;" data-position="3" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjg3i5de342zyqvcMzdF13Y17mbWVyBf4vh3WRAeSg4x0pGslJPYWEAapddHj2nOY-hQmtwb9vhNYMw-UOjVNTAtcsYhICv5RdMdEoyEYriINdcValFkwGhZY94QVymZiIpOSMvSwLJCw8/I/thumb_IMG_0842_10242.jpg" style="margin-bottom: 5px; margin-right: 5px; margin-top: 5px; max-height: none; max-width: 100%;" /><br />
<br />
Also I have to say that there will be videos of everything (except the keynote I guess) in the next 1-6 months available to everyone so search for spring one 4gx videos regularly.<br />
<br />
I definitely advice you to visit springone4gx if you can next year, or if you are in Europe like me at least visit the Spring IO conference in Spain which was also quite good.jNaydenhttp://www.blogger.com/profile/04678280364638370213noreply@blogger.com0tag:blogger.com,1999:blog-441421458098194397.post-30245034882767910672015-06-18T21:50:00.001+03:002015-06-18T21:52:54.505+03:00Introduction to Spring MVC (In Bulgarian)This is video from the presentation I did for <a href="http://softuni.bg/">Software University </a> at Sofia, Bulgaria.<br />
Camera : <br/>
<iframe width="560" height="315" src="https://www.youtube.com/embed/crYYNN9rB3I" frameborder="0" allowfullscreen></iframe>
<br/>
Screen capture : <br/>
<iframe width="560" height="315" src="https://www.youtube.com/embed/hiQfffk-Bgg" frameborder="0" allowfullscreen></iframe>
<br/><br/>
All demos can be downloaded from here <a href="https://github.com/gochev/examples/tree/master/SoftUni%20Spring%20MVC%20June%202015" target="_blank">https://github.com/gochev/examples/tree/master/SoftUni%20Spring%20MVC%20June%202015</a> <br/>
If you missed the event .. don't miss the next one. In Bulgarian Java User Group we do events like this one every month. <bt/>
Information about past and future events can be found here <a target="_blank" href="http://java-bg.org/events/">http://java-bg.org/events/</a>
jNaydenhttp://www.blogger.com/profile/04678280364638370213noreply@blogger.com0tag:blogger.com,1999:blog-441421458098194397.post-89142443757060701012015-06-05T14:20:00.002+03:002015-06-18T21:45:32.495+03:00ORM в Java: Hibernate и JPA A talk about Java and ORM I made at Software University in Bulgaria few months ago. It shows Hibernate (old school stuff) and JPA to as ORM. <br />
<br />
The talk is in Bulgarian<br />
<br />
<br />
<iframe width="560" height="315" src="https://www.youtube.com/embed/Y7xCWLLXL5c" frameborder="0" allowfullscreen></iframe>
<br/><br/>
Examples on github can be found here :<br/>
<a href="https://github.com/gochev/examples/tree/master/hibernate-example"> Hibernate example </a> <br/>
<a href="https://github.com/gochev/examples/tree/master/jpa-example"> JPA example </a><br/>jNaydenhttp://www.blogger.com/profile/04678280364638370213noreply@blogger.com0tag:blogger.com,1999:blog-441421458098194397.post-47882537787099573232015-05-12T16:15:00.003+03:002019-01-05T17:19:15.004+02:00What is jHipster at SoftUni Conf, March, 2015This is a small 10min talk that I made about jHipster. JHipster is a yeoman generator that can create a spring boot/jpa application with angular and bootstrap for a minute.<br />
<br />
I am not fan of code generation but .. its something that may help us doing presentations or preparing an example.<br />
<br />
The talk is in Bulgarian again<br />
<br />
<br />
<iframe allowfullscreen="" frameborder="0" height="315" src="https://www.youtube.com/embed/E2a8V-qljWo" width="560"></iframe>jNaydenhttp://www.blogger.com/profile/04678280364638370213noreply@blogger.com0tag:blogger.com,1999:blog-441421458098194397.post-5267634370613558582015-05-12T15:57:00.000+03:002019-01-05T17:19:21.069+02:00RAD with Spring @SoftUni Conf, March, 2015<br />
This is a video of the presentaiton about Rapid Application Development with Spring that I made at SoftUni conf.<br />
<br />
The video is in Bulgarian :( ... again :( <br />
<br />
<br />
<iframe allowfullscreen="" frameborder="0" height="315" src="https://www.youtube.com/embed/AyjAvPBMt9Q" width="560"></iframe>
<br />
Example can be found here : <a href="https://github.com/gochev/examples/tree/master/SoftUni%20Conf%202015%20March/spring-rad"> Example on github </a> jNaydenhttp://www.blogger.com/profile/04678280364638370213noreply@blogger.com0tag:blogger.com,1999:blog-441421458098194397.post-11860112205940205312015-02-12T09:54:00.004+02:002019-01-05T17:19:27.489+02:00Software University : Fast REST API with SpringThis is video from the presentation I did for <a href="http://softuni.bg/">Software University </a> <a href="http://softuni.bg/SoftUniConf">conf</a> at Sofia, Bulgaria.<br />
<iframe allowfullscreen="" frameborder="0" height="315" src="https://www.youtube.com/embed/OW2vbIBsh74" width="560"></iframe>
And here is the presentation (slideshare) only.
<br />
<br />
<iframe frameborder="0" height="400" marginheight="0" marginwidth="0" scrolling="no" src="//www.slideshare.net/slideshow/embed_code/44583300" width="476"></iframe>
All demos can be downloaded from here <a href="https://github.com/gochev/examples/tree/master/SoftUni%20Rest%20Spring" target="_blank">https://github.com/gochev/examples/tree/master/SoftUni%20Rest%20Spring</a> <br />
If you missed the event .. don't miss the next one. In Bulgarian Java User Group we do events like this one every month. <bt>
Information about past and future events can be found here <a href="http://java-bg.org/events/" target="_blank">http://java-bg.org/events/</a>
</bt>jNaydenhttp://www.blogger.com/profile/04678280364638370213noreply@blogger.com0tag:blogger.com,1999:blog-441421458098194397.post-24552371914009233802014-10-13T12:09:00.001+03:002014-10-17T17:07:12.977+03:00Software University Conference Presentation about Java 8This is video from the presentation I did for <a href="http://softuni.bg/">Software University </a> <a href="http://softuni.bg/SoftUniConf">conf</a> at Borovetz, Bulgaria.<br />
<iframe allowfullscreen="" frameborder="0" height="270" src="https://www.youtube.com/embed/9jNII1aT0JE" width="480"></iframe>
And here is the presentation (slideshare) only.
<br />
<br />
<iframe src="//www.slideshare.net/slideshow/embed_code/40189649" width="476" height="400" frameborder="0" marginwidth="0" marginheight="0" scrolling="no"></iframe>
<br />
I recommend to watch the previous video in my post bellow since it has more content (but I speak a bit faster there :) )jNaydenhttp://www.blogger.com/profile/04678280364638370213noreply@blogger.com0tag:blogger.com,1999:blog-441421458098194397.post-7861101147166674382014-07-18T20:24:00.005+03:002014-07-24T10:33:52.686+03:00My Presentation about "Beyond new things in Java" which I held at javaday.bg event.My Presentation about "Beyond new things in Java" which I held at javaday.bg event, organized by trader.bg.<br />
<br />
(IN BULGARIAN)
<iframe width="560" height="315" src="//www.youtube.com/embed/TwoYWFXxEiI" frameborder="0" allowfullscreen></iframe>
<br/><br/><br/>
And this is the presentation only:<br />
<br />
<br />
<iframe allowfullscreen="" frameborder="0" height="356" marginheight="0" marginwidth="0" scrolling="no" src="//www.slideshare.net/slideshow/embed_code/35885566" style="border-width: 1px 1px 0; border: 1px solid #CCC; margin-bottom: 5px; max-width: 100%;" width="427"> </iframe><br />
<div style="margin-bottom: 5px;">
<strong> <a href="https://www.slideshare.net/NaydenGochev/java-day2014-3" target="_blank" title="Lecture from javaday.bg by Nayden Gochev">Lecture from javaday.bg by Nayden Gochev</a> </strong> from <strong><a href="http://www.slideshare.net/NaydenGochev" target="_blank">Nayden Gochev</a></strong> </div>jNaydenhttp://www.blogger.com/profile/04678280364638370213noreply@blogger.com1tag:blogger.com,1999:blog-441421458098194397.post-53213654907023758972014-07-18T11:01:00.001+03:002014-07-18T11:07:02.616+03:00Patching a Maven library with your custom class.Sometimes you use a library that has a bug. Or maybe it doesn’t has a bug but you want to change something. Of course if it is an open source you can get the sources… build them … with your change and so on. However this first takes a lot of time and second you need the sources.<br />
What you usually want .. is to just replace one class.. or few classes with something custom… maybe add a line .. or remove a line and so on. <br />
Yesterday… I had an issue with jboss-logging. The version I was using was 3.2.0Beta1 and it turns out that using this version and log4j2 2.0 final basically meant that no log is send to log4j2. The reason was a null pointer exception that was catched in jboss logging class called Log4j2Logger. The bug I submitted is here <a href="https://issues.jboss.org/browse/JBLOGGING-107" title="https://issues.jboss.org/browse/JBLOGGING-107">https://issues.jboss.org/browse/JBLOGGING-107</a> and it was fixed at the same day. However I will use it as an example since I didn’t knew when this will be fixed.. and I didn’t want to wait till it is fixed.<br />
So I was thinking what I want.. to take the jboss-logging jar and replace the file called Log4j2Logger. Basically as you can see in the bug I wanted to replace line 54 to be :<br />
instead of :<br />
<blockquote>
<pre>this.logger.log(null, loggerClassName, translatedLevel,
parameters == null || parameters.length == 0 ? this.messageFactory.newMessage(message) :
this.messageFactory.newMessage(String.valueOf(message), parameters),
thrown);</pre>
</blockquote>
to become :<br />
<blockquote>
<span style="font-family: Courier New;">this.logger.log(translatedLevel, parameters == null || parameters.length == 0 ? this.messageFactory.newMessage(message) : this.messageFactory.newMessage(String.valueOf(message), parameters),</span></blockquote>
<br />
And that’s it. Of course I didn’t wanted to do this manually with zip <img alt="Усмивка" class="wlEmoticon wlEmoticon-smile" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhCdCrYcRMR9pSusCM4abcqrW0iLKjP4cF76cdvq20Oj2hw1MOqyj3QHYnxsoDBSwK3UzT0QmLe5eNnMzFmMvnQ8_xXDhBUuz8Nf-KEr-TtRlRJD8DxXPgEYfhn-5C6Wun2ZuwxLlsDrcI/?imgmax=800" style="border-bottom-style: none; border-left-style: none; border-right-style: none; border-top-style: none;" /> but to use maven as well.<br />
<br />
So what I did:<br />
<br />
1) I created a new maven project and added as dependency the jboss-logging.<br />
2) I set the new project groupid and artifactid as the ones in the dependancy.<br />
I set the version to be something like “3.2.0.Beta1-log4j2-npe-fix” so I added –log4j2-npe-fix<br />
3) I used a plugin that takes the original version, unpacks the original jar in target WITHOUT the class I want to patch in this case Log4j2Logger.class and added my own implementation in the sources of my project.<br />
4) And well thats all... ones I build.. my patched class will go in target.. and the original classes except the class I want to patch will also go in target and voala.. I will have a library which is patched.<br />
The full pom.xml looks like this:<br />
<br />
<?xml version="1.0" encoding="UTF-8"?><br /><project xmlns="<a href="http://maven.apache.org/POM/4.0.0%22">http://maven.apache.org/POM/4.0.0"</a><br /> xmlns:xsi="<a href="http://www.w3.org/2001/XMLSchema-instance%22">http://www.w3.org/2001/XMLSchema-instance"</a><br /> xsi:schemaLocation="<a href="http://maven.apache.org/POM/4.0.0">http://maven.apache.org/POM/4.0.0</a> <a href="http://maven.apache.org/xsd/maven-4.0.0.xsd%22">http://maven.apache.org/xsd/maven-4.0.0.xsd"</a>><br /> <modelVersion>4.0.0</modelVersion><br />
<br />
<groupId>org.jboss.logging</groupId><br /> <artifactId>jboss-logging</artifactId><br /> <version>3.2.0.Beta1-log4j2-npe-fix</version><br /> <dependencies><br /> <dependency><br /> <groupId>org.jboss.logging</groupId><br /> <artifactId>jboss-logging</artifactId><br /> <version>3.2.0.Beta1</version><br /> <type>jar</type><br /> </dependency><br /> </dependencies><br /> <build><br /> <plugins><br /> <plugin><br /> <groupId>org.apache.maven.plugins</groupId><br /> <artifactId>maven-dependency-plugin</artifactId><br /> <executions><br /> <execution><br /> <id>unpack</id><br /> <phase>generate-sources</phase><br /> <goals><br /> <goal>unpack</goal><br /> </goals><br /> <configuration><br /> <artifactItems><br /> <artifactItem><br /> <groupId>org.jboss.logging</groupId><br /> <artifactId>jboss-logging</artifactId><br /> <version>3.2.0.Beta1</version><br /> <type>jar</type><br /> <overWrite>true</overWrite><br /> <outputDirectory>${project.build.directory}/classes</outputDirectory><br /> <excludes><br /> **/Log4j2Logger.class<br /> </excludes><br /> </artifactItem><br /> </artifactItems><br /> </configuration><br /> </execution><br /> </executions><br /> </plugin><br /> </plugins><br /> </build><br /></project><br />
<pre> </pre>
<br />
and that’s it.. the only thing left is to update my project to use my version 3.2.0.Beta1-log4j2-npe-fix instead of the original 3.2.0.Beta1.<br />
<br />
<br />
<br />
I hope this will help to someone to save time.<br />
<pre> </pre>
<pre> </pre>
jNaydenhttp://www.blogger.com/profile/04678280364638370213noreply@blogger.com0tag:blogger.com,1999:blog-441421458098194397.post-52451178982129817632014-04-22T21:37:00.001+03:002019-01-05T17:19:37.469+02:00spring-loaded rocks !Today I found spring loaded (<a href="https://github.com/spring-projects/spring-loaded" title="https://github.com/spring-projects/spring-loaded">https://github.com/spring-projects/spring-loaded</a>)<br />
in short this is a java agent that enables class reloading of already running VM.<br />
Simply this means zero deployment time (in many cases). <br />
It is like a free and open source alternative of JRebel. <br />
Spring Loaded allows you to add/modify/delete methods/fields/constructors. The annotations on types/methods/fields/constructors can also be modified and it is possible to add/remove/change values in enum types.<br />
There is a preliminary java8 support. There is also another project DCEVM ( which is also great but supports only till JRE 6 update 26). More info here <a href="http://ssw.jku.at/dcevm/" title="http://ssw.jku.at/dcevm/">http://ssw.jku.at/dcevm/</a><br />
But lets stop speaking and show you how it works.<br />
In short you just need to pass the agent when starting the vm and that’s it.<br />
>java -javaagent:D:/Downloads/springloaded-1.2.0.BUILD-20140409.201438-12.jar -noverify org.gochev.MainClass<br />
I am using this Build since I am running Java 8 and this is currently the latest .<br />
The code I in my simple app is the following:<br />
A POJO like this :<br />
<pre><span style="color: red;"><b>package</b></span> org<span style="color: blue;"><b>.</b></span>gochev<span style="color: blue;"><b>;</b></span>
<span style="color: red;"><b>public</b></span> <span style="color: red;"><b>class</b></span> DynamicReloadedClass <span style="color: blue;"><b>{</b></span>
<span style="color: red;"><b>private</b></span> <span style="color: red;"><b>int</b></span> age <span style="color: blue;">=</span> <span style="color: brown;">30</span><span style="color: blue;"><b>;</b></span>
<span style="color: red;"><b>public</b></span> <span style="color: red;"><b>int</b></span> getAge<span style="color: blue;"><b>(</b></span><span style="color: blue;"><b>)</b></span> <span style="color: blue;"><b>{</b></span>
<span style="color: red;"><b>return</b></span> age<span style="color: blue;"><b>;</b></span>
<span style="color: blue;"><b>}</b></span>
<span style="color: red;"><b>public</b></span> <span style="color: red;"><b>void</b></span> setAge<span style="color: blue;"><b>(</b></span><span style="color: red;"><b>int</b></span> age<span style="color: blue;"><b>)</b></span> <span style="color: blue;"><b>{</b></span>
<span style="color: red;"><b>this</b></span><span style="color: blue;"><b>.</b></span>age <span style="color: blue;">=</span> age<span style="color: blue;"><b>;</b></span>
<span style="color: blue;"><b>}</b></span>
<span style="color: blue;"><b>}</b></span></pre>
<br />
<br />
<br /> <br />and a MainClass like this:<br />
<br />
<br />
<pre><span style="color: red;"><b>package</b></span> org<span style="color: blue;"><b>.</b></span>gochev<span style="color: blue;"><b>;</b></span>
<span style="color: red;"><b>import</b></span> java<span style="color: blue;"><b>.</b></span>util<span style="color: blue;"><b>.</b></span>Scanner<span style="color: blue;"><b>;</b></span>
<span style="color: red;"><b>public</b></span> <span style="color: red;"><b>class</b></span> MainClass <span style="color: blue;"><b>{</b></span>
<span style="color: red;"><b>public</b></span> <span style="color: red;"><b>static</b></span> <span style="color: red;"><b>void</b></span> main<span style="color: blue;"><b>(</b></span>String<span style="color: blue;"><b>[</b></span><span style="color: blue;"><b>]</b></span> args<span style="color: blue;"><b>)</b></span> <span style="color: blue;"><b>{</b></span>
<span style="color: red;"><b>try</b></span> <span style="color: blue;"><b>(</b></span>Scanner scanner <span style="color: blue;">=</span> <span style="color: red;"><b>new</b></span> Scanner<span style="color: blue;"><b>(</b></span>System<span style="color: blue;"><b>.</b></span>in<span style="color: blue;"><b>)</b></span><span style="color: blue;"><b>)</b></span> <span style="color: blue;"><b>{</b></span>
<span style="color: red;"><b>while</b></span> <span style="color: blue;"><b>(</b></span>true<span style="color: blue;"><b>)</b></span> <span style="color: blue;"><b>{</b></span>
System<span style="color: blue;"><b>.</b></span>out<span style="color: blue;"><b>.</b></span>println<span style="color: blue;"><b>(</b></span><span style="color: purple;">"test "</span>
<span style="color: blue;">+</span> <span style="color: red;"><b>new</b></span> DynamicReloadedClass<span style="color: blue;"><b>(</b></span><span style="color: blue;"><b>)</b></span><span style="color: blue;"><b>.</b></span>getAge<span style="color: blue;"><b>(</b></span><span style="color: blue;"><b>)</b></span><span style="color: blue;"><b>)</b></span><span style="color: blue;"><b>;</b></span>
scanner<span style="color: blue;"><b>.</b></span>next<span style="color: blue;"><b>(</b></span><span style="color: blue;"><b>)</b></span><span style="color: blue;"><b>;</b></span>
<span style="color: blue;"><b>}</b></span>
<span style="color: blue;"><b>}</b></span>
<span style="color: blue;"><b>}</b></span>
<span style="color: blue;"><b>}</b></span></pre>
<br />
<br />
So I can change the DynamicReloadedClass while the main method in the MainClass is looping. You can see this in action here :<br />
<br />
<br />
<a href="http://www.screencast.com/t/KIFIxv7j" title="http://www.screencast.com/t/KIFIxv7j">http://www.screencast.com/t/KIFIxv7j</a><br />
<br />
<br />
Awesome ... and free ! jNaydenhttp://www.blogger.com/profile/04678280364638370213noreply@blogger.com1tag:blogger.com,1999:blog-441421458098194397.post-72174212504987523242013-06-26T13:52:00.001+03:002019-01-05T17:21:03.010+02:00Google Reader alternatives ?None .. no really there is NO Google reader alternatives simply because Google reader is THE BEST.<br />
However since google reader will be shut down in few days and we don’t have a choice and we have to switch somewhere. So what are the alternatives one day before the google shutdown ?<br />
<h3>
1) Feedly : <a href="http://cloud.feedly.com/#latest">http://cloud.feedly.com/#latest</a></h3>
I hate it .. no really it is HELL of a BUGGY .. it doesn’t mark my blog posts as read.. it requires some crappy plugins that will fetch the articles in the background otherwise it is not working, the android app is peace of buggy shit with some promotional popular craps and no real full article view for tablets. It is amazingly bad.. it looks shiny but it is shit, it requires login on all your machines each time when you make changes between the machine (work, home, phone). It is unusable even when it looks good :<br />
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg6b3aiaLGWrKfKUH0pGs5HPfmodRzZqavUpyT40Gig5YtbNadrC-zQAP08FAn7ak23GUbVa7jbWU7oTxcIWBMWuwDmxoUyShImy7Q6orW6zEzRIuCTJ_njotQ5NYFE-USNvgF40qELBbo/s1600-h/feedly%25255B4%25255D.png"><img alt="feedly" border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjd7HaOLTIHcrwjGlsZ7p_Ef3aVLhyphenhyphen6gOpMQR-woH0vFax8w8sM8xZRwNHOoORpRv1bkSsjJkfPniRvW7Q7ka9FJyiTDC-frejqM9_wDcOPImXq55UMt9Ib6sNt0aX-4xSosK4_HrLIJ6M/?imgmax=800" height="345" style="background-image: none; border-bottom-width: 0px; border-left-width: 0px; border-right-width: 0px; border-top-width: 0px; display: inline; padding-left: 0px; padding-right: 0px; padding-top: 0px;" title="feedly" width="580" /></a><br />
It looks good but it is not an alternative.. no my friends its peace of crap that just wants to steal some google reader users.<br />
<h3>
2) AOL reader : <a href="http://reader.aol.com/">http://reader.aol.com/</a> currently in closed beta.</h3>
It is not bad actually it looks good it works good (when it works) however it is not working like 30% of the time still it may become a good alternative ones it is done but it wont be done tomorrow so .. nope it doesn’t work for me.<br />
It looks like that :<br />
<img src="http://cdn.imore.com/sites/imore.com/files/styles/large/public/field/image/2013/06/aol_reader_screenshot_imore.png?itok=eMDVzwVv" /><br />
<br />
<h3>
3) Digg Reader : <a href="http://digg.com/reader">http://digg.com/reader</a> currently in closed beta.</h3>
Good idea however it is hell of a buggy doesn’t looks and works very well and maybe some day it will be okei as AOL reader but this day is not today.<br />
It looks like that:<br />
<img src="http://img.gawkerassets.com/img/18rt9ekuxffb3png/ku-xlarge.png" /><br />
<h3>
4) NewsBlur, Pulse, Flipboard, NetVibes, Zite are basicaly RSS readers but <u>not</u> a Google reader alternatives. </h3>
You can read about all of them here <a href="http://gizmodo.com/10-google-reader-alternatives-that-will-ease-your-rss-p-5990540">http://gizmodo.com/10-google-reader-alternatives-that-will-ease-your-rss-p-5990540</a> however I don’t like them at all they look bad and they are useless for a lot of news. Sometimes I have 1500 news per day that I want to scroll as fast as possible and read only the 50 of them which are really liked so this readers to me and I guess for many of you as well cuz this readers simply doesn’t do the job.<br />
So what can we do ? what is left ? yes what is left is the REAL alternative. The real alternative is called<br />
<h3>
5) Old Reader : <a href="http://theoldreader.com/">http://theoldreader.com/</a> works and looks like a boss !</h3>
First of all no complains about how it works, it marks everything right on time I don’t have to cilck some crappy button “Mark all my articles as read” like in feebly otherwise 50% of your already checked articles are unread … also Feedly doesn’t show you all unreaded articles it is peace of shit anyway Old Reader is awesome and it is not just created a month ago by 3 random php guys who are trying to type something that can read XML file and show html instead it is old product which already have users, which is already stable and proven and it doesn’t require some weird browser extensions. The social plugins are missing indeed share on facebook or on google+ however there are bookmarklets for this I was always wonder before how you can share something before you actually read it just watching the headlines ? it is just strange… Anyway by default the reader looks like this (after last UI changes that the old reader team made) :<br />
<img src="http://img.gawkerassets.com/img/18hgxl6qchafsjpg/ku-xlarge.jpg" /><br />
I know what you will say : it looks bad.. Indeed I don’t like how it looks as well.. what I did in order to LOVE this reader is well I installed Stylish extension ( I already had it ). Stylish extension gives you a way to apply any css to any website that you visit.. for example you have something in Facebook you don’t wanna see then add a selector and hide it.. so for the old reader there are tons of css styles reader UI is made very nicely and all the css classes are nicely called everything is very easy for customization here is my try if someone want to use it : <a href="https://skydrive.live.com/redir.aspx?cid=3917982854a57d45&page=self&resid=3917982854A57D45!176&parid=3917982854A57D45!102&authkey=!&Bpub=SDX.SkyDrive&Bsrc=Share" title="https://skydrive.live.com/redir.aspx?cid=3917982854a57d45&page=self&resid=3917982854A57D45!176&parid=3917982854A57D45!102&authkey=!&Bpub=SDX.SkyDrive&Bsrc=Share">https://skydrive.live.com/redir.aspx?cid=3917982854a57d45&page=self&resid=3917982854A57D45!176&parid=3917982854A57D45!102&authkey=!&Bpub=SDX.SkyDrive&Bsrc=Share</a><br />
Just add this style in Stylish add the URL starting with <a href="http://theoldreader.com/">http://theoldreader.com/</a> and voala:<br />
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhlO7CJcXwN1cqXgBVXq0PAt6AI5Lq3RCvWNvbnO3Xl3m38gWGcnClCwRYpWHnEhEAYb6-wo4yEh773lcvMUqHg0SWKt4siQrVhbXZQxsdDRFUzk2p7Jqw7gMsmtliizVse8ZPtvQCyNMQ/s1600-h/oldreader%25255B3%25255D.png"><img alt="oldreader" border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj73Z2vWsQVVWchEQSUCNMt5Otw8AGSkq4a7bCimE4YQ6KqB5p0hKgwhF5FrC3I8HNufaPSWPuV7ZUjrCZcA6-Y5_CbCdCXkBQ-sKAZBaf0gKJmBGq97Cy8JjNF2D3a2u_lfKQIiQh2Vps/?imgmax=800" height="258" style="background-image: none; border-bottom-width: 0px; border-left-width: 0px; border-right-width: 0px; border-top-width: 0px; display: inline; padding-left: 0px; padding-right: 0px; padding-top: 0px;" title="oldreader" width="580" /></a><br />
<br />
Well that’s it guys – THE OLD READER the <u>ONLY</u> Google reader alternative on 26.06.2013.jNaydenhttp://www.blogger.com/profile/04678280364638370213noreply@blogger.com0tag:blogger.com,1999:blog-441421458098194397.post-53726434298597171892011-07-21T17:12:00.005+03:002013-02-03T21:23:36.633+02:00Семинар: Новости в Java платформата.<p> </p> <p>Анонса е леко нахално взаимстван от блога на Наков(<a title="http://www.nakov.com/blog/2011/07/21/seminar-java-7-java-ee-6-bgjug-27-july-2011/" href="http://www.nakov.com/blog/2011/07/21/seminar-java-7-java-ee-6-bgjug-27-july-2011/">http://www.nakov.com/blog/2011/07/21/seminar-java-7-java-ee-6-bgjug-27-july-2011/</a>) поради мързел от моя страна да го напиша. Общо взето промените са replace на Найден Гочев с Аз.</p> <p> </p> <p>Имам прекрасна новина за всички Java фенове. След като Java 7 официално излезе, дойде ред и на Българскота общност от Java разработчици да се присъедини към поредицата “Java 7 Launch” събития. Благодарение на много хора :+) ще си направим семинарче и парти по случай Java 7 и новостите от Java света, които идват заедно с нея. <br /><strong></strong></p> <h2>Програма на семинара</h2> <p>    Kакво ново в Java 7? <br />    Kакво ново в Java EE 6? <br />    Kакво ново в JavaFX 2.0? <br />    Kакво ново в JavaME?</p> <p>Лекциите са част от официалния “Oracle Java 7 Launch Kit”, който е предоставен от Oracle за Българската Java потребителска група (BGJUG) заедно с тениски и други рекламни материали. <br /><strong></strong></p> <h2>Кога и къде?</h2> <p>Семинарът “Новости от Java платформата” ще се проведе на 27 юли (сряда) от 19:00 часа в учебната зала на Академията на Телерик за софтуерни инженери. Адресът е: <a href="http://maps.google.bg/maps?f=q&source=s_q&hl=bg&geocode=&q=42.650550,+23.379362&aq=&sll=42.650493,23.379166&sspn=0.001353,0.00284&ie=UTF8&t=h&z=16">София, Младост-1, бул. Александър Малинов 33, партер</a>. <br /></p> <h2>Лектор</h2> <p>Лектор ще бъда аз.</p> <h2>Благодарности</h2> <p>Благодарностите за организирането на семинара са за:</p> <p>    BGJUG – организатор на събитието <br />    Oracle Corp. които предоставиха Java 7 Launch Kit, тениски и рекламни материали за BGJUG <br />    Петър Тахчиев, който поръча тениските и launch kit-a.    <br />    Академия на Телерик – домакин на събитието <br />    Светлин Наков, който помогна с намирането на домакин ;) </p>
<br />
jNaydenhttp://www.blogger.com/profile/04678280364638370213noreply@blogger.com0tag:blogger.com,1999:blog-441421458098194397.post-62453576080967144452011-07-05T16:47:00.005+03:002011-07-05T17:05:38.855+03:00JavaScript inheritance (object-oriented programming)<p> </p> <p>There are many posts explaining what JavaScript inheritance is how it works, is it bad or good, how it is comparable with Java inheritance with millions of examples using third party apis or function to make inheritance look more like C#/C++/Java Inheritance.</p> <p>This post is just to show HOW inheritance looks without anything else except browser so next time when you need to find it you can open this post which explains everything you need.</p> <p>JavaScript uses so called prototype inheritance you don’t need to know more except it is different then a C#/C++/Java way of doing inheritance</p> <h1>Define a class</h1> <p>In JavaScript you can define class like this:</p> <p>function A(){ <br />    this.aMethod = function (){ <br />        alert("A method"); <br />    } <br />    this.bMethod = function () { <br />        alert( "B Method"); <br />    } <br />}</p> <p>Yes, yes there are different ways I find this one the most easy one  you can read more about the ways how to create a class in JavaScript here : <a title="http://www.phpied.com/3-ways-to-define-a-javascript-class/" href="http://www.phpied.com/3-ways-to-define-a-javascript-class/">http://www.phpied.com/3-ways-to-define-a-javascript-class/</a></p> <p>Next you have a class how can you use it ?</p> <p>var a = new A(); <br />a.bMethod(); //will print B method <br />a.aMethod(); //will print A method</p> <p>BAM nothing else, easy right?</p> <p>ok so what if you want to extend this class ? </p> <h1>Prototype Inheritance </h1> <p>First you will create another class:</p> <p>function B(){ <br />    this.cMethod = function () { <br />        alert("C method"); <br />    } <br />}</p> <p>ok but how can I say that B extends A ? Simple : B.prototype = new A();</p> <blockquote></blockquote> <p>Example :</p> <p>B.prototype = new A();</p> <p>var b = new B(); <br />b.aMethod(); //will print A method <br />b.bMethod(); //will print B method <br />b.cMethod(); //will print C method</p> <p>Overriding is fine too.</p> <p>function B(){ <br />    this.bMethod = function() { <br />        alert("overriding"); <br />    } <br />    this.cMethod = function () { <br />        alert("C method"); <br />    } <br />}</p> <p>And use it as before ( keep in mind the .prototype = new A is required only ones)</p> <p>B.prototype = new A();</p> <p>var b = new B(); <br />b.aMethod(); //will print A method <br />b.bMethod(); //will print overriding <br />b.cMethod();// will print C method</p> <h3>Full example:</h3> <p> <br />function A(){ <br />    this.aMethod = function (){ <br />        alert("A method"); <br />    } <br />    this.bMethod = function () { <br />        alert( "B Method"); <br />    } <br />}</p> <p>function B(){ <br />    this.bMethod = function() { <br />        alert("overriding"); <br />    } <br />    this.cMethod = function () { <br />        alert("C method"); <br />    } <br />}</p> <p>B.prototype = new A();</p> <p>var b = new B(); <br />b.aMethod(); //will print A method <br />b.bMethod(); //will print overriding <br />b.cMethod(); //will print C Method <br /></p> <h1> </h1> <h1>Inheritance through Functions</h1> <p>If you don’t like prototypes for some reason you can use a inheritance through functions.</p> <p>Example:</p> <p>you just need when you define a class B (the subType) to call this.someFunctionName = supertype and then invoke this.someFunctionName(). Example this.extends = A; this.extends();</p> <h3>Full Example:</h3> <p> <br />function A(){ <br />    this.aMethod = function (){ <br />        alert("A method"); <br />    } <br />    this.bMethod = function () { <br />        alert( "B Method"); <br />    } <br />}</p> <p>function B(){ <br />    this.extends = A; <br />    this.extends(); <br />    <br />    this.bMethod = function() { <br />        alert("overriding"); <br />    } <br />    this.cMethod = function () { <br />        alert("C method"); <br />    } <br />}</p> <p>var b = new B(); <br />b.aMethod(); //will print A method <br />b.bMethod(); //will print overriding <br />b.cMethod(); //will print C method</p><br /><br /><h4>UPDATE: Under Internet Explorer if you want to use inheritance through Functions the FUNCTION name that you have to use SHOULD NOT BE "extends" the above example with extends will not work because IE don't like extends :), use some other name like "inheritFrom" for example</h4>jNaydenhttp://www.blogger.com/profile/04678280364638370213noreply@blogger.com0tag:blogger.com,1999:blog-441421458098194397.post-77037501817033502342011-05-19T12:19:00.001+03:002019-01-05T17:21:43.891+02:00[LINUX] How to find a specific String in file content with specific file name in specific folder<br />
This is really the dumbest thing ever in linux, there are many many dumb things but this is the dumbest. Ultra trivial task you want to “find a specific string in a file content of specific file type starting from root folder” this is the easiest thing ever, it was not available in Windows XP/98 and because of that I was keeping one JBuilder which can search normally in any java file containing XXX in starting from this folder. But in Windows Vista / 7 this is done EASY just press F3! In Linux on the other hand it is a NIGHTMARE I was having a trivial task which takes… 10 seconds to search for a properties file which contains a default.session.timeout=600 which is a row in this file and this took me more then 30 mins because there are TONS of posts how this is done but none have worked there ware examples using grep, egrep whatever NOTHING is working total CRAP really. So in short I found it somewhere and I want to post it in order to have another POST in google which gives the answers. <br />
So In short:<br />
How to search for a file content in linux in specific file names starting from specific root folder.<br />
find . -name "*.properties" -print | xargs grep default.session.timeout=600<br />
Which will give you all properties files which contains default.session.timeout=600 it doesn’t have to be the match the whole row you can search for just default.session which will give you all files which contains default.session. This command is typed in the folder that you want to start the search from for example /opt/hybris/jNaydenhttp://www.blogger.com/profile/04678280364638370213noreply@blogger.com1tag:blogger.com,1999:blog-441421458098194397.post-75511577154041631322011-03-11T12:08:00.003+02:002011-03-11T12:15:49.008+02:00Generate JavaDoc with UML diagrams<p>In my life many times has happened when I am assigned to a totally new project that I have no idea what it is about, that has to go live in 2 weeks and that I have to fix some issues in this ultra strange code sometimes even code written in different language.</p> <p>On my question is there any documentation the answer is: Yes but it is very old or no. So in short they want me to start working on a project with no documentation at all.</p> <p>My second question is is there a javadoc and the anwer is : yeah … kind of … so I am in a project with 30% javadoc with methods in French language for example ( I don’t know even a single word in French) so in short I am loosing 2 weeks to understand what is using what what is the model what is PersonnePhysique  and what is this crazy domain model. </p> <p>I believe this has happened with everyone of you at least once so what can you do ?</p> <ul> <li>You can start digging into the java code like crazy ( like everyone of us have tried many times)</li> <li>You can install intellij idea and use the great reverse engineering way to create UML diagrams for specific classes but intelliJ idea costs money.</li> <li>You can install netbeans 6.5 and do the same but you have to use this out dated version of NetBeans because this doesn’t exist in newer versions, thanks Oracle.</li> <li>You can install Eclipse + MoDisco + MDT + KML to generate xmisomething file then to generate xml file with KML thingy then to use UML2 tools to view this diagram blah.</li> <li>Or you can find some other way… this is the other way which I believe is very nice and useful and you should use it in every project that you can actually this should be the first thing that the architect should put in the project.</li> </ul> <p>So in short the other way is to generate a UML diagrams each time when a javadoc is generated it will generate a UML diagrams for each class and package which contains whatever you want operations,attributes,constructors just names you can click on them and navigate using them it is AWESOME.</p> <p>How this will look like ? like this:</p> <p><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi_fPzBppvmJNdRHQ5hkV52u_-1w0IWOJ6DZwc8q-rS3i4oqqCrCkf-nbXWxnpRyUc8kB3pLiavn7kza5Vud336JMnKNFjcwjaQOd0NCw_aU95uBAcm7mo5WsxlQHLOEm7SFmCbQL9DyG8/s1600-h/uml1%5B5%5D.png"><img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="uml1" border="0" alt="uml1" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjCsINW7pm1pOxAnGdRjZMmj_KET0E-rjn4SR75_841VEewAi0_MuU4LmRBvooi38CBgIQl5-QuedCl5qSuBoxFZqD9rI1YKX0dmyyp0g4Q4WsKNlktN9J-wnZiM2wjDsQWuE2Y0-ZCZUQ/?imgmax=800" width="557" height="391" /></a></p> <p>And you can click on items for example on Category which will forward you to the Category javadoc which has a diagram as well which looks like this :</p> <p><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh3_01L8KWWEZ5wC2oaw6C7aDqJhcvYeA6Z2gRuVCz2tdUfCE1TPUfyKXPCOsWv-CTb0lySKxtlDd0jkIrfYyVMx_X9RbpXdtcW7GuZMbQd9efA_HHAKJa-aLzOn3V5JPLBmUr0rt46fDQ/s1600-h/UML2%5B3%5D.png"><img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="UML2" border="0" alt="UML2" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgD9tq_p1F12ot2h5vyEcs5pqUmY-lxjSqEaSPcvFVMr-t1eGr3SNq9X8V3A4y5B_F7i7IDoTYGUZwabSvZOdL-LVYHmUUxJdPEs41aPJW_a2ire21AhRswjPR4oDQ0W8ETmp7XHQqPGuA/?imgmax=800" width="565" height="327" /></a></p> <p>Awesome right ?</p> <p>How you can do it ? In my example I will use maven so what you have to do :</p> <p>use of UmlGraph</p> <p>use of Graphviz</p> <p>change of maven pom.xml update (for ant integration check the last link in the blog post)</p> <p>1) install graphviz on the machine that will generate the javadoc .. usually this is a linux machine which runs hudson or whatever so in case of ubuntu you just need apt-get install graphviz4 otherwise you can download the msi/deb/rpg/source from here <a title="http://www.graphviz.org/Download..php" href="http://www.graphviz.org/Download..php">http://www.graphviz.org/Download..php</a> then just type “dot –-help” in console to check that the dot executable is in your path.</p> <p>2) update your pom.xml adding UmlGraph just add:</p> <p><plugin> <br />                <artifactId>maven-javadoc-plugin</artifactId> <br />                <version>2.7</version> <br />                <configuration> <br />                    <aggregate>true</aggregate> <br />                    <show>private</show> <br />                    <doclet>org.umlgraph.doclet.UmlGraphDoc</doclet> <br />                    <docletArtifact> <br />                        <groupId>org.umlgraph</groupId> <br />                        <artifactId>doclet</artifactId> <br />                        <version>5.1</version> <br />                    </docletArtifact> <br />                    <additionalparam> <br />                        -inferrel -attributes -types -visibility -inferdep -quiet -hide java.* -collpackages java.util.* -qualify -postfixpackage <br />                        -nodefontsize 9 <br />                        -nodefontpackagesize 7 <br />                            </additionalparam> <br />                </configuration> <br />            </plugin></p> <p>3) invoke mvn javadoc:javadoc … and you are done. :+) easy right ? You can see explanation about all umlgraph options here <a title="http://www.umlgraph.org/doc/indexw.html" href="http://www.umlgraph.org/doc/indexw.html">http://www.umlgraph.org/doc/indexw.html</a> like do you don’t want to see the attributes, but you want the operations and etc..</p> <p>Example with operations will look like this:</p> <p><img src="http://java.dzone.com/sites/all/files/images/uml-diagram.jpg" /></p> <p> </p> <p>For ant integration check <a title="http://java.dzone.com/articles/reverse-engineer-source-code-u" href="http://java.dzone.com/articles/reverse-engineer-source-code-u">http://java.dzone.com/articles/reverse-engineer-source-code-u</a></p>jNaydenhttp://www.blogger.com/profile/04678280364638370213noreply@blogger.com2tag:blogger.com,1999:blog-441421458098194397.post-9855450821187987322010-07-27T16:07:00.001+03:002010-07-27T16:07:17.571+03:00Using of Collections.emptyList() the right way in Java 1.5+<meta content="text/html; charset=windows-1251" http-equiv="Content-Type" /><meta name="Generator" content="Microsoft Word 12 (filtered)" /><style><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><!--<br /> /* Font Definitions */<br /> @font-face<br /> {font-family:"Cambria Math";<br /> panose-1:2 4 5 3 5 4 6 3 2 4;}<br />@font-face<br /> {font-family:calibri;<br /> panose-1:2 15 5 2 2 2 4 3 2 4;}<br />@font-face<br /> {font-family:consolas;<br /> panose-1:2 11 6 9 2 2 4 3 2 4;}<br /> /* Style Definitions */<br /> p.msonormal, li.msonormal, div.msonormal<br /> {margin-top:0cm;<br /> margin-right:0cm;<br /> margin-bottom:10.0pt;<br /> margin-left:0cm;<br /> line-height:115%;<br /> font-size:11.0pt;<br /> font-family:"Calibri","sans-serif";}<br />.msopapdefault<br /> {margin-bottom:10.0pt;<br /> line-height:115%;}<br />@page section1<br /> {size:612.0pt 792.0pt;<br /> margin:70.85pt 70.85pt 70.85pt 70.85pt;}<br />div.section1<br /> {page:section1;}<br />--></style> <div class="Section1"> <p style="line-height: normal; margin-bottom: 0pt" class="MsoNormal"><b><span style="font-family: consolas; color: #7f0055" lang="EN-US"></span></b></p> <p>It is little strange that no one really uses emptyList like he should in Java. <br />So this is small post showing how to use the emptyList method in the Collections class. </p> <p>Question: How to create an empty list ? <br />lets assume that we have a class Book with multiple titles. <br />So the class in our examples will be:</p> <p style="line-height: normal; margin-bottom: 0pt" class="MsoNormal"><b><span style="font-family: consolas; color: #7f0055" lang="EN-US">import</span></b><span style="font-family: consolas; color: black" lang="EN-US"> java.util.List;</span></p> <p style="line-height: normal; margin-bottom: 0pt" class="MsoNormal"><span style="font-family: consolas" lang="EN-US"></span></p> <p style="line-height: normal; margin-bottom: 0pt" class="MsoNormal"><b><span style="font-family: consolas; color: #7f0055" lang="EN-US">public</span></b><span style="font-family: consolas; color: black" lang="EN-US"> </span><b><span style="font-family: consolas; color: #7f0055" lang="EN-US">class</span></b><span style="font-family: consolas; color: black" lang="EN-US"> Book {</span></p> <p style="line-height: normal; margin-bottom: 0pt" class="MsoNormal"><span style="font-family: consolas; color: black" lang="EN-US">      </span><b><span style="font-family: consolas; color: #7f0055" lang="EN-US">private</span></b><span style="font-family: consolas; color: black" lang="EN-US"> List<String> </span><span style="font-family: consolas; color: #0000c0" lang="EN-US">titles</span><span style="font-family: consolas; color: black" lang="EN-US">;</span></p> <p style="line-height: normal; margin-bottom: 0pt" class="MsoNormal"><span style="font-family: consolas" lang="EN-US"></span></p> <p style="line-height: normal; margin-bottom: 0pt" class="MsoNormal"><span style="font-family: consolas; color: black" lang="EN-US">      </span><b><span style="font-family: consolas; color: #7f0055" lang="EN-US">public</span></b><span style="font-family: consolas; color: black" lang="EN-US"> </span><b><span style="font-family: consolas; color: #7f0055" lang="EN-US">void</span></b><span style="font-family: consolas; color: black" lang="EN-US"> setTitles(List<String> titles) {</span></p> <p style="line-height: normal; margin-bottom: 0pt" class="MsoNormal"><span style="font-family: consolas; color: black" lang="EN-US">            </span><b><span style="font-family: consolas; color: #7f0055" lang="EN-US">this</span></b><span style="font-family: consolas; color: black" lang="EN-US">.</span><span style="font-family: consolas; color: #0000c0" lang="EN-US">titles</span><span style="font-family: consolas; color: black" lang="EN-US"> = titles;</span></p> <p style="line-height: normal; margin-bottom: 0pt" class="MsoNormal"><span style="font-family: consolas; color: black" lang="EN-US">      }</span></p> <p style="line-height: normal; margin-bottom: 0pt" class="MsoNormal"><span style="font-family: consolas; color: black" lang="EN-US">      </span><b><span style="font-family: consolas; color: #7f0055" lang="EN-US">public</span></b><span style="font-family: consolas; color: black" lang="EN-US"> List<String> getTitles() {</span></p> <p style="line-height: normal; margin-bottom: 0pt" class="MsoNormal"><span style="font-family: consolas; color: black" lang="EN-US">            </span><b><span style="font-family: consolas; color: #7f0055">return</span></b><span style="font-family: consolas; color: black"> </span><span style="font-family: consolas; color: #0000c0">titles</span><span style="font-family: consolas; color: black">;</span></p> <p style="line-height: normal; margin-bottom: 0pt" class="MsoNormal"><span style="font-family: consolas; color: black">      }</span></p> <p style="line-height: normal; margin-bottom: 0pt" class="MsoNormal"><span style="font-family: consolas; color: black">}</span></p> <p class="MsoNormal">Lets say that in our snippet we have something like :</p> <style><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><!--<br /> /* Font Definitions */<br /> @font-face<br /> {font-family:"Cambria Math";<br /> panose-1:2 4 5 3 5 4 6 3 2 4;}<br />@font-face<br /> {font-family:calibri;<br /> panose-1:2 15 5 2 2 2 4 3 2 4;}<br />@font-face<br /> {font-family:consolas;<br /> panose-1:2 11 6 9 2 2 4 3 2 4;}<br /> /* Style Definitions */<br /> p.msonormal, li.msonormal, div.msonormal<br /> {margin-top:0cm;<br /> margin-right:0cm;<br /> margin-bottom:10.0pt;<br /> margin-left:0cm;<br /> line-height:115%;<br /> font-size:11.0pt;<br /> font-family:"Calibri","sans-serif";}<br />.msopapdefault<br /> {margin-bottom:10.0pt;<br /> line-height:115%;}<br />@page section1<br /> {size:612.0pt 792.0pt;<br /> margin:70.85pt 70.85pt 70.85pt 70.85pt;}<br />div.section1<br /> {page:section1;}<br />--></style> <div class="Section1"> <p style="line-height: normal; margin-bottom: 0pt" class="MsoNormal"><span style="font-family: consolas"></span></p> <p class="MsoNormal"><span style="font-family: consolas; color: black">  Book myCrazyBook=</span><b><span style="font-family: consolas; color: #7f0055">new</span></b><span style="font-family: consolas; color: black"> Book();</span></p> </div> </div> <p>and we want to assign an empty list to the titles in this book. This is a common scenario if you want to set something to be emptyList in specific case instead of null. </p> <p>So of course your first try will be something like: <br />Answer 1:</p> <blockquote> <div class="Section1"> <p style="line-height: normal; margin-bottom: 0pt" class="MsoNormal"><span style="font-family: consolas; color: black">  myCrazyBook.setTitles(</span><b><u><span style="font-family: consolas; color: #7f0055">new</span></u></b><u><span style="font-family: consolas; color: black"> ArrayList()</span></u><span style="font-family: consolas; color: black">);  </span></p> </div> </blockquote> <p>-WARRNING - ArrayList is a raw type. References to generic type ArrayList<E> should be parameterized </p> <p>Ok changing to:</p> <div class="Section1"> <p style="line-height: normal; margin-bottom: 0pt" class="MsoNormal"><span style="font-family: consolas; color: black">  </span><span style="font-family: consolas; color: black" lang="EN-US">myCrazyBook.setTitles(</span><b><span style="font-family: consolas; color: #7f0055" lang="EN-US">new</span></b><span style="font-family: consolas; color: black" lang="EN-US"> ArrayList<String>());  </span><span style="font-family: consolas; color: black" lang="EN-US">  </span></p> </div> <p>WTF ? the problem in this answer is not small one : <br />- you are creating empty ArrayList which basiclly is not needed. ( what if you are in a loop 1000+ empty ArrayLists ? )</p> <p>Answer 2.</p> <style><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><!--<br /> /* Font Definitions */<br /> @font-face<br /> {font-family:"Cambria Math";<br /> panose-1:2 4 5 3 5 4 6 3 2 4;}<br />@font-face<br /> {font-family:calibri;<br /> panose-1:2 15 5 2 2 2 4 3 2 4;}<br />@font-face<br /> {font-family:consolas;<br /> panose-1:2 11 6 9 2 2 4 3 2 4;}<br /> /* Style Definitions */<br /> p.msonormal, li.msonormal, div.msonormal<br /> {margin-top:0cm;<br /> margin-right:0cm;<br /> margin-bottom:10.0pt;<br /> margin-left:0cm;<br /> line-height:115%;<br /> font-size:11.0pt;<br /> font-family:"Calibri","sans-serif";}<br />.msopapdefault<br /> {margin-bottom:10.0pt;<br /> line-height:115%;}<br />@page section1<br /> {size:612.0pt 792.0pt;<br /> margin:70.85pt 70.85pt 70.85pt 70.85pt;}<br />div.section1<br /> {page:section1;}<br />--></style> <p>   <span style="font-family: consolas; color: black" lang="EN-US">myCrazyBook.setTitles(<u>Collections.</u></span><i><u><span style="font-family: consolas; color: #0000c0" lang="EN-US">EMPTY_LIST</span></u></i><span style="font-family: consolas; color: black" lang="EN-US">);</span></p> <p>-WARNING : Type safety: The expression of type List needs unchecked conversion to conform to List<String>, because the EMPTY_LIST is raw type, which was heavily used before Java 1.5. <br />The definition of this list is :</p> <div class="Section1"> <p style="line-height: normal; margin-bottom: 0pt" class="MsoNormal"><span style="font-family: consolas; color: black" lang="EN-US">    </span><span style="font-family: consolas; color: #3f5fbf" lang="EN-US">/**</span></p> <p style="line-height: normal; margin-bottom: 0pt" class="MsoNormal"><span style="font-family: consolas; color: #3f5fbf" lang="EN-US">     * The empty list (immutable).  This list is serializable.</span></p> <p style="line-height: normal; margin-bottom: 0pt" class="MsoNormal"><span style="font-family: consolas; color: #3f5fbf" lang="EN-US">     </span><span style="font-family: consolas; color: #3f5fbf">*</span></p> <p style="line-height: normal; margin-bottom: 0pt" class="MsoNormal"><span style="font-family: consolas; color: #3f5fbf">     * </span><b><span style="font-family: consolas; color: #7f9fbf">@see</span></b><span style="font-family: consolas; color: #3f5fbf"> #emptyList()</span></p> <p style="line-height: normal; margin-bottom: 0pt" class="MsoNormal"><span style="font-family: consolas; color: #3f5fbf">     */</span></p> <p class="MsoNormal"><span style="font-family: consolas; color: black" lang="EN-US">    </span><b><span style="font-family: consolas; color: #7f0055" lang="EN-US">public</span></b><span style="font-family: consolas; color: black" lang="EN-US"> </span><b><span style="font-family: consolas; color: #7f0055" lang="EN-US">static</span></b><span style="font-family: consolas; color: black" lang="EN-US"> </span><b><span style="font-family: consolas; color: #7f0055" lang="EN-US">final</span></b><span style="font-family: consolas; color: black" lang="EN-US"> List </span><i><span style="font-family: consolas; color: #0000c0" lang="EN-US">EMPTY_LIST</span></i><span style="font-family: consolas; color: black" lang="EN-US"> = </span><b><span style="font-family: consolas; color: #7f0055" lang="EN-US">new</span></b><span style="font-family: consolas; color: black" lang="EN-US"> EmptyList();</span></p> </div> <p>So you see it is not ArrayList or LinkedList or MyCrazyCustomListWhichIUseEveryWhereList.</p> <p>Answer 3: <br />Eclipse will tell you this answer : Replace with Collections.emptyList();</p> <div class="Section1"> <p style="line-height: normal; margin-bottom: 0pt" class="MsoNormal"><span style="font-family: consolas; color: black" lang="EN-US">      myCrazyBook.<u>setTitles</u>(Collections.<i>emptyList</i>()); </span></p> </div> <p>COMPILE TIME ERROR: why ? because emptyList invoked like that means List of Objects not List of String. The other thing is that you cannot cast to List<String> because you cannot cast List<Object>  to List<String>.</p> <p>Answer 4: <br />You know that there is Collections.emptyList() AND YOU KNOW THAT IT RETURNS List<T> <br />so your answer is:</p> <div class="Section1"> <p style="line-height: normal; margin-bottom: 0pt" class="MsoNormal"><span style="font-family: consolas; color: black">            </span><span style="font-family: consolas; color: black" lang="EN-US">Book myCrazyBook=</span><b><span style="font-family: consolas; color: #7f0055" lang="EN-US">new</span></b><span style="font-family: consolas; color: black" lang="EN-US"> Book();</span></p> <p style="line-height: normal; margin-bottom: 0pt" class="MsoNormal"><span style="font-family: consolas; color: black" lang="EN-US">            List<String> titles = Collections.<i>emptyList</i>();</span></p> <p style="line-height: normal; margin-bottom: 0pt" class="MsoNormal"><span style="font-family: consolas; color: black" lang="EN-US">            </span><span style="font-family: consolas; color: black">myCrazyBook.setTitles(titles);</span></p> <p style="line-height: normal; margin-bottom: 0pt" class="MsoNormal"><span style="font-family: consolas; color: black">            </span></p> </div> <p>And this will work WITHOUT any WARNINGS or ERRORS. The type of the List is taken from the type of the variable that you are trying to assign to. <br />Of course why you need this local variable ? I want to remove it it is not needed and used, but if you remove it you are in Answer 3. So what can you do ? </p> <p>Answer 5: The right but strange looking answer.</p> <div class="Section1"> <p style="line-height: normal; margin-bottom: 0pt" class="MsoNormal"><span style="font-family: consolas; color: black">            </span><span style="font-family: consolas; color: black" lang="EN-US">Book myCrazyBook=</span><b><span style="font-family: consolas; color: #7f0055" lang="EN-US">new</span></b><span style="font-family: consolas; color: black" lang="EN-US"> Book();</span></p> <p style="line-height: normal; margin-bottom: 0pt" class="MsoNormal"><span style="font-family: consolas; color: black" lang="EN-US">            myCrazyBook.setTitles(Collections.<String><i>emptyList</i>());</span></p> </div> <p>Yes this is not a joke there is a dot (.) then the generic type before the method name. This compiles, runs, no warnings thats the real way. <br />It is a little strange that most people dont know this aspect of generics in Java even I didn't know it, I was thinking that you cannot pass a generic type like this but as it looks you can. </p> <p>So if you have some static method like this one:</p> <p style="line-height: normal; margin-bottom: 0pt" class="MsoNormal"><b><span style="font-family: consolas; color: #7f0055" lang="EN-US">public</span></b><span style="font-family: consolas; color: black" lang="EN-US"> </span><b><span style="font-family: consolas; color: #7f0055" lang="EN-US">class</span></b><span style="font-family: consolas; color: black" lang="EN-US"> Main{</span></p> <p style="line-height: normal; margin-bottom: 0pt" class="MsoNormal"><span style="font-family: consolas; color: black" lang="EN-US">      </span><b><span style="font-family: consolas; color: #7f0055" lang="EN-US">public</span></b><span style="font-family: consolas; color: black" lang="EN-US"> </span><b><span style="font-family: consolas; color: #7f0055" lang="EN-US">static</span></b><span style="font-family: consolas; color: black" lang="EN-US"> <G> List<G> someGreatMethod(){</span></p> <p style="line-height: normal; margin-bottom: 0pt" class="MsoNormal"><span style="font-family: consolas; color: black" lang="EN-US">            List<G> gList= </span><b><span style="font-family: consolas; color: #7f0055" lang="EN-US">new</span></b><span style="font-family: consolas; color: black" lang="EN-US"> ArrayList<G>();</span></p> <p style="line-height: normal; margin-bottom: 0pt" class="MsoNormal"><span style="font-family: consolas; color: black" lang="EN-US">            </span><b><span style="font-family: consolas; color: #7f0055">return</span></b><span style="font-family: consolas; color: black"> gList;</span></p> <p style="line-height: normal; margin-bottom: 0pt" class="MsoNormal"><span style="font-family: consolas; color: black">      }</span></p> <p class="MsoNormal"><span style="font-family: consolas; color: black">}</span></p> you can invoke it with Main.<String>someGreatMethod(); for example. jNaydenhttp://www.blogger.com/profile/04678280364638370213noreply@blogger.com7