Friday, December 27, 2013

SSH Password less connectivity between servers..

Login to server say A with a certain ip address.
 
 
Steps to execute
 
1.ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/home/a/.ssh/id_rsa): 
Created directory '/home/a/.ssh'.
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /home/a/.ssh/id_rsa.
Your public key has been saved in /home/a/.ssh/id_rsa.pub.
The key fingerprint is:
3e:4f:05:79:3a:9f:96:7c:3b:ad:e9:58:37:bc:37:e4 a@A
 
in the .ssh directory u would find three files:-
 
-rw-r--r--   1 carisman asg          229 Nov 27 17:21 id_rsa.pub
-rw-------   1 carisman asg          883 Nov 27 17:21 id_rsa
-rw-r--r--   1 carisman asg         2406 Dec  2 06:06 known_hosts
-rw-r--r--   1 carisman asg         1914 Dec 10 15:00 authorized_keys
 

where id_rsa.pub contains the public key of the server 

id_rsa contains the private key.


Now say you wanna log into server b
from server a via (ssh username@ip)
 
go to server b.find the .ssh directory which is actually a hidden dir.
 
now copy the public key of server a into the auihorized_keys file of server b.
 
then try again logging via ssh.
Next time it shouldn't prompt for password. 



dys301a001: more authorized_keys

ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAIEA5/AGIVIbEpYMWnn1O8IOnVeG3k76bI9cYg+8Rqn/GjHzs5iownSQ0SOCRJmaXfdY4XLW/IhUNh0bLIN/hyHZXKzB1
KGH8dWT69fWaHdfUzCMI0coTqZp0S8CcblM6R8lZ5j7pLTmNyqS8zeDha6MPf+3IlfdsI0lhbOh4fM1un0= dial@hwsnet01
1024 35 110606535021230677166642170605791804032587756457705016112225220058665302167946280750828811369230048501248010930732174
09750990674780468447807993612977975979054372083446310435517956860073945567084113240701328264607148843115383124630161854727920
8805722148623831645095170046145961368543171199904180920721600578077 gipp@dyslby01
ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAIEAsUrfr0OqdoCx/4+R7pNj0aEoy/Ic6t+LQNZRbAQ67vipzej+Pt5ij5B5UTuUc3gSX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sqGESkgIrbzWCApIUTlNcQlSGKJKGSwFQWsrojsQVFYSSygI26gnD
lvQu/HrT1qTCmDcHo+VRZL0qzEA3jwjy60DNLvohHWLm5s2xrQ50FUkpmIp4t5K4GjeaDcnM/eQ9wpuLLM= voip@dys118d001

If you look at the file you can see that the public keys have been generated at the respective servers and have been added to the authorized_key file of this server.

Sunday, June 9, 2013

JAVA DECOMPILER FOR READING THE JAR FILES

Recently I was having problems when i was trying  to read the external jar files.i searched and found that eclipse already has a plugin for that.then i did download the decompiler .and yes its makes you a better programmer when you understand the jar files.


Eclipse->Help->Install new software->add

NAME:JD-Eclipse Update Site

URL:http://jd.benow.ca/jd-eclipse/update  

restart eclipse .


Saturday, June 23, 2012

Struts2 Architecture+lifecycle

reference:-http://viralpatel.net/blogs/introduction-to-struts-2-framework/


  1. The normal lifecycle of struts begins when the request is sent from client. This results invoke the servlet container which in turn is passed through standard filter chain.
  2. The FilterDispatcher filter is called which consults the ActionMapper to determine whether an Actionshould be invoked.
  3. If ActionMapper finds an Action to be invoked, the FilterDispatcher delegates control to ActionProxy.
  4. ActionProxy reads the configuration file such as struts.xml. ActionProxy creates an instance ofActionInvocation class and delegates the control.
  5. ActionInvocation is responsible for command pattern implementation. It invokes the Interceptors one by one (if required) and then invoke the Action.
  6. Once the Action returns, the ActionInvocation is responsible for looking up the proper result associated with the Action result code mapped in struts.xml.
  7. The Interceptors are executed again in reverse order and the response is returned to the Filter (In most cases to FilterDispatcher). And the result is then sent to the servlet container which in turns send it back to client.
     
    last week i have gone through the struts concepts .thanks to mykong's blog.i am becoming his fan.
    REFERENCE:-http://www.mkyong.com/tutorials/struts-2-tutorials/

Saturday, April 14, 2012

successful in understanding google app engine .finished learning a full project,awesome concepts

the whole project can be downloaded form http://www.mediafire.com/?2cwxmg5i2cnl3f6
Understanding datastore??
references:-https://developers.google.com/appengine/docs/java/gettingstarted/usingdatastore

 DatastoreService datastore =  DatastoreServiceFactory.getDatastoreService();     datastore.put(greeting);

Because querying in the High Replication datastore is only strongly consistent within entity groups, we assign all Greetings to the same entity group by setting the same parent for each Greeting. This means a user will always see a Greeting immediately after it was written. However, the rate at which you can write to the same entity group is limited to 1 write to the entity group per second.
The low-level Java API provides a Query class for constructing queries and a PreparedQuery class for fetching and returning the entities that match the query from the datastore. The code that fetches the data is here:



Query query = new Query("Greeting", guestbookKey).addSort("date",Query.SortDirection.DESCENDING);
   List<Entity> greetings = datastore.prepare(query).asList(FetchOptions.Builder.withLimit(10));
follow this link:
https://appengine.google.com/->newapps6974(my app name)->datastore indexes
in the datastore indexes you will see the entity name and indexes.refer to the datastore-indexes,xml file now and see the matching.
see the datastore viewer.you will see the mesages in the descending order(datewise)).awesome.

working for the first time with google appengine

today i learnt to run a web project under google app engine from my eclipse ide with the help of google appengine plugins
the encircled area denotes the google plugins.
now to create a new project u click the bluish g icon..and do the needful.
the project is deployed by the deploy app engine project
 after deploying u run it as a run-as web application
my url-http://newapps6974.appspot.com/

references:-http://www.mkyong.com/google-app-engine/google-app-engine-hello-world-example-using-eclipse/

Wednesday, April 11, 2012

The day i started using frameworks

it took some time while getting acquainted with hibernate.but no matter what it was easy learning.
why hibernate?
The developers get rid of writing complex SQLs and no more need of JDBC APIs for resultset handling.
x.cfg.xml file provides  the connection with database.
Y.hbm.xml provides mapping between database column and POJO variable.
A simple web app test to know the basics.

remember to create a database connection on the back end and then select that when you open a new project to execute
the code can be downloaded from 
http://www.mediafire.com/?lw5pvhxpfwx5xr9

hibernate.cfg.xml file


<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
    <session-factory>
        <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
        <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
        <property name="hibernate.connection.url">jdbc:mysql://localhost:3306/hibernatetutorial</property>
        <property name="hibernate.connection.username">root</property>
        <property name="hibernate.connection.password">root</property>
        <property name="hibernate.connection.pool_size">10</property>
        <property name="hibernate.cache.provider_class">org.hibernate.cache.NoCacheProvider</property>
        <property name="hibernate.hbm2ddl.auto">update</property>
        <mapping resource="entities/Subscriber.hbm.xml"/>
    </session-factory>
</hibernate-configuration>

Subscriber.hbm.xml


<?xml version="1.0" encoding="UTF-8"?>


<!DOCTYPE hibernate-mapping PUBLIC
  "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
  "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">


<hibernate-mapping>
    <class name="entities.Subscriber" table="test">
        <id name="uname" type="java.lang.String">
            <column name="username" />
            <generator class="assigned"/>
        </id>
        <property name="pwd" type="java.lang.String">
            <column name="password"/>
        </property>
    </class>
  


</hibernate-mapping>


create a jsp page .pass the login and password say through a form into a servlet.create a getter setter class with the instance variables that are to be used to insert data in a database..these are mapped to column names in the Y.hbm.xml file

the servlet file

 protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        // TODO Auto-generated method stub
        PrintWriter out = response.getWriter();
        String uname = request.getParameter("uname");
        String pwd = request.getParameter("pwd");
        System.out.println("inside the servlet");
        try {
            SessionFactory sf = new Configuration().configure().buildSessionFactory();
            Session s = sf.openSession();
            Subscriber sub = new Subscriber();
            sub.setUname(uname);
            sub.setPwd(pwd);
            s.beginTransaction();
            s.save(sub);
            s.getTransaction().commit();
            s.close();
            sf.close();
            out.println(
                    "<h3 >[" + uname + "  ] has been registered successfully!</h3 >");
        } catch (Exception ex) {
            out.println(
                    "<h3 >[" + uname + "] could NOT be registered!</h3 >");
            System.out.println(ex.getMessage());
        }
    }

Sunday, February 26, 2012

FileUpload using jersey

today i learnt to implement file uploading using jersey

@Path("fileupload")
public class FileUploadResource {

@POST
@Produces("text/plain")
public String loadFile(@Context HttpServletRequest request) {
String resultStatus="fail";
String fileRepository="d:\\"; //the files u choose to upload will be uploaded to this d. directory
//servlet file upload handles multiple files in a html widget

if (ServletFileUpload.isMultipartContent(request)) {//checks if the servlet request contains multipart data.
FileItemFactory factory = new DiskFileItemFactory();
ServletFileUpload upload = new ServletFileUpload(factory);
List<FileItem> items=null;
try {
items = upload.parseRequest(request);
} catch (FileUploadException e) {

e.printStackTrace();
}
if(items!=null) {
Iterator<FileItem> iter = items.iterator();
while (iter.hasNext()) {
FileItem item = iter.next();
    if(!item.isFormField() && item.getSize() > 0) {
    String fileName = processFileName(item.getName());
    try {
item.write(new File(fileRepository+fileName));
//the write methodn writes uploaded file into the disk
} catch (Exception e) {
e.printStackTrace();
}
        resultStatus="ok";
    }
}
}
}
return resultStatus;
}

private String processFileName(String fileNameInput) {
String fileNameOutput=null;
fileNameOutput = fileNameInput.substring(fileNameInput.lastIndexOf("\\")+1,fileNameInput.length());
//extracts the name of the file
return fileNameOutput;
}
ur file will be uploaded to the directory