Friday, August 29, 2014

Generate java file from wsdl

Hi, The wsimport tool is used to parse an existing Web Services Description Language (WSDL) file and generate required files -java class or java files etc.- for web service client to access the published web services. This wsimport tool is available in the $JDK/bin folder. And wsimport tool come with jdk 1.&+

#wsimport -keep -d (for your generate files directory) -verbose http://kirazibrahim.blogpsot.com.tr/ws/server?wsdl

Friday, August 15, 2014

ClassNotFoundException: org.hibernate.service.jndi.JndiException

if you are getting this expection;
java.lang.ClassNotFoundException: org.hibernate.service.jndi.JndiException
    java.net.URLClassLoader$1.run(Unknown Source)
    java.net.URLClassLoader$1.run(Unknown Source)
    java.security.AccessController.doPrivileged(Native Method)
    java.net.URLClassLoader.findClass(Unknown Source)
    org.springframework.boot.loader.LaunchedURLClassLoader.findClass(LaunchedURLClassLoader.java:148)
    java.lang.ClassLoader.loadClass(Unknown Source)
    org.springframework.boot.loader.LaunchedURLClassLoader.doLoadClass(LaunchedURLClassLoader.java:131)
    org.springframework.boot.loader.LaunchedURLClassLoader.loadClass(LaunchedURLClassLoader.java:103)
    java.lang.ClassLoader.loadClass(Unknown Source)
    java.lang.Class.forName0(Native Method)
    java.lang.Class.forName(Unknown Source)
    org.jboss.logging.Logger$1.run(Logger.java:2252)
    java.security.AccessController.doPrivileged(Native Method)
    org.jboss.logging.Logger.getMessageLogger(Logger.java:2227)
    org.jboss.logging.Logger.getMessageLogger(Logger.java:2214)
    org.hibernate.ejb.Ejb3Configuration.(Ejb3Configuration.java:143)
    org.hibernate.ejb.HibernatePersistence.createContainerEntityManagerFactory(HibernatePersistence.java:74)
    org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:318)
    org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:317)
    org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1607)
    org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1544)
    org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:539)
    org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:475)
    org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:300)
    org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228)
    org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:296)
    org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:195)
    org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:973)
    org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:750)
    org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:482)
    org.springframework.context.support.ClassPathXmlApplicationContext.(ClassPathXmlApplicationContext.java:139)
    org.springframework.context.support.ClassPathXmlApplicationContext.(ClassPathXmlApplicationContext.java:83)
    com.mydomain.GetController.getUser(GetController.java:20)
    sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    java.lang.reflect.Method.invoke(Unknown Source)
    org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:214)
    org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:132)
    org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:104)
    org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:748)
    org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:689)
    org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:83)
    org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:947)
    org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:878)
    org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:946)
    org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:837)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
    org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:822)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
    org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:77)
    org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:108)

And if you are using hibernate-core & hibernate-entitymanager in your pom.xml, They must mu same version. I tried this and solved.
   
        org.hibernate
        hibernate-core
        4.1.9.Final
    


    
        org.hibernate
        hibernate-entitymanager
        4.1.9.Final
    

Friday, July 18, 2014

Using spring framework in Standalone Java Project

Hi,
if you want to use spring framework in your java application (jar) you need to take care for something.

First of all you need to use apache-shade-plugin for read your applicationContext.xml file in jar.

Here is sample pom.xml

 


<groupid>tr.com.kiraz</groupid>
    <artifactid>fatura</artifactid>
    <version>1.0.0</version>
    <packaging>jar</packaging>
    <name>fatura</name>

    <properties>
        <project .build.sourceencoding="">UTF-8</project>
        <project .reporting.outputencoding="">UTF-8</project>
        <argline>-Dfile.encoding=UTF-8</argline>
    </properties>


    <build>
        <plugins>
            <plugin>
                <groupid>org.apache.maven.plugins</groupid>
                <artifactid>maven-compiler-plugin</artifactid>
                <version>2.3.2</version>
                <configuration>
                    <source></source>1.6
                    <target>1.6</target>
                </configuration>
            </plugin>

            <plugin>
                <!-- Build an executable JAR -->
                <groupid>org.apache.maven.plugins</groupid>
                <artifactid>maven-jar-plugin</artifactid>
                <version>2.4</version>
                <configuration>
                    <archive>
                        <manifest>
                            <addclasspath>true</addclasspath>
                            <mainclass>tr.com.tnbkep.BankaFatura</mainclass>
                        </manifest>
                    </archive>
                </configuration>
            </plugin>


            <plugin>
                <groupid>org.apache.maven.plugins</groupid>
                <artifactid>maven-shade-plugin</artifactid>
                <version>2.3</version>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>shade</goal>
                        </goals>
                        <configuration>
                            <transformers>
                                <!--<transformer implementation="org.apache.maven.plugins.shade.resource.ComponentsXmlResourceTransformer"/>-->
                                <transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
                                    <resource>META-INF/spring.handlers</resource>
                                </transformer>
                                <transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
                                    <resource>META-INF/spring.schemas</resource>
                                </transformer>

                            </transformers>
                        </configuration>
                    </execution>
                </executions>
            </plugin>


        </plugins>
    </build>

    

Wednesday, July 16, 2014

Send attachment in java mail

How can i send attachment in java mail ? You can use java mail API, if you don't have got yet you can download from this link java mail API and add your project library.

public static void main(String[] args) throws MessagingException, IOException {

        String filename = "fatura.txt";

//        dosya oluşturma ve içerisine bilgi girme
        String text = "fatura bilgileri dosya içi";
        try {
            File file = new File(filename);
            BufferedWriter output = new BufferedWriter(new FileWriter(file));
            output.write(text);
            output.close();
        } catch ( IOException e ) {
            LOGGER.error("dosya oluşturulamadı");
        }


        Properties props = System.getProperties();
        javax.mail.Session session = javax.mail.Session.getDefaultInstance(props, null);


        MimeMessage message = new MimeMessage(session);
        message.setSubject("Fatura Bilgileri");
        message.setSentDate(new Date());

        // E-mail body kısmı

        MimeBodyPart messagePart = new MimeBodyPart();
        messagePart.setText("Tarih :" + new Date());

        // E-mail attachment kısmı

        MimeBodyPart attachmentPart = new MimeBodyPart();
        FileDataSource fileDataSource = new FileDataSource(filename) {
            @Override
            public String getContentType() {
                return "application/octet-stream";
            }
        };
        attachmentPart.setDataHandler(new DataHandler(fileDataSource));
        attachmentPart.setFileName(fileDataSource.getName());

        // bütün partları ekle

        Multipart multipart = new MimeMultipart();
        multipart.addBodyPart(messagePart);
        multipart.addBodyPart(attachmentPart);
        message.setContent(multipart);

        sendMail(message);

    }

Send mail method



public static void sendMail(MimeMessage mail) throws MessagingException {

        String host = "yourhostname";
        String username = "ibrahim.kiraz";
        Properties props = new Properties();

        props.setProperty("mail.smtp.host", host);
        props.put("mail.smtp.starttls.enable", "false");
        props.setProperty("mail.smtp.auth", "true"); // s
        javax.mail.Session session = javax.mail.Session.getInstance(props);
       
 // mesaj content kısmı

        Transport t = session.getTransport("smtp");
        Address fromUser = new InternetAddress("\"İbrahim Kiraz\"ibrahimkiraz@abc.com");
        Address toUser = new InternetAddress("ibrahim.kiraz@xxx.com.tr");
        mail.setFrom(fromUser);
        mail.setRecipient(Message.RecipientType.TO, toUser);


        try {
            t.connect(host, username);
            t.sendMessage(mail, mail.getAllRecipients());
            LOGGER.info("Mail başarıyla gönderildi");
        } catch (MessagingException e) {
            LOGGER.error("Mail gönderilemedi", e);
        } finally {
            t.close();
        }

    }

Tuesday, July 15, 2014

How can i use Crontab, Crond Service

What is Crontab and Crond Service ?

Hi,
Crond service provides for using periodic task in linux to us. Ok, now how can i use crond service ?
This example may be helpful.

Open MPutty or Putty and connect your server (Centos, Redhat vs)
#crontab -e

Add those lines

*     *    *    *    * ls>>/var/log/yourLogFile

Upper line provides every minute execute ls command and send output to yourLogFile.


This * means that
minute     hour     day     month     dayofweek     command



# at 3:30 AM in the file /tmp/meminfo 
30 3 * * /root/scripts/yourScript.sh >> /tmp/meminfo 
# run custom script the second day of every month at 4:10 AM 
10 4 2 * * /root/scripts/yourScript.sh


When you finish your job in file, you must be start crond service this command
#service crond start

Monday, July 14, 2014

Dovecot, Postfix kurulumu

Dovecot kurulumu, postfix kurulumu Centos 6.5 yüklü sunucu üzerinde anlatılacaktır.

Postfix Kurulumu


1- İlk olarak /etc/hosts dosyasına maillerde kullanılacak sunucu ve ip adresi eklenir.
# nano /etc/hosts   
  192.168.0.21 example.com

2- Postfix yüklenir
# yum -y install postfix 

3- SMTP autherization paketleri yüklenir
# yum -y install cyrus-sasl cyrus-sasl-devel cyrus-sasl-gssapi cyrus-sasl-md5 cyrus-sasl-plain

4- Postfix kurulumu tamamlandıktan sonra SSL sertifikası oluşturulur.
# mkdir /etc/postfix/ssl 
# cd /etc/postfix/ssl/
# openssl genrsa -des3 -rand /etc/hosts -out smtpd.key 1024 
# chmod 600 smtpd.key 
# openssl req -new -key smtpd.key -out smtpd.csr 
# openssl x509 -req -days 365 -in smtpd.csr -signkey smtpd.key -out smtpd.crt 
# openssl rsa -in smtpd.key -out smtpd.key.unencrypted 
# mv -f smtpd.key.unencrypted smtpd.key 
# openssl req -new -x509 -extensions v3_ca -keyout cakey.pem -out cacert.pem -days 365

5- /etc/postifx/main.cf dosyası açılır ve aşağıdaki satırlar commentlenir.
# nano /etc/postfix/main.cf
    inet_interfaces = localhost  (116. satır)   
    mydestination = $myhostname, localhost.$mydomain, localhost  (164. satır)

6- /etc/postfix/main.cf dosyası tekrar açılır ve aşağıdaki satırlar eklenir.
    myhostname = mail.example.com
    mydomain =
example.com
    myorigin = $mydomain
    home_mailbox = mail/
    mynetworks = 127.0.0.0/8
    inet_interfaces = all
    mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain
    smtpd_sasl_auth_enable = yes
    smtpd_sasl_type = cyrus
    smtpd_sasl_security_options = noanonymous
    broken_sasl_auth_clients = yes
    smtpd_sasl_authenticated_header = yes
    smtpd_recipient_restrictions = permit_sasl_authenticated,    permit_mynetworks,reject_unauth_destination
    smtpd_tls_auth_only = no
    smtp_use_tls = yes
    smtpd_use_tls = yes
    smtp_tls_note_starttls_offer = yes
    smtpd_tls_key_file = /etc/postfix/ssl/smtpd.key
    smtpd_tls_cert_file = /etc/postfix/ssl/smtpd.crt
    smtpd_tls_CAfile = /etc/postfix/ssl/cacert.pem
    smtpd_tls_received_header = yes
    smtpd_tls_session_cache_timeout = 3600s
    tls_random_source = dev:/dev/urandom


7- /etc/postfix/master.cf dosyası açılır ve aşağıdaki satırlar eklenir.
       smtps     inet  n       -       n       -       -       smtpd
      -o smtpd_sasl_auth_enable=yes
      -o smtpd_reject_unlisted_sender=yes
      -o smtpd_recipient_restrictions=permit_sasl_authenticated,reject
      -o broken_sasl_auth_clients=yes


8- Postfix kurulumu tamalandı şimdi postfix ve saslauthd servisleri başlatılabilir.
# service postfix start
# service saslauthd start

9- Sunucu başlatıldığında otomatik olarak başlaması için
# chkconfig --level 235 postifx on
# chkconfig --level 235 saslauthd on
 
10- Şimdi SMTP bağlantısının başarılı bir şekilde kurulup kurulmadıgını kontrol edebiliiriz.
# telnet localhost 25   
Trying ::1...
Connected to localhost.
Escape character is '^]'.
220 mail.example.com ESMTP Postfix
ehlo localhost <---- bu komut girilir
250-mail.example.com
250-PIPELINING
250-SIZE 10240000
250-VRFY
250-ETRN
250-STARTTLS
250-AUTH PLAIN LOGIN
250-AUTH=PLAIN LOGIN
250-ENHANCEDSTATUSCODES
250-8BITMIME
250 DSN

  
çıktısı alınıyor ise başarılı bir şekilde postfix kurulmuş demektir. 

Dovecot Kurulumu
 
1- Öncelikle dovecot.org/download.html adresinden şu andaki son versiyonu olan 2.2.13 versiyonu indirilir ve daha önceden oluşturduğumuz dizine kopyalanır.
# mkdir -p /data/install/2014/
# cd /data/install/2014/
# mkdir dovecot
# wget http://www.dovecot.org/releases/2.2/dovecot-2.2.13.tar.gz 
# tar -xzpf dovecot-2.2.13.tar.gz 
# cd dovecot-2.2.13 


2- Compile edebilmemiz için c compiler (gcc) ve diğer buna bağlı paketler indirilir.
# yum install gcc openldap-devel mysql-devel



3- Konfigürasyon ve kurulum başlatılır 
# ./configure --prefix=/usr 
            --sysconfdir=/etc 
            --localstatedir=/var 
            --docdir=/usr/share/doc/dovecot-2.2.13 
            --disable-static 

# make
# make install 



4- Softlink oluşturulur
# cd /usr/local
# ln -s dovecot-2.2.13 dovecot 


5- İndirilen dovecot paketinin içerisinde yer alan örnek konfigürasyon dosyaları /etc/dovecot dizini altına kopyalanır 
# cp -rv /usr/share/doc/dovecot-2.2.13/example-config/* /etc/dovecot 


6- Local kullanıcılar için yetkilendirme, mailbox lokasyonu gibi konfigürasyonlar aşağıdaki şekilde /etc/dovecot/local.conf dosyasına yazılmıştır.
# nano /etc/dovecot/local.conf



protocols = imap 
ssl = no 
listen = * 
mail_location = mbox:~/Mail:INBOX=/var/mail/%u 

userdb {
  driver = passwd
}
passdb {
  driver = shadow
}



7- Dovecot servisini başlatabilmek için startup script i yazmak gerekmektedir.
/etc/rc.d/init.d dizinine gidilir ve dovecot isminde bir dosya oluşturulur ve aşağıdaki satırlar içerisini kopyalanır.


#!/bin/bash
#
#       /etc/rc.d/init.d/dovecot
#
# Starts the dovecot daemon
#
# chkconfig: - 65 35
# description: Dovecot Imap Server
# processname: dovecot
# config: /etc/dovecot.conf
# config: /etc/sysconfig/dovecot
# pidfile: /var/run/dovecot/master.pid

### BEGIN INIT INFO
# Provides: dovecot
# Required-Start: $local_fs $network
# Required-Stop: $local_fs $network
# Should-Start: $remote_fs
# Should-Stop: $remote_fs
# Default-Start:
# Default-Stop: 0 1 2 3 4 5 6
# Short-Description: start and stop Dovecot Imap server
# Description: Dovecot is an IMAP server for Linux/UNIX-like systems,
#              written with security primarily in mind.  It also contains
#              a small POP3 server.
### END INIT INFO

ulimit -n 5000
# Source function library.
. /etc/init.d/functions

if [ -f /etc/sysconfig/dovecot -a $UID -eq 0 ]; then
    . /etc/sysconfig/dovecot
fi

RETVAL=0
prog="Dovecot Imap"
exec="/usr/local/dovecot/sbin/dovecot"
config="/etc/dovecot/dovecot.conf"
pidfile="/var/run/dovecot/master.pid"
lockfile="/var/lock/subsys/dovecot"

start() {
        [ $UID -eq 0 ] || exit 4
        [ -x $exec ] || exit 5
        [ -f $config ] || exit 6

        echo -n $"Starting $prog: "
        daemon --pidfile $pidfile $exec $OPTIONS
        RETVAL=$?
        [ $RETVAL -eq 0 ] && touch  $lockfile
        echo
}

stop() {
        [ $UID -eq 0 ] || exit 4
        echo -n $"Stopping $prog: "
        killproc -p $pidfile $exec
        RETVAL=$?
        [ $RETVAL -eq 0 ] && rm -f $lockfile
        echo
}

reload() {
        [ $UID -eq 0 ] || exit 4
        echo -n $"Reloading $prog: "
        killproc -p $pidfile $exec -HUP
        RETVAL=$?
        echo
}

#
#       See how we were called.
#
case "$1" in
  start)
        start
        ;;
  stop)
        stop
        ;;
  reload)
        reload
        ;;
  force-reload|restart)
        stop
        sleep 1
        start
        RETVAL=$?
        ;;
  condrestart|try-restart)
        if [ -f $lockfile ]; then
            stop
            sleep 3
            start
        fi
        ;;
  status)
        status -p $pidfile $exec
        RETVAL=$?
        ;;
  *)
        echo $"Usage: $0 {condrestart|try-restart|start|stop|restart|reload|force-reload|status}"
        RETVAL=2
        [ "$1" = 'usage' ] && RETVAL=0
esac

exit $RETVAL 

8- Dovecot servis olarak eklenir ve çalıştırılabilir scripte dönüştürülür. 
# chmod +x /etc/init.d/dovecot
# chkconfig --add dovecot

9- Sistem boot edildiğinde otomatik olarak Dovecot başlatılması için
# chkconfig dovecot on
 
10-  Konfigürasyonu test etmek için kullanıcı eklenir
# useradd -m ibrahim -s /sbin/nologin
# useradd -m kiraz -s /sbin/nologin 
 
Son olarak da squirrelMail ile kullanıcı girişi yapılarak local de mail gönderimi test edilir.

Thursday, July 10, 2014

MX kaydı sorgulama


Merhaba,
Daha önceki yazılarım arasında nslookup komutu ile domain sorgulama işlemi yapmıştım şimdi ise nslookup ile MX kaydı sorgulaması nasıl yapılır ona değineceğim.

Windows komut satırını açarak aşağıdaki şekilde sorgulama yapabiliriz.


How can we use svg file as a icon of v-btn (vuetify button) ?

<template>   <v-btn>     <CustomIcon />     Click me   </v-btn> </template> <script> // Import your SVG ...