Thursday, March 14, 2019

Server-side development 1

Compare and contrast web applications with web services



WSDL

WSDL is an XML vocabulary for describing Web services allowing developers to describe Web
Services and their capabilities, in a standard manner.
•standard format to describe a Web Service (description stack)
•specifies three fundamental properties:
•What a service does - operations (methods) provided by the service
• How a service is accessed - data format and protocol details
•Where a service is located - Address (URL) details
•The document written in WSDL is also simple called a WSDL (or WSDL document)
•WSDL is a contract between the XML(SOAP) Web service and the client who wishes to use
 this service
•The service provides the WSDL document and the Web service client uses the WSDL
document to create the stub (or to dynamically decode messages)

Fundamental properties of a WSDL document and the use of WSDL document in web services and client development

Three fundamental properties:
•What a service does - operations (methods) provided by the service
• How a service is accessed - data format and protocol details
•Where a service is located - Address (URL) details

WSDL is often used in combination with SOAP and an XML Schema to provide Web services over the Internet. A clientprogram connecting to a Web service can read the WSDL fileto determine what operations are available on the server. Any special datatypes used are embedded in the WSDL file in the form of XML Schema.

Structure of the WSDL document, explaining the elements in WSDL








definitions
Contains the definition of one or more services. JDeveloper generates the following attribute declarations for this section:
  • name is optional.
  • targetNamespace is the logical namespace for information about this service. WSDL documents can import other WSDL documents, and setting targetNamespace to a unique value ensures that the namespaces do not clash.
  • xmlns is the default namespace of the WSDL document, and it is set to http://schemas.xmlsoap.org/wsdl/.
  • All the WSDL elements, such as <definitions><types> and <message> reside in this namespace.
  • xmlns:xsd and xmlns:soap are standard namespace definitions that are used for specifying SOAP-specific information as well as data types.
  • xmlns:tns stands for this namespace.
  • xmlns:ns1 is set to the value of the schema targetNamespace, in the <types> section.
Notice that the default of http://tempuri.org in namespaces to ensure that the namespaces are unique.
types
Provides information about any complex data types used in the WSDL document. When simple types are used the document does not need to have a types section.
message
An abstract definition of the data being communicated. In the example, the message contains just one part, response, which is of type string, where string is defined by the XML Schema.
operation
An abstract description of the action supported by the service.
portType
An abstract set of operations supported by one or more endpoints.
binding
Describes how the operation is invoked by specifying concrete protocol and data format specifications for the operations and messages.
port
Specifies a single endpoint as an address for the binding, thus defining a single communication endpoint.
service
Specifies the port address(es) of the binding. The service is a collection of network endpoints or ports.

Compare the PortType and operation elements in WSDL with the java equivalences

PortType element may have one or more operation elements, each of which defines an RPC- or documentstyle Web service method
• Java equivalence:
• portType -> java interface
• operation -> method name

Compare and contrast the binding and service elements in WSDL

Binding
•map a PortType to a specific protocol, typically SOAP over http, using a specific data
encoding style
•one portType can be bound to several different protocols by using more than one
port
•bindings refer back to portTypes by name, just as operations point to messages.
•binding styles may be either “RPC” or “Document”(SOAP).
•also specify SOAP encoding


<binding name="net.xmethods.services.stockquote.StockQuoteBinding"
type="tns:net.xmethods.services.stockquote.StockQuotePortType">
<soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http" />
<operation name="getQuote">
<soap:operation soapAction="urn:xmethods-delayed-quotes#getQuote" />
<input>
<soap:body use="encoded"
namespace="urn:xmethods-delayed-quotes"
encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" />
</input>
<output>
<soap:body use="encoded"
namespace="urn:xmethods-delayed-quotes"
encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" />
</output>
</operation>
</binding>

Service
• it binds the Web service to a specific network-addressable location, i.e. it takes the bindings declared previously and ties them to a port, which is a physical network endpoint to which clients bind over the specified protocol,
• contain one or more port elements, each of which represents a different Web service and the port element assigns the URL to a specific binding,
• reference a particular binding, and along with addressing information is wrapped together into a service element to form the final physical, network addressable Web service,
• access point for each port
• port type - The operations performed by the web service.
• message - The messages used by the web service.
• types - The data types used by the web service.
• binding - The communication protocols used by the web service.

<service
name="net.xmethods.services.stockquote.StockQuoteService">
<documentation>net.xmethods.services.stockquote.StockQuote web service
</documentation>
<port
name="net.xmethods.services.stockquote.StockQuotePort"
binding="tns:net.xmethods.services.stockquote.StockQuoteBinding">
<soap:address
location="http://64.39.29.211:9090/soap" />
</port>
</service>

Explain how SOAP is used with HTTP

OAP ( 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 (HTTP).  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 microservice-centric development environments.

Structure of SOAP message in message oriented communication


• Envelope
• wraps entire message and contains header and body
• defines an overall framework for expressing what is in a message; who should deal with it, and whether it is optional or mandatory

• Header
• optional element with additional info such as security or routing

• Body
• application-specific message content being communicated as arbitrary XML payloads in the request and response messages
• fault element provides information about errors that occurred while processing the message


Importance of the SOAP attachments, explaining the MIME header

•SOAP messages may have one or more attachments
• each AttachmentPart object has a MIME header to indicate the type of data it contains.
• it may also have additional MIME headers to identify it or to give its location, which can be useful when there are multiple attachments
•when a SOAP message has one or more AttachmentPart objects, its SOAPPart object may or may not contain message content

Annotations in JAX-WS

Annotation classAnnotationProperties
javax.jws. WebServiceThe @WebService annotation marks a Java class as implementing a Web service or marks a service endpoint interface (SEI) as implementing a web service interface.
Important
  •  A Java class that implements a web service must specify either the @WebService or @WebServiceProvider annotation. Both annotations cannot be present. This annotation is applicable on a client or server SEI or a server endpoint implementation class.
  • If the annotation references an SEI through the endpointInterface attribute, the SEI must also be annotated with the @WebService annotation.
  • See the exposing methods in SEI-based JAX-WS web services information to learn about best practices for using the @WebService and @WebMethod annotations on a service endpoint implementation to specify Java methods that you want to expose as JAX-WS web services.
  • Annotation target: Type
  • Properties:
    - name
    The name of the wsdl:portType. The default value is the unqualified name of the Java class or interface. (String)
    - targetNamespace
    Specifies the XML namespace of the WSDL and XML elements generated from the web service. The default value is the namespace mapped from the package name containing the web service. (String)
    - serviceName
    Specifies the service name of the web service: wsdl:service. The default value is the simple name of the Java class + Service. (String)
    - endpointInterface
    Specifies the qualified name of the service endpoint interface that defines the services' abstract web service contract. If specified, the service endpoint interface is used to determine the abstract WSDL contract. (String)
    - portName
    The wsdl:portName. The default value is WebService.name +Port . (String)
    - wsdlLocation
    Specifies the web address of the WSDL document defining the web service. The web address is either relative or absolute. (String)
javax.jws. WebMethodThe @WebMethod annotation denotes a method that is a web service operation.
Apply this annotation to methods on a client or server Service Endpoint Interface (SEI) or a server endpoint implementation class.
  • Annotation target: Method
  • Properties:
    - operationName
    Specifies the name of the wsdl:operation matching this method. The default value is the name of Java method. (String)
    - action
    Defines the action for this operation. For SOAP bindings, this value determines the value of the SOAPAction header and must be explicitly set.
    - exclude
    Specifies whether to exclude a method from the web service. The default value is false. (Boolean)
javax.jws. OnewayThe @Oneway annotation denotes a method as a web service one-way operation that only has an input message and no output message.
Apply this annotation to methods on a client or server Service Endpoint Interface (SEI) or a server endpoint implementation class.
  • Annotation target: Method
  • There are no properties on the Oneway annotation.
javax.jws. WebParamThe @WebParam annotation customizes the mapping of an individual parameter to a web service message part and XML element.
Apply this annotation to methods on a client or server Service Endpoint Interface (SEI) or a server endpoint implementation class.
  • Annotation target: Parameter
  • Properties:
    - name
    The name of the parameter. If the operation is remote procedure call (RPC) style and the partName attribute is not specified, then this is the name of the wsdl:part attribute representing the parameter. If the operation is document style or the parameter maps to a header, then -name is the local name of the XML element representing the parameter. This attribute is required if the operation is document style, the parameter style is BARE, and the mode is OUT or INOUT. (String)
    - partName
    Defines the name of wsdl:part attribute representing this parameter. This is only used if the operation is RPC style, or the operation is document style and the parameter style is BARE. (String)
    - targetNamespace
    Specifies the XML namespace of the XML element for the parameter. Applies only for document bindings when the attribute maps to an XML element. The default value is the targetNamespace for the web service. (String)
    - mode
    The value represents the direction the parameter flows for this method. Valid values are ININOUT, and OUT. (String)
    - header
    Specifies whether the parameter is in a message header rather than a message body. The default value is false. (Boolean)
javax.jws. WebResultThe @WebResult annotation customizes the mapping of a return value to a WSDL part or XML element.
Apply this annotation to methods on a client or server Service Endpoint Interface (SEI) or a server endpoint implementation class.
  • Annotation target: Method
  • Properties:
    - name
    Specifies the name of the return value as it is listed in the WSDL file and found in messages on the wire. For RPC bindings, this is the name of the wsdl:partattribute representing the return value. For document bindings, the -nameparameter is the local name of the XML element representing the return value. The default value is return for RPC and DOCUMENT/WRAPPED bindings. The default value is the method name + Response for DOCUMENT/BARE bindings. (String)
    - targetNamespace
    Specifies the XML namespace for the return value. This parameter is only used if the operation is RPC style or if the operation is DOCUMENT style and the parameter style is BARE. (String)
    - header
    Specifies whether the result is carried in a header. The default value is false. (Boolean)
    - partName
    Specifies the part name for the result with RPC or DOCUMENT/BARE operations. The default value is @WebResult.name. (String)
javax.jws. HandlerChainThe @HandlerChain annotation associates the web service with an externally defined handler chain.
You can only configure the server side handler by using the @HandlerChain annotation on the Service Endpoint Interface (SEI) or the server endpoint implementation class.
Use one of several ways to configure a client side handler. You can configure a client side handler by using the @HandlerChain annotation on the generated service class or SEI. Additionally, you can programmatically register your own implementation of the HandlerResolver interface on the Service, or programmatically set the handler chain on the Binding object.
  • Annotation target: Type
  • Properties:
    - file
    Specifies the location of the handler chain file. The file location is either an absolute java.net.URL in external form or a relative path from the class file. (String)
    - name
    Specifies the name of the handler chain in the configuration file. (String)
javax.jws. SOAPBindingThe @SOAPBinding annotation specifies the mapping of the web service onto the SOAP message protocol.
Apply this annotation to a type or methods on a client or server Service Endpoint Interface (SEI) or a server endpoint implementation class.
The method level annotation is limited in what it can specify and is only used if the style property is DOCUMENT. If the method level annotation is not specified, the @SOAPBinding behavior from the type is used.
  • Annotation target: Type or Method
  • Properties:
    - style
    Defines encoding style for messages sent to and from the web service. The valid values are DOCUMENT and RPC. The default value is DOCUMENT. (String)
    - use
    Defines the formatting used for messages sent to and from the web service. The default value is LITERALENCODED is not supported. (String)
    - parameterStyle
    Determines whether the method's parameters represent the entire message body or whether parameters are elements wrapped inside a top-level element named after the operation. Valid values are WRAPPED or BARE. You can only use the BARE value with DOCUMENT style bindings. The default value is WRAPPED. (String)



No comments:

Post a Comment

RICH WEB BASED APPLICATIONS

Term “Rich Internet Applications” (RIAs) from “Rich Web-based Applications” (RiWAs). A rich Internet application (RIA) is a Web applicati...