Welcome to Java4u

A Single Place for all Java Resources

Looking for something?

Subscribe to this blog!

Receive the latest posts by email.

.Just enter your email below if you want to subscribe!

Email

OAuth 2.0

OAuth 2.0 is an open authorization framework and mainly focuses on authorization flows fand secures access to many well-known web APIs.

Java 8 features

The key features of JDK 8 are Project Lambda (JSR 335), the Nashorn JavaScript Engine, a new Date and Time API (JSR 310), a set of Compact Profiles and the removal of the "permanent generation" from the HotSpot Java Virtual Machine (JVM). A complete list of the new features and capabilities of JDK 8 is available.

Lambda Expression

A lambda expression represents an anonymous function. It comprises of a set of parameters, a lambda operator (->) and a function body.

SOAP vs RESTful

SOAP : Web service use XML messages that follow the Simple Object Access Protocol (SOAP) standard.
RESTful : Web service, often better integrated with HTTP than SOAP-based services are, do not require XML messages or WSDL service–API definitions.

Softwares Engineering / SDLC

Software engineers apply the principles of engineering to the design, development, maintenance, testing, and evaluation of the software and systems that make computers or anything containing software work.

Showing posts with label WebServices. Show all posts
Showing posts with label WebServices. Show all posts

Tuesday, June 17, 2014

JAX-RS

Java API for RESTful Web Services (JAX-RS), is a set if APIs to developer REST service. JAX-RS is part of the Java EE6 and higher, and make developers to develop REST web application easily.
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. 
Project Jersey is the production-ready reference implementation for the JAX-RS specification. Jersey implements support for the annotations defined in the JAX-RS specification, making it easy for developers to build RESTful web services with Java and the Java Virtual Machine (JVM).
In this series of JAX-RS tutorials, we use both Jersey and RESTEasy, popular JAX-RS implementation.
Because RESTful web services use existing well-known W3C and Internet Engineering Task Force (IETF) standards (HTTP, XML, URI, MIME) and have a lightweight infrastructure that allows services to be built with minimal tooling, developing RESTful web services is inexpensive and thus has a very low barrier for adoption. You can use a any development tool for developing Restful web services

Rest Full Web service API Design frame work



Annotations
@Path :
  1. It is used when we build a new class or when we use an method in a inner class.
  2. Responsible for routing the HTTP request to the proper method or class.
  3. This annotation can also be used with @PathParam annotation.
  4. Identifies the URL Path that java class will respond.
    1. E.g.: @Path (“/v1/message”)
    2. E.g.:@Path (“/v1/message/ {msg}”) (for @PathParam).
  5. Different Annotations @GET, @POST, @PUT, @DELETE, @HEAD
    1. @GET: mostly used to read and access the public methods.
    2. @POST: used to insert add / delete data or to submit data like login pages with HTTPS we can secure the data.
    3. @PUT: used for updating data mostly used for inserting/ adding the data.
    4. @DELETE: used delete the data.
    5. @HEAD: used to return meta-data for resource.
NOTE : we use only one for each method.
Mapping jersey annotations to the HTTP methods

@Produces :
  1. @Produces specify the media type that a method will produce and send back to the client.
  2. When you see @Produces at the class level, it treated as a default.
  3. When used with @Produces at  methods, it becomes a require to access that method.
  4. You can also define more than one for specific method.
  5. It does do some encoding but nothing extensive.
  6. you can define your own MediaType  as seen below
          E.g. : @Produces(MediaType.TEXT_HTML)
                            Or
                  @Produces(“text/html”)

If we need to send data to servers we have two ways to send it
  1. we can send it part of URL String by using URL Parameters
  2. we can send through the body of HTTP Request.
@Consumes :

  1. Annotation specifies where it is going to look for the data, and also what type of data it was.
  2. It is easy better to send data in the body, but if u use  something like get request than u can only use URL Parameters and we can also define our own consume types.
  3. For Eg.. with (pre-defined media types)
@Post
@Consumes(MediaType.APPLICATION_FORM_URLENCODE)
Public void saveMessage(String msg){
/*…..*/       //body
}

WebService Introduction

Web Service : A service that is made available over the web/network & accessible over the network.
And a service that is accessible/ provided over online/network that come under web service
E.g.: In Social Media Web Site we use that service to interact with friends, or in commerce web sites we use the service to purchase products.
So we can call them as web services

Difference b/w standard website & a web service?

Web Site is meant for human consumption.
Web Service is meant for code/application level consumption.

There are primarily two different types of web services
1) SOAP Web service
2) REST Web service

When coming to SOAP its older one and REST is new entry in web service world
Here we have 2 Specifications in Java World
1. JAX-WS is the specification for SOAP web service.
2. JAX-RS is the specification for REST web service.

Friday, June 13, 2014

SOAP vs REST


SOAP : Great at Asynchronous processing and invocation, Formal contracts, Stateful operations
REST : Limited bandwidth and resources, Totally stateless operations, Caching situations





SOAP

  • SOAP stands for Simple Object Access Protocol. REST stands for REpresentational State Transfer.
  • SOAP is a XML based messaging protocol and REST is not a protocol but an architectural style.
  • SOAP has a standard specification but there is none for REST.
  • Whole of the web works based on REST style architecture. Consider a shared resource repository and consumers access the resources.
  • Even SOAP based web services can be implemented in RESTful style. REST is a concept that does not tie with any protocols.
  • SOAP is distributed computing style and REST is web style (web is also a distributed computing model).
  • REST messages should be self-contained and should help consumer in controlling the interaction between provider and consumer(example, links in message to decide the next course of action). But SOAP doesn’t has any such requirements.

REST 

  •  REST does not enforces message format as XML or JSON or etc. But SOAP is XML based message protocol.
  • REST follows stateless model. SOAP has specifications for stateful implementation as well.
  • SOAP is strongly typed, has strict specification for every part of implementation. But REST gives the concept and less restrictive about the implementation.
  • herefore REST based implementation is simple compared to SOAP and consumer understanding.
  •  SOAP uses interfaces and named operations to expose business logic. REST uses (generally) URI and methods like (GET, PUT, POST, DELETE) to expose resources.
  • SOAP has a set of standard specifications. WS-Security is the specification for security in the implementation. It is a detailed standard providing rules for security in application implementation. Like this we have separate specifications for messaging, transactions, etc.
  • Unlike SOAP, REST does not has dedicated concepts for each of these. REST predominantly relies on HTTPS.
  •  Above all both SOAP and REST depends on design and implementation of the application.



Areas where SOAP based Web Services is a great solution:


Asynchronous processing and invocation: If application needs a guaranteed level of reliability

and security then SOAP 1.2 offers additional standards to ensure this type of operation. Things like

WSRM – WS-Reliable Messaging etc.



Formal contracts: If both sides (provider and consumer) have to agree on the exchange format

then SOAP 1.2 gives the rigid specifications for this type of interaction.



Stateful operations: If the application needs contextual information and conversational state

management then SOAP 1.2 has the additional specification in the WS* structure to support those things (Security, Transactions, Coordination, etc). Comparatively, the REST approach would make the developers build this custom plumbing.

Areas where Restful Web Services are a great choice:

Limited bandwidth and resources: Remember the return structure is really in any format
(developer defined). Plus, any browser can be used because the REST approach uses the standard GET, PUT, POST, and DELETE verbs. 
Again, remember that REST can also use the XMLHttpRequest object that most modern browsers support today, which adds an extra bonus of AJAX.

Totally stateless operations: If an operation needs to be continued, then REST is not the best
approach and SOAP may fit it better. However, if you need stateless 
CRUD (Create, Read, Update,and Delete) operations, then REST is suitable.

Caching situations: If the information can be cached because of the totally stateless operation of the REST approach, this is perfect.




SOAP vs REST



Click on the link to Download or Watch

SOAP vs REST

WSDL Explaination



Click on the link to Download or Watch


WSDL Explaination

Tuesday, June 10, 2014

Apache Axis2 videos



Click on the links to Download or Watch

  1.  Apache Axis2 WebService Part 1
  2.  Apache Axis2 WebService Part2