Wednesday, March 20, 2019

T6

1. Compare and contrast Message oriented communication with resource oriented communication 

Advantages

Asynchronous Messaging
Message-oriented middleware comprises a category of inter-application communication software that usually relies on asynchronous message-passing, as opposed to a request-response architecture. In case of asynchronous systems, message queues provide temporary storage when the destination program is busy or unable to get connected. Apart from this, most asynchronous MOM systems provide persistent storage to back up the message queue which means sender and receiver does not necessarily connect to the network at the same time (asynchronous delivery), and problems with irregular connectivity are also solved. If the receiver application fails for any reason, the senders can continue uninterrupted, as messages which are sent will automatically accumulate in the message queue for processing when the receiver restarts.

Routing
Many message-oriented middleware implementations depend on a message queue system. Most implementations have routing logic provided by the messaging layer itself, while very few depend on client applications to provide routing information or allow both paradigms. Some implementations make use of broadcast or multicast distribution paradigms.

Transformation
In a message-based middleware system, the message received at the destination need not be identical to the message originally sent. A MOM system with built-in intelligence can transform messages en route to match the requirements of the sender or of the recipient. In conjunction with the routing and broadcast/multicast facilities, one application can send a message in its own native format, and two or more other applications may each receive a copy of the message in their own native format. Many modern MOM systems provide sophisticated message transformation (or mapping) tools which allow programmers to specify transformation rules applicable to a simple GUI drag-and-drop operation.

Disadvantages
The primary disadvantage of many message-oriented middleware systems is that they require an extra component in the architecture, the message transfer agent (message broker). As with any system, adding another component can lead to reductions in performance and make the system as a whole more difficult and expensive to maintain.  When introduced due to lack of standards governing the use of message-oriented middleware has caused problems. Most of the major vendors have their own implementations, each with its own application programming interface (API) and management tools.

MOM - Implementation
The message queue is a fundamental concept within MOM. Queues provide the ability to store messages on a MOM platform. MOM clients are able to send and receive messages to and from a queue. Queues are central to the implementation of the asynchronous interaction model within MOM. Usually the messages contained within a Queue is sorted in a particular order. The standard queue found in a messaging system is the First-In First-Out (FIFO) queue; as the name suggests, the first message sent to the queue is the first message to be retrieved from the queue. Many attributes of a queue can be configured. These include the queue’s name, queue’s size, the save threshold of the queue, message-sorting algorithm etc. Typically each application may have its own queue, or applications may share a queue, there is no restriction on the set-up. MOM platforms support multiple queue types for different purposes.

MOM - Messaging Models
A solid understanding of the available messaging models within MOM is key to appreciate the unique capabilities it provides. Two main message models that are commonly available, the point-to-point and publish/subscribe models. Both of these models are based on the exchange of messages through a channel (queue). A typical system will utilize a mix of these models to achieve different messaging objectives.

Point-to-Point Model
The point-to-point messaging model provides a straightforward asynchronous exchange of messages between software entities. In this model, messages from producing clients are routed to consuming clients via a queue. As discussed earlier, the most common queue used is a FIFO queue, in which messages are sorted in the order. While there is no restriction on the number of clients who can publish to a queue, there is usually only a single consuming client, although this is not a strict requirement. The model allows multiple receivers to connect to the queue, but only one of the receivers will consume the message. The techniques of using multiple consuming clients to read from a queue can be used to easily introduce smooth, efficient load balancing into a system. In the point-to-point model, messages are always delivered and will be stored in the queue until a consumer is ready to retrieve them.

Publish/Subscribe Model
The publish/subscribe messaging model, is a mechanism used to disseminate information between anonymous message consumers and producers. These one-to-many and many-to-many distribution mechanisms allow a single producer to send a message to one user or potentially hundreds of thousands of consumers. In the publish/subscribe (pub/sub) model, the sending and receiving application is free from the need to understand anything about the target application. It only needs to send the information to a destination within the publish/subscribe engine. The engine will then send it to the consumer. Clients producing messages “publish” to a specific topic or channel, these channels are then “subscribed” to by clients wishing to consume messages. The service routes the messages to consumers on the basis of the topics to which they have subscribed as being interested in. Within the publish/subscribe model, there is no restriction on the role of a client; a client may be both a producer and consumer of a topic/channel.

2. Discuss the resource based nature of the REST style 

•Things vs Actions 
•Nouns vs Verbs 
•Identified by URIs
•Multiple URIs may refers to same resource
•Separate from their representations 

3. Explain the meaning of “representations” in REST style

It means REST architecture could have multi level cache at client and server ends. ... Resource — There must be resources with their unique resource identifier i.e. unique url in REST APIs. Representations — Representation is the value/response of the Resource at a point in time based on the media-type.

•Typically JSON or XML
      •Or even can be a web page, file, image, etc…

•E.g. The state of a student (as per the database) can be represented by a resource of webpage, XML dataset, etc…

 4. Discuss the constraints of REST, indicating their use in the domain of web

Constraint #1: Client-Server Architecture
The first constraint proposed by REST is the separation of the server from its client. You should encourage separation of concerns between your server and clients wherever possible. Your goal should be to maximize the division of labor — and minimize overlap — between the two.
The server, or back end, is typically responsible for storing your application’s persistent data, along with all the business logic required to interact with it. This could include user authentication, authorization, data validation, and so on.


Constraint #2: Statelessness
The next important constraint proposed by REST is that of statelessness.
Broadly speaking, the main goal of a stateless service is to make incoming requests self-sufficient, and execute them in complete isolation.
Each request must have all the information that the server might need to properly process it and respond. In other words, the server does not need to use information from previous requests. The responsibility of maintaining the application state of a client is thus handed off to the client itself.


Constraint#3: Cache
The third constraint is that of explicit cacheability. The idea is to mark messages returned by a service as explicitly cacheable or non-cacheable. If they’re cacheable, the server should figure out the duration for which the response is valid.
If the client has access to a valid cached response for a given request, it avoids repeating the same request. Instead, it uses its cached copy. This helps alleviate some of the server’s work, and thus contributes to scalability and performance.
This is a form of optimistic replication — also known as lazy replication — where the service does not try to guarantee 100% consistency between itself and its clients unless absolutely critical. Instead, it makes this sacrifice in exchange for a gain in perceived performance.


5. Identify contemporary examples of different types of implementations for the elements of REST style
As stated earlier in the previous article of REST , the REST style is an abstraction of the architectural elements within a distributed hypermedia system. REST distinguishes three classes of architectural elements, they are:


          1. Components
          2. Connector
          3. Data
       
Components


In REST, the various software that interacts with one another are called components. They are categorized by roles summarized in the table below:
Component RoleDescriptionExample
Origin ServerUses a server connector to receive the request, and is the definitive source for representations of its resources. Each server provides a generic interface to its services as a resource hierarchy.Apache httpd, Microsoft IIS
User AgentUses a client connector to initiate a request and becomes the ultimate recipient of the response.Browser like Netscape Navigator etc
GatewayAct as both, client and server in order to forward - with possible translation - requests and responses.Squid, CGI, Reverse Proxy
ProxyCERN Proxy, Netscape Proxy, Gauntlet

Connector


Connectors represent the activities involved in accessing resources and transferring representations. Roles provide an interface for components to implement. REST encapsulates different activities of accessing and transferring representations into different connector types. The table below summarizes the connector types:
Connector TypeDescriptionExample
ClientSending requests, receiving responses.HTTP library
ServerListening for requests, sending responses.Web Server API
CacheCan be located at the client or server connector to save cacheable responses, can also be shared between several clientsBrowser cache
ResolverTransforms resource identifiers into network addresses.bind (DNS lookup library)
TunnelRelays requests, any component can switch from active behavior to a tunnel behavior.SOCKS, SSL after HTTP CONNECT

Data


The key aspect of REST is the state of the data elements, its components communicate by transferring representations of the current or desired state of data elements. REST identifies six data elements: a resource, resource identifier, resource metadata, representation, representation metadata, and control data, shown in the table below:
Data ElementDescriptionExample
ResourceAny information that can be named is a resource. A resource is a conceptual mapping to a set of entities not the entity itself. Such a mapping can change over time. In general, a RESTful resource is anything that is addressable over the Web.Title of a movie from IMDb, A Flash movie from YouTube, Images from Flickr etc
Resource IdentifierEvery resource must have a name that uniquely identifies it. Under HTTP these are called URIs. Uniform Resource Identifier (URI) in a RESTful system is a hyperlink to a resource. It is the only means for clients and servers to exchange representations of resources.The relationship between URIs and resources is many to one. A resource can have multiple URIs which provide different information about the location of a resource.Standardized format of URI:scheme://host:port/path?queryString#fragmente.g:http://some.domain.com/orderinfo?id=123
Resource metadataThis describes the resource. A metadata provides additional information such as location information, alternate resource identifiers for different formats or entity tag information about the resource itself.Source link, vary
RepresentationIt is something that is sent back and forth between clients and servers. So, we never send or receive resources, only their representations. A representation captures the current or intended state of a resource. A particular resource may have multiple representationsSequence of bytes, HTML document, archive document, image document
Representation metadataThis describes the representation.Headers (media-type)
Control dataThis defines the purpose of a message between components, such as the action being requested.If-Modified-Since, If-Match

 6. Explain how to define the API of RESTful web services using RESTful URLs 
Building RESTful web services, like other programming skills is part art, part science. As the Internet industry progresses, creating a REST API becomes more concrete with emerging best practices. As RESTful web services don't follow a prescribed standard except for HTTP, it's important to build your RESTful API in accordance with industry best practices to ease development and increase client adoption.

Presently, there aren't a lot of REST API guides to help the lonely developer. RestApiTutorial.com is dedicated to tracking REST API best practices and making resources available to enable quick reference and self education for the development crafts-person. We'll discuss both the art and science of creating REST Web services
7. Discuss the pros and cons of using MVC for RESTful web service development, indicating the application of MVC in RESTful web service design 
Difference between MVC and Web API

There are many differences between MVC and Web API, including:

We can use the MVC for developing  the Web application that replies as both data and views but the Web API is used for generating the HTTP services that replies only as data.
In the Web API the request performs tracing with the actions depending on the HTTP services but the MVC request performs tracing with the action name.
The Web API returns the data in various formats, such as JSON, XML and other format based on the accept header of the request. But the MVC returns the data in the JSON format by using JSONResult.
The Web API supports content negotiation, self hosting. All these are not supported by the MVC.
The Web API includes the various features of the MVC, such as routing, model binding but these features are different and are defined in the "System.Web.Http" assembly. And the MVC features are defined in the " System.Web.Mvc" assembly.
The Web API helps the creation of RESTful services over the .Net Framework but the MVC does not support.

8.Discuss the JAX-RS API and its implementations 

JAX-RS: Java API for RESTful Web Services (JAX-RS) is a Java programming language API spec that provides support in creating web services according to the Representational State Transfer (REST) architectural pattern. JAX-RS uses annotations, introduced in Java SE 5, to simplify the development and deployment of web service clients and endpoints.



difference between Jersey and JAX RS
JAX-RS is an specification (just a definition) and Jersey is a JAX-RS implementation. Jersey framework is more than the JAX-RS Reference Implementation. Jersey provides its own API that extend the JAX-RS toolkit with additional features and utilities to further simplify RESTful service and client development 

9. Identify the annotations in JAX-RS, explaining their use 
Annotations in the JAX-RS API are used to provide meta-data around the web resource. A typical example is to use the @GET annotation with the @Path annotation to identify the method that should handle a GET request to the specified URI in the @Path annotation.

The @Path Annotation

Next, comes the URI path to the resource. In a bookshop application, this might be /books/.


@Path("/books")
public class BookResource {}

The @GET HTTP Method Annotation

Methods annotation with the @GET annotation respond to HTTP get requests.
@GET
@Produces(MediaType.APPLICATION_JSON)
public Response getAllBooks() {
    List<Book> books = BookRepository.getAllBooks(); // queries database for all books
    GenericEntity<List<Book>> list = new GenericEntity<List<Book>>(books) {};
    return Response.ok(list).build();
}

The @PUT HTTP Method Annotation

The @PUT annotation is used for updating a record and method annotated this way respond to an HTTP PUT request.


@PUT
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response updateBook(Book book) {
    book = bookRepository.updateBook(book);
    return Response.ok(book).build();
}

The @DELETE HTTP Method Annotation

Methods annotated @DELETE are expected to delete a resource.
@DELETE
@Path("{isbn}")
@Produces(MediaType.APPLICATION_JSON)
public Response deleteBook(@PathParam("isbn") String isbn) {
    Book book = bookRepository.deleteBookByIsbn(isbn);
    return Response.ok(book).build();
}


Usually, the resource or its id is passed to the resource method parameter from the URI variable as you can see in this example.

10. Explain the use and importance of “media type” in JAX-RS 


@Consumes and @Produces


All resource methods can consume and produce content of almost any type. If you make a POST request to a URI, such as api/books, the REST API expects the HTTP body to contain a payload that represents the resource it should create.
This resource can be represented using any media type. Although typically, it will be represented in either, JSON or XML, but it could be plain text, binary or a custom format. It doesn’t matter, as long as there is a method in the resource class that can consume that media type.


Friday, March 15, 2019

t-5

1. Compare and contrast web applications with web services, indicating the need for web services. 
web applications
Web applications are defined by being interactive. You're supposed to use a web application in order to perform a function and use some of the web applications features. Lots of web applications don't even have real informative content or data exactly. People are just supposed to use them in order to perform additional tasks, using their features to accomplish something. You use a web application to check your incoming messages, for instance, or play a game.


web services
Web service is a technology by which two or more remote web applications interact with each other over network/internet. It can be implemented using Java, .net, PHP etc. Web pages allow people to communicate and collaborate with each other while web services allow programs to communicate and collaborate with each other.


2. Discuss what WSDL is and the use of it in the context of web services. 

WSDL is an XML-based standard for describing a web service. A WSDL document describes the available functions of a web service, their expected arguments, and the data types for their return values. WSDLs are used by developers of client applications that consume XML-based web services.
                  
3. Explain the fundamental properties of a WSDL document and the use of WSDL document in web services and client development. 
web services and client 
WSDL is often used in combination with SOAP and XML Schema to provide web services over the Internet. A client program connecting to a web service can read the WSDL to determine what functions are available on the server. Any special datatypes used are embedded in the WSDL file in the form of X

4. Discuss the structure of the WSDL document , explaining the elements in WSDL. 

WSDL document has a definitions element that contains the other five elements, types, message, portType, binding and service. The following sections describe the features of the generated client code. WSDL supports the XML Schemas specification (XSD) as its type system.
                   
5. Compare the PortType and operation elements in WSDL with the java equivalences. 
PortType 
The WSDL portType element defines a group of operations (sometimes known as an interface). The WSDL binding element describes the concrete details of using a particular portType with a given protocol. An abstract set of operations supported by one or more endpoints.



operation elements
WSDL Document Structure. Services are defined using six major elements: ... binding, which specifies concrete protocol and data format specifications for the operations and messages defined by a particular portType. port, which specifies an address for a binding, thus defining a single communication endpoint.

6. Compare and contrast the binding and service elements in WSDL. 

Binding
WSDL Binding to SOAP. WSDL bindings defines the message format and protocol details for a web service. The binding element has two attributes - name and type. ... The soap:binding element has two attributes - style and transport.

Service elements
<types>
Defines the (XML Schema) data types used by the web service
<message>
Defines the data elements for each operation
<portType>
Describes the operations that can be performed and the messages involved.
<binding>
Defines the protocol and data format for each port type

7. Explain how SOAP is used with HTTP. 
SOAP is an integral part of the service-oriented architecture and the Web services specifications associated with SOA. Because it allows the sender to create a message route based on the logical services that have to be applied to the message on the way to its destination, it lends itself to providing secure and compliant connections, controlling access, offering reliable delivery and failure recovery, and supporting dynamic service discovery. SOA without SOAP is difficult to imagine.
SOAP’s messages are defined at a high level in XML, but most SOAP applications use Web Services Definition Language (WSDL), which is authored in XML.  The XML structure of SOAP makes it handy for applications that expect their information to be provided in XML form, and the fact that SOAP can ride on a variety of network protocols, including HTTP, means it’s easily passed through firewalls, where other protocols might require special accommodation.
The data structure of SOAP is based on XML, which is similar in many ways to the HTML used to define web pages. Like HTML, XML is largely human-readable, which makes it fairly easy to understand a SOAP message, but also makes the messages relatively large in comparison to the Common Object Request Broker Architecture  and its Remote Procedure Call protocol that will accommodate binary data.
8.Discuss how SOAP can be used for functional oriented communication? 
SOAP ( Simple Object Access Protocol) is a message protocol that allows distributed elements of an application to communicate. SOAP can be carried over a variety of lower-level protocols, including the web-related Hypertext Transfer Protocol .  SOAP defines a header structure that identifies the actions that various SOAP nodes are expected to take on the message, in addition to a payload structure for carrying information. The concept of routing a message through a string of nodes that perform different functions is how SOAP supports things like addressing, security and format-independence. Essentially, the headers identify roles, which in turn provide the SOA features which SOAP then routes to. Stringing messages through a sequence of steps is uncommon in today’s micro service-centric development environments.

9. Explain the structure of SOAP message in message oriented communication, indicating the elements used. 

SOAP is intended to be a simple yet powerful extensible protocol for distributed messaging based on XML. A key element of SOAP is its concept of having a message envelope and a set of headers. The envelope contains the message body that can be XML data or parameters and is intended for the recipient.

In this example, a Get Last Trade Price SOAP request is sent to a Stock Quote service. The request takes a string parameter, ticker symbol, and returns a float in the SOAP response. The SOAP Envelope element is the top element of the XML document representing the SOAP message. XML namespaces are used to disambiguate SOAP identifiers from application specific identifiers. 


Example 1 SOAP Message Embedded in HTTP Request
        
10. Discuss the importance of the SOAP attachments, explaining the MIME header.

This document defines a SOAP feature that represents an abstract model for SOAP attachments. It provides the basis for the creation of SOAP bindings that transmit such attachments along with a SOAP envelope, and provides for reference of those attachments from the envelope.
                            

11. Identify different set of frameworks /libraries for SOAP web service development, in different environments (Java, .Net, PHP, etc…). 
Java
WS-Reliable Messaging, WS-Security, WS- Atomic Transaction, WS-Addressing, MTOM, WS-Policy, WS-Metadata Exchange

.Net
WS-Addressing, WS-Metadata Exchange, WS-Security, WS-Policy, WS-Security Policy, WS-Trust, WS-Secure Conversation, WS-Reliable Messaging, WS-Coordination, WS-Atomic Transaction,WS-Discovery

PHP
SOAP MTOM, WS-Addressing, WS-Security, WS-Security Policy, WS-Secure Conversation, WS-Reliable Messaging

C and C++
WS-Addressing, WS-Discovery, WS-Policy, WS-Reliable Messaging, WS-Security, WS-Security Policy.

12. Explain the annotations in JAX-WS, providing examples of their use. 

The starting point for developing a JAX-WS web service is a Java class annotated with the javax.jws.WebService annotation. The Web Service annotation defines the class as a web service endpoint.
service endpoint interface  is a Java interface that declares the methods that a client can invoke on the service. An SEI is not required when building a JAX-WS endpoint. The web service implementation class implicitly defines a SEI.
You may specify an explicit SEI by adding the endpoint Interface element to the WebService annotation in the implementation class. You must then provide a SEI that defines the public methods made available in the endpoint implementation class.
You use the endpoint implementation class and the wsgen tool to generate the web service artifacts and the stubs that connect a web service client to the JAX-WS run time. For reference documentation on wsgen, see the Application Server man pages at .
Together, the wsgen tool and the Application Server provide the Application Server's implementation of JAX-WS.
These are the basic steps for creating the web service and client:

  1. Code the implementation class.

  2. Compile the implementation class.

  3. Deploy the WAR file. The tie classes (which are used to communicate with clients) are generated by the Application Server during deployment.

  4. Code the client class.

  5. Use ws import to generate and compile the stub files.

  6. Compile the client class.

  7. Run the client.
The sections that follow cover these steps in greater detail.


JAX-WS Example

Now that we have gone through the web services terminologies, let’s go ahead and create a JAX-WS web service. We will create a web service that will expose methods to add, delete and get person objects. So first of all we will create a model bean for our data.
            13. Discuss how a web service can be tested using different approaches (using a dummy client or a dedicated tool, etc…). 

JAX-WS uses the javax.jws package 

•It uses annotations 

     @WebService 

          Web Service Example

                  

     @WebMethod 
@WebMethod JAX-WS annotation can be applied over a method only. This specified that the method represents a web service operation

     @OneWay 
@Oneway JAX-WS annotation is applied to WebMethod which means that method will have only input and no output. When a @Oneway method is called, control is returned to calling method even before the actual operation is performed. It means that nothing will escape method neither response neither exception.

       
     @WebResult
     

t-11

1. Distinguish the term “Rich Internet Applications” (RIAs) from “Rich Web-based Applications” (RiWAs).  Rich Internet Applications A ric...