Monday, October 14, 2013

Understanding Maven Concepts


  • Maven builds are controlled by Project Object Model (POM) files.  POM files, unlike Ant scripts, describe the project. A POM file doesn’t have code or task steps, it just describes the structure of the project .
  • Maven manages dependencies between projects.
  • If your project needs a jar file like Log4J, then add dependency to your POM file and Maven will automatically fetch that jar file and make it available while compilation .
  • When your own code is compiled and stored by Maven, it also has to have a version number. Version numbers with ‘SNAPSHOT’ in them are special. They’re “work-in-progress” code. Maven breaks components into ‘releases’ and ‘snapshots’. It won’t allow you to store components that have snapshot version numbers as releases.


If Project Structure  is  having "Standard Directory Layout" i.e.

/src
  /main
    /java - All your Java source files, e.g., /com/mycompany/Main.java
    /resources - Resource files that need to end up in the project JAR
    /webapp - Web files if you’re building a WAR
  /test
    /java - All your test Java source files
    /resources - Resource files needed for testing
/target - Everything generated by the build, include the JAR/WAR file

Then your POM file would look like this:


groupId will identify your project uniquely across all projects, so we need to enforce a naming schema. It has to follow the package name rules, what means that has to be at least as a domain name you control, and you can create as many subgroups as you want

artifactId is the name of the jar without version ,The name of the artifact the project creates .

version if you distribute it then you can choose any typical version with number ,  The version number of the artifact created

  • So, in our above example, the final JAR file for our project would be ‘my-project.jar’ but it would be registered with Maven as com.mycompany.my-project.
  • Version numbers with ‘SNAPSHOT’ in them are special. They’re “work-in-progress” code  .
  • Maven breaks components into ‘releases’ and ‘snapshots’


Some common goals:
  1. clean remove any old build files
  1. compile compile the code
  1. test compile the code and run the unit tests
  2. package compile and test the code and create any build products
  3. site generate site documentation


  • Maven components are stored in repositories(like nexus ). You can define as many repositories as you like, but you can’t install your own JAR files
  • Each developer also has their own “local” repository. The local repository is just a set of directories on each developer’s machine (located under ‘.m2’ in the user’s home directory). When Maven downloads components from repositories they are stored locally. Developers can also install components directly into the local repository
  • When you start adding dependencies to your POM files, Maven will attempt to locate them in one of it’s repositories and then download them to the local repository.
  • This POM file will cause Maven to download the Log4J 1.2.13 component and make it available on the classpath while compiling the code. If you were creating a WAR file, EAR file, etc. it would also copy the jar file into the ‘lib’ directory of the final package.
  • optionally, give them a scope. The scope tells Maven whether the dependency is only necessary when testing the code or only necessary to compile but not for packaging.

  • When you’re working in a team, you need to be able to share your custom components between team members.
(By Sona Type)

Wednesday, October 9, 2013

Understanding web service in simple words


What is a Web Service ? :
  • A webservice is a software function provided at a network address over the web
  • It is supposed to be "always on"
  • Web services are really nothing more than a request/ response mechanism that allows a client to remotely access/ modify data.

Types of Web Services :

  1. Big Web Services  (Basically StateFull)
( JAX-WS provides the functionality for “big” web services )
  • Big web services use XML messages that follow the Simple Object Access Protocol (SOAP) standard.



A SOAP-based design must include the following elements.

  • A formal contract ,WSDL can be used to describe the details of the contract .
  • The architecture must address complex nonfunctional requirements .
Examples include transactions, security, addressing, trust, coordination, and so on. For More on JAX-WS Refer this link 

Basic Component of State Full Webservices

What is WSDL?
  •  Web Services Description Language
  • based on XML
  • describe Web services
  • locate Web services

What is SOAP?
  • Simple Object Access Protocol
  • format for sending messages
  • platform independent
  • based on XML

What is UDDI?
UDDI is a directory service where companies can register and search for Web services.



 2)  RESTful Web Services (Stateless)
         (  JAX-RS provides the functionality for Representational State Transfer (RESTful) web services  )
         
REST is well suited for basic, ad hoc integration scenarios. RESTful web services, often better integrated with HTTP than SOAP-based services are, do not require XML messages or WSDL service–API definitions .
developing RESTful web services is inexpensive .

Appropriate for  following conditions .

  1. The web services are completely stateless (A stateless server is a server that treats each request as an independent transaction that is unrelated to any previous request.) A good test is to consider whether the interaction can survive a restart of the server.
  1. A caching infrastructure can be leveraged for performance. If the data that the web service returns is not dynamically generated and can be cached.
  2. producer and service consumer have a mutual understanding of the context and content being passed along.

Tuesday, October 8, 2013

Learn JAX WS in Few Seconds..

Implementing web service Endpoint/Client with JAX WS

Developing Web Service End Point
1) In Eclipse  create a java project "JAXWS-Server".
2) Create JAXWS-Service Endpoint Interface:

--------------------------------------------------------------------------
package mysimple.example.define;
import javax.jws.WebMethod;
import javax.jws.WebService;

@WebService
public interface Greeting {
@WebMethod String sayHello(String name);
}
-------------------------------------------------------------------------- 

3) Create JAXWS-Service Endpoint Implementation class:

-------------------------------------------------------------------------- 
package mysimple.example.define;
import javax.jws.WebService;

@WebService(endpointInterface = "mysimple.example.define.Greeting")
public class GreetingImpl implements Greeting  {

@Override
public String sayHello(String name) {
return "Hello, This is simplest JAX-WS example By :: " + name;
}
}
--------------------------------------------------------------------------  

4) Create Endpoint Publisher class:

-------------------------------------------------------------------------- 
package mysimple.example.publish;
import javax.xml.ws.Endpoint;

import mysimple.example.define.GreetingImpl;

public class WSPublisher {
public static void main(String[] args) {
Endpoint.publish("http://localhost:8080/WS/Greeting",new GreetingImpl());
}
}
-------------------------------------------------------------------------- 

5) Run the WSPublisher….and your WebService is published.


Developing Web Service Client :

1) In eclipse create a new java project JAXWS-Client
2) we need to generate the client stubs by following command(on the src path)

Command : wsimport -keep -verbose http://localhost:8080/WS/Greeting?wsdl


  1. Remove all the class files
  2. Create the  Client Class which will be dependent on the stubs

-------------------------------------------------------------------------- 
package mysimpleexample.client;
import mysimple.example.define.Greeting;
import mysimple.example.define.GreetingImplService;



public class Client {
public static void main(String[] args){

GreetingImplService service = new GreetingImplService();
Greeting greeting = service.getGreetingImplPort();
System.out.println("------->>  Call Started");
System.out.println(greeting.sayHello("Manish_Kumar_Jaiswal"));
System.out.println("------->>  Call Ended");
}
}
-------------------------------------------------------------------------- 

  1. Output :

------->>  Call Started
Hello, This is simplest JAX-WS example By :: Manish_Kumar_Jaiswal
------->>  Call Ended