Tuesday, October 24, 2017

unable to find valid certification path to requested target

1. Add certificate to cacerts with InstallCert.java or linux command line. Put it to %JAVA_HOME%\jre\lib\security\

2. Check or add usage correct -Djavax.net.ssl.trustStore="...\cacerts"

3. Check Network, Firewall and Proxy settings by accessing the site with:
      Try:
         ping host 
         ping ip
      Try:
         telnet hostname port 

AWS SES - Amazon Send Email Service

COMMANDS
javac -cp *; MailTest.java
java -cp *;  -Dlog4j.configurationFile=log4j2-console.xml MailTest

DIR
aws-java-sdk-core-1.11.119.jar
aws-java-sdk-ses-1.11.119.jar
httpclient-4.5.3.jar
httpcore-4.4.6.jar
jackson-annotations-2.7.0.jar
jackson-core-2.7.1.jar
jackson-databind-2.7.1.jar
jcl-over-slf4j-1.7.7.jar
joda-time-2.8.1.jar
log4j-api-2.1.jar
log4j-core-2.1.jar
log4j-slf4j-impl-2.1.jar
log4j2-console.xml
MailTest.class
MailTest.java

slf4j-api-1.7.7.jar




MailTest.java
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.amazonaws.AmazonServiceException;
import com.amazonaws.auth.AWSStaticCredentialsProvider;
import com.amazonaws.auth.BasicAWSCredentials;
import com.amazonaws.services.simpleemail.AmazonSimpleEmailService;
import com.amazonaws.services.simpleemail.AmazonSimpleEmailServiceClientBuilder;
import com.amazonaws.services.simpleemail.model.Body;
import com.amazonaws.services.simpleemail.model.Content;
import com.amazonaws.services.simpleemail.model.Destination;
import com.amazonaws.services.simpleemail.model.Message;
import com.amazonaws.services.simpleemail.model.SendEmailRequest;


public class MailTest {

private static final Logger LOGGER = LoggerFactory.getLogger(MailTest.class);

public static void main(String[] args) {

System.out.println("=start=");

String awsAccessKey="change_it";
String awsSecretKey="change_it";
String awsSesRegion="us-west-2";

BasicAWSCredentials credentials = new BasicAWSCredentials(awsAccessKey, awsSecretKey);

AmazonSimpleEmailService amazonSesClient = AmazonSimpleEmailServiceClientBuilder.standard()
.withCredentials(new AWSStaticCredentialsProvider(credentials))
.withRegion(awsSesRegion)
.build();


Content subjectContent = new Content("subject");
Content bodyContent = new Content("body email content");

Body mailBody = new Body().withText(bodyContent);

Message message = new Message().withSubject(subjectContent).withBody(mailBody);

Destination destination = new Destination().withToAddresses("alexey.zavizionov@gmail.com");
SendEmailRequest request = new SendEmailRequest()
.withSource("alexey.zavizionov@gmail.com")
.withDestination(destination)
.withMessage(message);

System.out.println("===============");
System.out.println(request);
System.out.println("---------------");

try {
amazonSesClient.sendEmail(request);
LOGGER.debug("Email with subject '{}' was sent to: {}", "subject", "alexey.zavizionov@gmail.com");
return;
} catch (AmazonServiceException a) {
LOGGER.error("Maximum sending rate exceeded when sending email: {}", message, a);
return;
} catch (Exception e) {
LOGGER.error("Failed to send email: {}", message, e);
return;
} finally {
System.out.println("=THE END=");
}

}

}


log4j2-console.xml
code
   
       
           
                %level{length=1} %date{MMdd-HHmm:ss,SSS} %logger{1.} %message [%thread]%n
           
       
   
   
       
           
       
   

Error: Could not find or load main class - SOLUTION

PROBLEM:
Error: Could not find or load main class

SOLUTION:
java -cp *;  MyTest
Don't forget to use ";"!


Wednesday, October 11, 2017

Eclipse + OSGi + m2e + Tycho plugin

Eclipse Java EE IDE for Web Developers.

Version: Mars Release (4.5.0)
Build id: 20150621-1200




Or use a new one
https://www.eclipse.org/downloads/packages/eclipse-ide-java-ee-developers/oxygen1


---
m2e should be already installed in eclipse



---

Tycho software site

org.sonatype.tycho.repository -
http://repo1.maven.org/maven2/.m2e/connectors/m2eclipse-tycho/0.8.0/N/0.8.0.201409231215/




Open resource


Click at "Set as Target Platform"




Eclipse download statistic



Version                 Year    EE         ide    classic      size ee
Galileo 3.5.2        2009 745 1094 651 190
Helios 3.6.2         2010 3982 934 421 206
Indigo 3.7.2         2011 4671156 1659485 3223475 213
Juno 4.2.2            2012 2825040 1119755 1827173 229
Kepler 4.3.2        2013 4174634 1235322 5699326 250
Luna 4.4.2           2014 2561008 4392111 347281 254
Mars 4.5.2           2015 3419709 1479877 169154 275
Neon                    2016 1805982 804094 54177 304
Oxygen                2017 136808 88226 8991 328

Wednesday, September 20, 2017

Monday, September 11, 2017

Git add changes to last commit

It will be rebasing last commit with a new one.

git add .
git commit --amend --no-edit
git push -f

Wednesday, September 6, 2017

uptime periodic print

while(true); do uptime | sed -E 's/\s*up\s*([0-9]* day[s]*,\s*[0-9]*:[0-9]*|[0-9]*:[0-9]*),\s*[0-9]* user[s]*,\s*load average:\s/, /'; sleep 3; done




while(true); do uptime | cut -d':' -f4; sleep 3; done

Friday, September 1, 2017

Grep Console for Eclipse console highlights

http://marian.schedenig.name/projects/grep-console/installation/

Monday, July 17, 2017

Mongo find by id from one collection in other on remove

var id = db.getCollection('first_collection').find({jobClass:"com.example.CleanerJob"}, { _id: 1 }).next()._id;
db.getCollection('second_collection').findOne({"jobId":id});
db.getCollection('first_collection').findOne(id);

Test it on your local. If it is ok, replace all "findOne" with "remove"

RELATED:
quartz and mongo:
org.quartz.JobPersistenceException: Could not load job class [See nested exception: java.lang.ClassNotFoundException:
at com.novemberain.quartz.mongodb.JobConverter.toJobDetail
...
at com.novemberain.quartz.mongodb.MongoDBJobStore.triggersFired
...


Tuesday, July 11, 2017

Все сотовые Украины

Все мобильные операторы Ураины
All Ukraine mobile operators.
Mobile UA codes.


Wednesday, July 5, 2017

Create one class from another with Stream API

public class User {
public User(

public class UserInfo {
public UserInfo(User log) {

List all = service.getUsers();

List infos = all.stream().map(UserInfo::new).collect(Collectors.toList());

Tuesday, July 4, 2017

Rename git branch

Create a new branch from the old one:

git checkout branch_name
git checkout -b new_branch_name
git push --set-upstream origin new_branch_name

Delete the old branch local and remote:

git branch -D branch_name
git push origin --delete branch_name

Possible you want to rebase or squash commits:

git rebase -i master

=happy=

Thursday, June 8, 2017

NoClassDefFoundError LogManager

PROBLEM:
NoClassDefFoundError: Could not initialize class org.apache.log4j.LogManager

SOLUTION:
remove:  -Dlog4j.configuration=file:conf/log4j.xml


Docs:
slf4j: https://www.slf4j.org/legacy.html
jars:
commons-logging-1.2.jar
jcl-over-slf4j-1.7.7.jar or jul-to-slf4j-1.7.12.jar
log4j-1.2.18*.jar
slf4j-api-1.7.12.jar
slf4j-log4j12-1.7.12.jar





Wednesday, June 7, 2017

PROBLEM:
Compilation failure
error: cannot access Consumer

SOLUTION:
Upgrade Java 1.7 to Java 1.8

Tuesday, June 6, 2017

Maven: Unable to find valid certification path to requested target

PROBLEM:
[ERROR] Failed to execute goal on project ***:
Could not resolve dependencies for project ***:
Failed to collect dependencies at ***
Failed to read artifact descriptor for ***
Could not transfer artifact *** sun.security.validator.ValidatorException:
PKIX path building failed:
sun.security.provider.certpath.SunCertPathBuilderException:
unable to find valid certification path to requested target

SOLUTION:
Create folder c:\Users\YOUR_NAME\certs\
Put keys *.cer and certs in it
Run:
mvn -Djavax.net.ssl.trustStore="c:\Users\YOUR_NAME\certs\cacerts" -Dmaven.wagon.http.ssl.ignore.validity.dates=true  -Dmaven.wagon.http.ssl.insecure=true -Dmaven.wagon.http.ssl.allowall=true  clean install

Wednesday, May 31, 2017

Git howto

Clone the master

git clone https://git/com.company.api.core.git
git clone https://git/com.company.api.core.git []

Create a new branch

git checkout -b my_hello_world_branch
git add .
git commit -m "B012345 Fixed Hello World"
git push -u origin my_hello_world_branch

Checkout

git checkout master
git checkout 
git checkout 

Merge a fresh master into your branch

git checkout master
git pull --rebase
git checkout some_fix_bug
git merge master
git push
or
git fetch
git pull origin master
git push
Before push you might need to resolve conflicts, then add and commit them

Stash

Save not staged (not git added changes) changes in local stack storage
git stash
Pop them back
git stash pop

Reset

Reset staged files, to get them back to local (NOTHING LOST).
git reset HEAD

If you have uncommitted changes that you want to discard (you'll LOST ALL UNCOMMITTED), use this:
This removes all the local uncommitted changes.
git reset --hard 
which is equivalent to
git reset --hard HEAD 

If you want to remove some offending commits from your local branch (you'll LOST PREVIOUS COMMIT), try rewinding it:
git reset --hard HEAD^ #moves HEAD back by one commit 
or e.g. (you'll LOST PREVIOUS three COMMITS)
git reset --hard HEAD~3 #moves HEAD back by 3 commits 
Use these with caution, as you won't be able to undo these operations. Once you're done cleaning up your local branch, use git pull to get the latest code.
Then 
git push -f origin 
If you have it in ignore, use 
 git clean -xf.
You can do 
 git clean -df 
but that will also remove un-tracked directories. Use -n for a dry-run.

Delete branches

Delete branch local
git branch -D 
Delete branch remote
git push origin --delete 

Copy a commit

Apply any commit done in the some branch to the local current branch
git cherry-pick c1qwlkjfcnc432289a42d34ab4b23803c9

Show list all

git branch
git tag
git branch -r
git remote show origin

Checkout Tags

After the clone, you can list the tags with 
 git tag -l 
and then checkout a specific tag: 
 git checkout tags/

Diff

Show changes between commits (Diff man )
git diff 4223732fhkjsdve1ffce96563367e8fdc^
git diff HEAD^
git diff HEAD~2

Rename a tag

Here is how to rename a tag old to new:
git tag new old
git tag -d old
git push origin :refs/tags/old
git push --tags

Show staged diff

You can show changes that have been staged with the --cached flag:
git diff --cached

Show diff latest 10 commit in current folder

git log -10 . | grep commit | sed 's/commit //' | xargs  git diff

Squashing commits with rebase