MVC model at the basis of Web Services implementation solutions will be even better point. Part in the follow-up, you will see how to use Struts to do this. I will elaborate on WSManager layer to the existing Struts framework, this one demonstrated the use of Web Services Services Ways models.

Struts applications using Web Services

Development work in the future you can expand to build a comparatively well Struts application to support Web Services. Mentioned earlier, Struts architecture clear distinction between the view, controller and model. Model contains all the necessary business logic from data storage to retrieve data warehouse. You can build a simple Web service layer - known as WSManager layer - such a model can provide Web Services Web Services can also be ordered. Architecture of the use of such applications will be the best component-based development with the World Wide Web together, shown in Figure 4.

Figure 4. The use of Web services Struts application

The following aspects have to be discussed in this architecture are different components of the detailed information, in particular, should pay close attention to WSManager layer, because it is this architecture really add some new.

Struts Controller

MVC architecture of the controller part of the main focus on receiving the request of the client (typically running Web browser users), which decided to implement a business logic function to respond to the request, then in charge of the next generation user interface to connect to the appropriate view group pieces up. In Struts, the Controller's main component is a small ActionServlet Class Service procedures.

ActionServlet is responsible for the adoption of XML document will be the request URI is mapped to a specific behavior. This document contains a list of URI requests but also to inform ActionServlet it should be how to allocate each request. This approach has several advantages:

☆ application logic flow of the whole text file at classification.

☆ list in this format more easily view and understanding, especially for a big application procedures.

ActionServlet determines the application's flow. Action categories are much inherited the ActionServlet. Action in each category:

☆ are mapped to separate the process of treatment

☆ through the ActionController with Struts combining Struts JSPs

☆ as a succession of Struts in Action category of a Java implementation class.
Struts in Action category called category WSManager relevant approach to the use of Web Services. WSManager to obtain the required response - or if one has been lifted will be unusual - it back to the Struts controller.

WSManager

WSManager receive JAX-RPC endpoint request. Will WSManager class method calls are mapped to the new client requests. These new arrivals are SOAP client requests information format. WSManager must achieve safety certification, change parameters, the model at the request of the designated service, the requests to the pretreatment parameters. Request parameters contained in the form of Java objects, Java original parameters, XML document, or even piecewise SOAP document (for example, SOAP Element object). These types must be translated into support within the schema (for example, predefined Java Data Access Objects).

Although WSManager can deal directly with the Java object combined with the parameters, but also need to take some additional steps to deal with XML documents. Recommends the following steps:

1. WSManager category should be able to through the XML Schema to verify the validity of XML documents.

2. WSManager category and then to XML documents into an internal support schema.

3. WSManager final document should be decomposed to the extent possible, it is mapped to the domain object go.

WSManager achieve the following tasks are very important:

1. Identity authentication and authorization to use

2. Error Handling

3. Cache.

Can also be generated in response to WSManager; this process by the method call return value of easy structure composed. WSManager to retain this feature, you can cache data so as to avoid repeat visits to model service layer. You can also focus on the management of XML documents in response to aggregation, as well as the conversion, if you want to return to the scheduling of those documents must comply with different schema and internal schema, this point has become particularly important.

WSManager deal with all the SOAP request and put them assigned to the model layer by exposing business logic. If the model are as a Service EJB layer to achieve, then you can at EJB layer through Session Fa? Ade design patterns to achieve. If you use this mode WSManager, you will receive a lot of benefits because WSManager Council:

☆ as the initial point of contact to manage the requests and services

☆ call the security services, including identity verification and to authorize the use, thereby avoiding any duplicate layer of the visit.

☆ appointed business deal (using Struts application from the model used by services)

☆ At WSManager layer cache data to avoid any unnecessary database access.

Posted by: display of Web Services

WSManager category at each implementation of a public method will be published as a Web Service from. In other words, you want to for these types of release of a Web service description. Web Services are described by the Web Services Description Language Services (Web Services Description Language, WSDL) description and quote from it to any XML schema composed. (WSDL services are described in standard language.)

You can center or in the public register of companies at the enterprise registry Published on Web Services Description. Similarly, you can release from the definition of WEB Services XML Schema to the same public or proprietary (UDDI) Registration Center. Java Web services using JAXR client application programming interface to query the company or a public registry on the service description.

If your clients are the exclusive partner, then you do not need to use the registry. However, you can at your application at the Web layer or with the appropriate security protection of well-known location to publish your Web service description (WSDL and XML schemas). For example, the scenario has a resale customer of those applications, he has a particular vendor agreements. Customer application development time has been at manufacturers of static with a combination of Web Services. Only authorized groups can query XML schema or retrieval from the Web Service Description layer to generate client-side code. You should implement effective WSManager layer client authentication and authorization of use.
Order from: the use of Web Services

Applications can be used in a public registry or the enterprise has been maintained by Web Services. WSManager have to resolve the necessary WSDL documents related to the operation and call back a value. Struts controller class call at WSManager related approach to the use of specific Web Services. Data as a predefined data access objects at WSManager and send back and forth between Struts controller. Visit Web services happen all the anomalies will be listed at WSManager out and back to Struts ActionController.

Service requestor agent through the use of Service to search for Web services; find it if you want to use Web Services for the use of this service with the service providers will set up a contract, then can call the service business.

WSManager the use of WSDL documents, the server name, port name, operation name, as well as including the original Java types, Java arrays, Java objects or XML documents, such as all the necessary request parameters with one ordering a Web Service.

If it is published in the UDDI registry target Web Service, then all the Struts-based applications can be used as XMethods (please see reference) such agent services to ordering it. End in the implementation of the requested operation, the supplier of the desired Web Service return value. WSManager return value can be changed with the application makes it expected to match the schema; It can also be requested in the application on modified basic results. Receive results from WSManager later, Struts ActionController be able to deal with the results and send to the relevant view, or the model can also call the relevant Services to complete the deep treatment.

Error Handling

All errors are at the treatment WSManager layer; This eliminates the unnecessary server overhead. If the model of service is deemed to EJB layer to achieve, then its performance will be very significantly enhanced.

At the role of acting as suppliers, WSManager dished out all this SOAPFaultException such as abnormal. It also can check the new request and dished out all of the abnormal lack of mandatory fields. You can create a class to track and record data warehouse of these errors, then you can reference affectation.

In order to serve as role when, WSManager caught out by the service provider by all SOAP anomaly and will they change the format required by WSManager. You can record the error as dished out by subsequent reference. If necessary, then at the time required can also check out the response value and dished out as abnormal. You can create a category to record these anomalies, as a future reference. WSManager be able to verify the response values and can be used as an exception it thrown out.

Audit

At the role of acting as suppliers, WSManager can record detailed information, the future can be used as audit. Use of such information has a lot of purposes, such as:

☆ receive at the large number of sampling points based on the registered client.

☆ to collect data for marketing purposes.

☆ decide whether the application needs to be updated.

☆ identification and capture of illegal users.
Cache

Web services clients often than the general client - server architecture the client wants to have more; in Web Services architecture, the client do more work, such as cache. Web Services on the proper use of data cache can achieve its maximum performance. When the service request information is read-only or when the time than those in accordance with the information requested by the rate of change was even slower, you should consider to use Web Services caches.

Identity verification and to authorize the use

newsFrm.setNewsDetails (newsList);
/ / Set the NewsForm in the request
request.setAttribute (mapping.getAttribute (), newsFrm);
/ / return actionForward;
return mapping.findForward ( "success");
From the model of service received after the Data Access Objects, Action category by passing to the model of service with a data access object to call WSManager category getStocks () method. WSManager category getStocks () method implementation of JAX-RPC to purchase shares Web Services.
Stock obtained from the results of Web Services is necessary to change the cost to the schema and gathered back to pre-defined data access object go. This object from the place it was called back to action category. 2 sets out a list of how to use WSManager of JAX-RPC to Order Web Service, as well as how to share the results of Web services and schema changes in the cost to gather data access objects to return to go.

List 2. Ordering Web Service and send in response to

public Vector getStocks () throws Exception (
/ / Method level variables
Vector stockValues = new Vector ();
try (
/ / Create service factory
javax.xml.rpc.ServiceFactory factory =
javax.xml.rpc.ServiceFactory.newInstance ();
/ / Define targetNameSpace
String targetNamespace = "http://www.themindelectric.com/"
+ "Wsdl / net.xmethods.services.stockquote.StockQuote /";
/ / Define qname
QName serviceName =
new QName (targetNamespace,
"net.xmethods.services.stockquote.StockQuoteService");
/ / Define portname
QName portName =
new QName (targetNamespace,
"net.xmethods.services.stockquote.StockQuotePort");
/ / Define operation name
QName operationName = new QName ( "urn: xmethods-delayed-quotes",
"getQuote");
/ / Specify wsdl location
java.net.URL wsdlLocation =
new java.net.URL ( "http://services.xmethods.net/soap/urn:xmethods-
delayed-quotes.wsdl ");
/ / Create service
javax.xml.rpc.Service service =
factory.createService (wsdlLocation, serviceName);
/ / Create call
javax.xml.rpc.Call call =
service.createCall (portName, operationName);
/ / Populate an array with list of stock names
Vector populatedStockNames = this.getPopulatedList ();
/ / Loop through the populated list, and for each stock get a result
java.util.Iterator i = this.getPopulatedList (). iterator ();
String stockName = null;
Float result;
com.ddj.wsstruts.valueobject.StockValue stockValue = null;
while (i.hasNext ()) (
stockName = (String) i.next ();
/ / Invoke the remote web service
result = (Float) call.invoke (new Object [] (stockName));
if (category.isDebugEnabled ()) (
category.debug ( "The quote for" + stockName + "is:" + result);
)
/ / Set stock name and stock values in stockValue bean
stockValue = new com.ddj.wsstruts.valueobject.StockValue ();
stockValue.setStockName (stockName);
stockValue.setStockValue (result.toString ());
/ / Add the stockValue bean to stockValues vector
stockValues.add (stockValue);
)
)
Once the call End Class Action Model for Service and WSManager, ActionForm in stock value and the information content of the domain will be filled. Control was returned to the JSP page, from the ActionForm to obtain all the necessary values and print UI.