Tutorial for building J2ee Applications Using JBoss and Eclipse-9

xiaoxiao2021-03-06  79

Chapter 9.

CREATING Web Services:

Web services promises to be the next generation of software development. In essence, a web service is a means of interfacing to web or enterprise applications that allows you to integrate these with other enterprise applications, including those from different vendors and different platforms, using XML As the means of exchanging data.

There is a great deal of hype about web services. In the past there have been a number of initiatives to provide such vendor-and-platform agnostic integration technology, but none of these has been totally succesful. A good example is that of getting an enterprise applicaction running on Windows to communicate with an enterprise application running on Unix. Sure, it's been possible by various means but typically with a mechanism which is not equally well supported by both environments. That has changed with the advent of web services SOAP and XML Provide an Integration Glue That Everyone Can Finally Agree ON.

The basic mechanism of Web services is to use XML to transport its across different applications using the standard Web HTTP protocol (Hyper Text Transfer Protocol). Specifically SOAP (Simple Object Access Protocol) is used, which is a lightweight XML based RPC (Remote Procedure Call) Over http. The Protocol Has Three Parts:

An envelope (SOAP envelope) that defines a framework for describing what is in a message and how to process it. A set of encoding rules for expressing instances of application defined-dataypes. A set of rules for representing remote procedure calls and responses.

Web Services Standards:

Now lets go through some evolving standards used in in Web Services, which are SOAP, WSDL (Web Services Description Language), UDDI (Universal Description Discovery and Integration), ebXML which is promoted by OASIS (Organization for the Advancement of Structured Information Standards) and UN / CEFACT (United Nations Centre for Trade Facilitation and Electronic Business). We will cover only SOAP and WSDL in this tutorial.WSDL (Web Services Description Language) describes the interface of a network service similar to IDL (interface Definition Language) in CORBA (Common Object Request Broker Architecture), specifying what messages an endpoint (ie a service instance which processes client requests and returns responses) will receive and send. WSDL is itself an XML metadata format. (In the terms of similar mechanisms like RMI or Corba, a Service Is The Interface OR Set of Methods That A Client Will Invoke Across The Wire.

SOAP (Simple Object Access Protocol) AS Discussed Earlier Describes The Format of The Data That Is Transmitted over The Wire.

Both these standards are still evolving under the eye of the W3C, but these standards are regarded as the building block of the next revolution in distributed computing and the IT industry in general. Web services promise to do for machine-to-machine communication what the Web HAS DONE for Human-to-Human and Machine-To-Human Communication.

However, Due to The Evolute Nature of the Web Services Standards Tools and Platforms, The Full Impact Is Still Far from Being REALIZED.

Web Services in Java:

As discussed earlier, Web Services standards are still evolving and their support in Java is still evolving. Even though Web Services were initially promoted by Microsoft and IBM, with the release of J2EE 1.4 Sun has provided full support for Web Services.In the J2EE environment Web Services Are Built On Jax-RPC (Java API for XML-Based RPC). This is an API for Building Web Services and Clients That Use Remote Procedure Calls (RPC) and XML.

In JAX-RPC, a remote procedure call is represented by an XML-based protocol such as SOAP. The SOAP specification defines the envelope structure, encoding rules, and convention for representing remote procedure calls and responses. These calls and responses are transmitted as SOAP messages (XML files) over HTTP. Even though the SOAP messages are a bit complex, but this complexity is transparent to the developer. When developing client and server side implementations, developers do not have to generate SOAP messages these are generated by the JAX --RPC API Calls.

On the server side, the developer specifies the remote procedures by defining methods in an interface written in the Java programming language. The developer also codes one or more classes that implement those methods. Client programs are also easy to code. A client creates a proxy , a local object representing the service, and then simply invokes methods on the proxy. With JAX-RPC, the developer does not generate or parse SOAP messages. It is the JAX-RPC runtime system that converts the API calls and responses to and from SOAP MESSAGES.

For this tutorial, we will use the Apache Axis library, which is an open source initiative of the Apache Software Foundation (ASF). Axis is a JAX-RPC compliant SOAP engine. It can be integrated with web containers like Tomcat / Jetty, which allows it to use the features of such web containers like security, resource pooling, multi-threading, etc.Note: JAX-RPC is based on JSR-101, which took the first step in defining a standard set of Java APIs and a programming Model for developing and deploying Web Services on the java placeform. Apache Axis is Jax-RPC Compliant.

Now another specification which is evolving is JSR-109. This builds upon JAX-RPC. It defines a standard mechanism for deploying a Web service in the J2EE environment, more specifically, in the area of ​​Enterprise JavaBean (EJB) technology and servlet containers.

.

Jboss.3.2.x comes with integrated support for Web-services provided by Jboss.Net. Jboss.NET has Apache AXIS as a plugin service for the Jboss-Microkernel. Jboss.Net uses the built-in JBoss deployment system that understands the WSR packaging. [Web Service aRchive (WSR- or .wsr-) files are ordinary .jar files that contain, besides necessary byte code for plugging into the Axis machinery, a slightly extended Axis deployment descriptor in their "META-INF / web-service .xml "entry]. Currently, There Are Not That Many Application Servers Available Which Support WSR Deployment, Which Can Result In Portability Issues.

THHEREFORE for this Tutorial We Will Use apache-axis 1.1 for create and deploying web services.

Installing Axis:

Download the apache-axis binary from http://ws.apache.org/axis/.ex: Version 1.1 Binary - tar.gz

First Create a Dir Named Axis under / Opt and The Save this File Under / OPT / AXIS /.

[Vishal @ Vishal Axis] $ PWD

/ OPT / AXIS

[Vishal @ Vishal Axis] $ LS

AXIS-1_1.TAR.GZ

Now unzip the file. A New Directory Will BE CREATED with the name axis-1_1.

[Vishal @ Vishal Axis] $ TAR -XVZF AXIS-1_1.TAR.GZ

AXIS-1_1 /

AXIS-1_1 / DOCS /

AXIS-1_1 / DOCS / ANT /

AXIS-1_1 / DOCS / ANT / ANT.HTML

AXIS-1_1 / DOCS / ANT / AXIS-Admin.html

-------------------------------------------------- ---

-------------------------------------------------- -

-------------------------------------------------- ----

AXIS-1_1 / XMLS /

AXIS-1_1 / XMLS / Checkstyle.xml

AXIS-1_1 / XMLS / Deploy_CATALINA_LOCAL.XML

AXIS-1_1 / XMLS / Path_refs.xml

AXIS-1_1 / XMLS / Properties.xml

AXIS-1_1 / XMLS / Targets.xml

AXIS-1_1 / XMLS / Taskdefs.xml

AXIS-1_1 / XMLS / Taskdefs_post_compile.xml.

[Vishal @ Vishal Axis] $ LS

AXIS-1_1 AXIS-1_1.TAR.GZ

[Vishal @ Vishal Axis] $

The Directory Structure Will Be as Shown Below.

[Vishal @ Vishal Axis] $ PWD

/ OPT / AXIS

[Vishal @ Vishal Axis] $ LS

AXIS-1_1 AXIS-1_1.TAR.GZ

[Vishal @ Vishal Axis] $ CD AXIS-1_1

[Vishal @ Vishal Axis-1_1] $ LS

DOCS LIICENSE README RELESE-Notes.html Samples WebApps XMLS

[Vishal @ Vishal Axis-1_1] $ PWD

/ OPT / AXIS / AXIS-1_1

[Vishal @ Vishal Axis-1_1] $ CD LIB /

[Vishal @ Vishal LIB] $ LS

Axis-ant.jar command-discovery.jar jaxrpc.jar saaj.jar

Axis.jar Commons-logging.jar log4j-1.2.8.jar wsdl4j.jar

[Vishal @ Vishal Lib] $

Now The Axis Binary IS Installed, Let's Configure It for use with our application server jboss-3.2.1.

Configuring Axis with JBOSS:

In Order to Configure Jboss with Axis, First Go To $ JBOSS_HOME / Server / All / Deploy / All / as Shown Below. [Vishal @ Vishal Deploy] $ PWD

/opt/jboss/jboss-3.2.1/server/all/Deploy

[Vishal @ Vishal Deploy] $

Create a Dir Named WebApps Under this Directory As Shown Below.

[Vishal @ Vishal Deploy] $ LS

Cache-invalidation-service.xml jbossweb-jetty.sar myStoremgr.jar

Cluster-service.xml jboss-xa-jdbc.rar Onlinestore.war

Farm-Service.xml JMS Properties-Service.xml

HSQLDB-DS.XML JMX-Console.war Schedule-Manager-Service.xml

HTTP-INVOKER.SAR JMX-EJB-Connector-Server.SAR Scheduler-Service.xml

Iiop-service.xml jmx-invoker-adaptor-server.sar sqlexception-service.xml

JBossha-httpsession.sar jmx-rmi-adaptor.sar transaction-service.xml

JBoss-jca.sar mail-service.xml user-service.xml

JBoss-local-jdbc.rar management uuid-key-generator.sar

Jboss-net.sar myfirstbean.jar

JBossWeb-ejb.jar mysecondbean.jar

[Vishal @ Vishal Deploy] $ MKDIR WebApps

[Vishal @ Vishal Deploy] $ LS

Cache-invalidation-service.xml jbossweb-jetty.sar myStoremgr.jar

Cluster-service.xml jboss-xa-jdbc.rar Onlinestore.war

Farm-Service.xml JMS Properties-Service.xml

HSQLDB-DS.XML JMX-Console.war Schedule-Manager-Service.xml

HTTP-INVOKER.SAR JMX-EJB-Connector-Server.SAR Scheduler-Service.xml

Iiop-service.xml jmx-invoker-adaptor-server.sar sqlexception-service.xml

JBossha-httpsession.sar jmx-rmi-adaptor.sar transaction-service.xml

JBoss-jca.sar mail-service.xml user-service.xml

JBoss-local-jdbc.rar management uuid-key-generator.sar

JBoss-net.sar myfirstbean.jar WebApps

JBossWeb-ejb.jar mysecondbean.jar

[Vishal @ Vishal Deploy] $

Now Go to / Opt / Axis / AXIS-1_1 / WebApps Dir. Copy The Axis Dir To $ JBOSS_HOME / Server / All / Deploy / All / WebApps / as Shown Below.note: Here Jboss_Home IS /OPT/JBoss/Jboss-3.2 .1

[Vishal @ Vishal WebApps] $ PWD

/ OPT / AXIS / AXIS-1_1 / WebApps

[Vishal @ Vishal WebApps] $ LS

Axis

[Vishal @ Vishal WebApps] $ cp -r axis /opt/jboss/jboss-3.2.1/server/all/deploy/webapps/.

[Vishal @ Vishal WebApps] $

Now Go Back to the $ jboss_home / server / all / deploy / webapps / dir and rename the axis directory to axis.war.

[Vishal @ Vishal WebApps] $ PWD

/opt/jboss/jboss-3.2.1/server/All/Deploy/webapps

[Vishal @ Vishal WebApps] $ LS

Axis

[Vishal @ Vishal WebApps] $ mv Axis Axis.war

[Vishal @ Vishal WebApps] $ LS

Axis.war

[Vishal @ Vishal WebApps] $

NOTE: AS SHOWN ABOVE, The Directory Axis Has Been Renamed To Axis.war So That Jboss Can Recognize This As a Web Application and Hence The Web Container Can Deploy It At Run-Time.

NOW From With, if it isn't already running. If it isn't alleady running. If it is already running. If it is already running...................

Also made Sure All The Libraries Which Come with Axis Are On The ClassPath ($ ClassPath OR $ AXISCLASSPATH) AS Shown Below.

[

Vishal @ Vishal Lib] $ PWD

/opt/jboss/jboss-3.2.1/server/All/Deploy/webapps/Axis.war/web-inf/lib

[Vishal @ Vishal LIB] $ LS

Axis-ant.jar command-discovery.jar jaxrpc.jar saaj.jar

Axis.jar Commons-logging.jar log4j-1.2.8.jar wsdl4j.jar

[Vishal @ Vishal LIB] $ Echo $ AXISCLASSPATH

/opt/axis/axis-1_1/lib/axis.jar:/opt/axis/axis-1_1/lib/jaxrpc.jar:/opt/axis/axis 1_1/lib/saaj.jar:/opt/axis/ AXIS-1_1 / lib / wsdl4j.jar: /opt/axis/Axis-1_1/lib/commons-discovery.jar: /opt/axis/axis-1_1/lib/commons-logging.jar :.

[Vishal @ Vishal Lib] $

Now to test your configuration go to http://127.0.0.1:8080/AXIS/.

Note:. The port no will be different if you have customized it from its default settings.You should now be able to see an Apache-Axis start page as shown below If you do not, then either the webapp is not actually installed properly. Or the appserver is not running.

Now Validate The Local Installation's Configuration By Clicking on The Link 'Validate The Local Installation's Configuration'.

This will bring you to happyaxis.jsp, a test page that verifies whether required and optional libraries are present The URL for this will be something like http:. // localhost: 8080 / axis / happyaxis.jsp as shown below in figure.

IF any of the needed ipraries are missing, Axis will not work.

. Note: Make sure that all the needed libraries are found, and this validation page is happy Optional components are indeed optional; install them as you require If you see nothing but an internal server error and an exception trace, then you probably have multiple. XML Parsers on The ClassPath (OR AxisclassPath), and this is causing version control.

Now Go Back to your apache ax斯 start page and select The list of already Deployed Web Services. By Clicking On 'View The List of Deployed Web Services'.

NOTE: There a few Web Services Which com with apache-axis bundle to assist us with our Learning Curve.

In order to make sure that your Web Service is up and running, click on each WSDL (Web Service Description Language) as shown above in figure Example:. If we click on AdminService (WSDL) then the following screen will be available as shown below .

Before we write our first Web Service, let's test one of the working example services which is already deployed as part of the Apache bundle.Note: For more information look at the documentation for Apache-AXIS under 'Installing and deploying web applications using xml- Axis' at http://ws.apache.org/axis/.

Now, SOAP 1.1 uses HTTP POST to submit an XML request to the endpoint, but Axis also supports a HTTP GET access mechanism, which is very useful for useful for testing. So to test the service, let's retrieve the version of Axis from the version Endpoint, by calling the getversion method: http: // localhost: 8080 / axis / services / version? method = getversion this will result in the screen shown Below.

After Success, Testing The Web Service, Let's Write Our OWN First Web Service By Extending Our Tutorial Application MyStore.

We will create a web service named MyStoreLoginService, which will allow the user to login to MyStore using a Java Client, but using Web service (HTTP) rather then RMI, which is normally the case when we use servlets / JSP or a Java Client. StoreAccessBean Will Be acting as our endpoint.

Note: Lomboz-2.1_02 witth Eclipse 2.1 and Lomboz 2.1.1 with Eclipse 2.1.1 does not have a wizard to create a webservice (that is Web Service Deployment Descriptor [WSDD]) and deploy it So we will have to do. IT by Hand. Both Versions of Lomboz Do Provide a Wizard for Creating A SOAP Client.

Create The Web Service:

In order to create a Web Service we need to create an endpoint. In this case, our Stateless Bean StoreAccessBean will be acting as an endpoint. Method loginUser will be invoked from the client side using this Web Service, so we have to create a Web Service Deployment Descriptor (WSDD) file describing the signature of the loginUser method along with some other required information.Note: Currently, only a Stateless Bean can be used as an endpoint for a Web Service as specified in JSR-109.

WSDD IS An Axis Specific File, Used to Create A Skeleton for Jax-RPC. This is transparent to the developer, and overce this skeleton is created and deployed, axis generates wsdl and public publishes the web-service.

For more information: http://ws.apache.org/axis/.

Now, Under Eclipse, Go to Package Explorer> Expand MyStore (Project) Node> SELECT SRC, Right Click and A Menu Will Pop Up.

On The Pop Up Menu> New> SELECT Package> Add name of package as 'au.com.tusc.webservice'.

Press Finish.

This Will Create a new package named au.com.tusc.webservice under 'src'.

Go to src / au.com.tusc.webservice> SELECT New> File as Shown Below.

Now create a file named deploy.wsdd under the package supply au.com.tusc.webservice as shown below.

Add The Following XML Tags As Shown Below In The Deploy.wsdd File, And The File ..

Lets Analyze these deployment descriptors.

The service name tag is responsible for giving the name to the service and the provider Provider states that the web service is an EJB-Web Service The name of our service is MyStoreLoginService and the provider is java:.. EJB.

The first parameter is beanJndiName which specifies where the bean (EJB) is in the JNDI tree. We are using the local interfaces of StoreAccessBean, so it is StoreAccessLocal.

Note: We used non-local interfaces for StoreAccessBean until chapter 8, where the Bean is accessed by Web Components and Java Clients As all the component are in the same JVM, we are typically using local interfaces as these interfaces have many advantages compared to. Remote Interfaces. Thase Are:

Simpler programming model, no need to catch remote exceptions that can not happen in co-located deployment. Since RemoteException is not needed on every method signature, your EJB business method's interface is independent of EJB. This can free callers from dependence on the EJB API. AS IT IS Running in The Same JVM AND NOT IN A Distributed Environment, Although Coded To Call-by-Value It Is Running with Call-by-Reference.

The Parameter Above Is Called HomeInterfacename and It Has As It's Value The Remote Home Local Interface Which is au.com.tusc.session.storeAccessLocalhome.

The Parameter Above Is Called RemoteInterfaceName and It Has As It's Value The Remote Local Interface Which is au.com.tusc.session.storeAccessLocal.

The allowedMethods parameter has the value loginUser to indicate that only this method will be made public or can be accesed from client. The rest of the parameters are specific to the application server, in this case JBOSS.So, now our deploy.wsdd is complete Let's deploy it.

Note: Currently Lomboz Doesn't Have a Wizard for Creating The WSDD File and To Deploy It. So That's why we have to create it by hand.

Deploy the Web Service:

In Order to Deploy this We will have to go to our linux console (if Windows the dos-console).

Now, Assuming The Application Server (JBoss) IS Running and Our Bean Has Bean Deployed (All The Beans Are In MyStore.jar as Covered In Previous Chapter).

Go Into The Directory Where Deploy.wsdd Has Been Created As Shown Below.

[Vishal @ Vishal WebService] $ PWD

/ Home / Vishal / Workspace / MyStore / SRC / AU / COM / TUSC / WebService

[Vishal @ Vishal WebService] $ ls

Deploy.wsdd

[Vishal @ Vishal WebService] $

NOTE: Make Sure That $ AXISCLASSPATH IS Set Properly As Mentioned Above.

[Vishal @ Vishal WebService] $ Echo $ AXISCLASSPATH

/opt/axis/axis-1_1/lib/axis.jar:/opt/axis/axis-1_1/lib/jaxrpc.jar: BiPT/AXIS/AXIS-1_1/Lib/saaj.jar:

/ OPT / AXIS / AXIS- 1_1 / lib / wsdl4j.jar: /opt/axis/AXIS-1_1/lib/commons-discovery.jar:

/opt/axis/axis-1_1/lib/commons-logging.jar :.

[Vishal @ Vishal WebService] $

Now We Will Be Using The AdminClient (Org.apache.axis.Client.adminClient) Class, Which IS Part of The Axis API'S, To Deploy the WSDD.

Note: by Default IT Uses Port 8080, But if you have to use limited the --p argument.

Use this command to deploy wsdd as shown below.

[Vishal @ Vishal WebService] $ java org.apache.axis.client.adminClient Deploy.wsdd

Processing file deploy.wsdd done processing

[Vishal @ Vishal WebService] $

IF The Message Shown Above Is Displayed The Your Web Service IS Deployed SUCCESFULLY.

NOTE: An Admin Client Can Be Used Both from The Command Line and ProgramMAAMAALY.

NOW, Let's Access Our Web Service and ITS Corresponding Web Service Description Language (WSDL).

Go to the Following Url http: // localhost: 8080 / axis / servlet / axisservlet to see the all the deployed services as shown below.

Go to wsdl and it will show the wsdl generated by axis for the deployed web service as shown bell.

Now Save this WSDL As It Will Be Required To Generate The Soap Client Using Lomboz's Soap Client Creation Wizard. Save this File Under The package supply a shown below.

Note: The Lomboz SOAP Client Wizard Uses The "WSDL2JAVA" Tool, Which Will Build Java Proxies and Skeletons for Services with WSDL Description with the apache-axis distribution.

Now Go Back to Eclipse, And Refresh Your Project. MyStore and MyStoreloginService.wsdl Will Be Present Now as shown bellow.

Since The Web Service IS Deployed Success, It's Time To Create The Test Client.

CREATE Web Service Test Client:

Now, Lomboz (Both Versions 2.1_02 & 2.1.1) Province A Wizard for Creating Soap Clients for Published Web Services Using Their Corresponding WSDL Files.

But before we do that, one necessary step is to make sure we have all the libraries on the classpath neccesary for generateing the stub for the SOAP Client. These are the same libraries used for $ AXISCLASSPATH covered above in the chapter.

Note: This can be configured by adding the neccessary libraries to the jboss321all.server file used for configuration of Lomboz with Eclipse, which was covered in chapter 1.To import the required libraries on the projects classpath,

Go to Project Explorer Select Project MyStore> Right Click> SELECT Properties.

Under Properties> Select Java Build Path> SELECT TAB LIBRARIES.

Press Add External Jars as Shown Below.

The Following Libraries Are Imported As Shown Below:

Axis.jar, jaxrpc.jar, saaj.jar, wsdl4j.jar, commons-discovery.jar, commit-logging.jar

Note: Lomboz 2.1_02 and 2.1.1 Come with the libraries Mentioned. Since We are for the Latest Version of Apache-Axis (V1.1), IT IS Better to Import these New Libraries INSTEAD.

Now Under Project Explorer Go To Src / Au.com.Tusc.Webservice> Right Click.

On The Pop Up Menu Select New> Select Lomboz SOAP Client Wizard.

Under the SOAP Client Wizard select 'MyStoreLoginService.wsdl'. Also select the checkbox with Add Axis to buildpath. And under namespace mapping select the package name 'au.com.tusc.WebService' as shown below in figure.

Press Finish.

.

Now Let's Write the Test Client.

So, Go to Src / Au.com.Tusc.Webservice and Add A New File Named TestClient.java.

Add The Following Code to this (TestClient.java) File as Shown Below. We Will Analyze this Code Later.

Now Let's Examine The 2 Main Statements.

StoreAccessLocalServiceLocator Service = New StoreAccessLocalServiceLocator ();

This is necessary as the ServiceLocator object returns the endpoint for the web service which is used for making the call In this example the end point is. "Http: // localhost: 8080 / axis / services / MyStoreLoginService"; StoreAccessLocal port = service. getMystoreloginService ();

THIS RETURNS The Reference of The Local Interface for the Bean So That The next Necessary Methods Can Be invoked.

NOTE: There Four Different Styles of Service In Axis 1.1 as specified in the user guide That with the apache-axis distribution.

RPC services use the SOAP RPC conventions, and also the SOAP "section 5" encoding. The test client which we have created above is using SOAP RPC style. Document services do not use any encoding (so in particular, you will not see multiref object serialization or SOAP-style arrays on the wire) but dO still do XML <->. Java databinding Wrapped services are just like document services, except that rather than binding the entire SOAP body into one big structure, they "unwrap" it into individual parameters. The web clients covered later on are using this style of service. Message services receive and return arbitrary XML in the SOAP Envelope without any type mapping / data binding. If you want to work with the raw XML of the incoming and outgoing SOAP Envelopes, Write a Message Service.

For more information please refer to the use guide.

Test Your Client:

To test your client, select au.com.tusc.webservice.testclient node> Go to the top level menu and select the 'Running Man' icon.

On That Select 'Run As'> Select Java Application.

Note: The Steps to Run Test Clients Have Been Covered In Previous Chapter.

Now, under your console, If you get UserID as as 'U2' then your call was successful, as shown below.We have learned how to create, deploy and access web services using a Java client. Now that same web service can be accessed Using Web Components Like Servlets (JSP / Servlets).

There Are Three Different Ways of Creating Web Service Clients Which Are

The Static Stub Client Implement Above. Dynamic Proxy Client. Dynamic Invocation Interface (DII) Client Used In The Web Client Implement in Next Section.

CREATE Web Client:

To create a web client all the necessary steps have been covered in chapter 8, so leaving those details, we can straight away add the following lines to our servlet named 'Login' under au.com.tusc.WebService as shown below in this code Snippet from login.java.

Package au.com.tusc.webservice;

Import java.io.ioException;

Import java.io.printwriter;

Import javax.servlet.servletconfig;

Import javax.servlet.servletException;

Import javax.servlet.http.httpservlet;

Import javax.servlet.http.httpservletRequest;

Import javax.servlet.http.httpservletResponse;

Import javax.xml.namespace.qname;

Import org.apache.axis.client.call;

Import org.apache.axis.client.service;

/ **

* @Author Vishal

*

* To change the template for this generated type comment Go to to TOERATED TYCE

* Window> Preferences> Java> Code Generation> Code and Comments

* /

Public class login extends httpservlet {

Public void init (servletconfig config) throws servletexception {

Super.init (config);

System.out.println ("Entering Login.init ()");

System.out.println ("Leaving Login.init ()");

}

Protected void doget (httpservletRequest request, httpservletResponse response) throws servletexception, ioException {

ProcessRequest (Request, Response);

}

Protected Void Dopost (httpservletRequest Request, HttpservletResponse Response)

Throws servletexception, ioException {

ProcessRequest (Request, Response);

}

Protected Void ProcessRequest (httpservletRequest Request, HttpservletResponse Response)

Throws servletexception, ioException {

System.out.println ("Entering Login.ProcessRequest ()");

Response.setContentType (Text / HTML ");

PrintWriter out = response.getwriter ();

Out.println (" MyStore login </ title>");</p> <p>Out.println ("<body> <b> <h2> Welcome to myStore </ h2> </ b> </ body>);</p> <p>Out.print ("<body> <h2> login details: userid is:");</p> <p>Try {</p> <p>String username = CallwebService ();</p> <p>Out.print (UserName);</p> <p>} catch (exception e) {</p> <p>System.out.Println ("Exception in login.processRequest");</p> <p>}</p> <p>Out.print ("</ h2> </ body> </ html>");</p> <p>IF (out! = null) Out.close ();</p> <p>System.out.println ("Leaving Login.ProcessRequest ()");</p> <p>}</p> <p>Private string callwebservice () throws exception {</p> <p>// URL IS Used for Creating The Call, Which Uses The WSDL.</p> <p>Call call = new call (New URL ("http: // localhost: 8080 / axis / service? WSDL");</p> <p>// Calls the Object, Passing in the username and passwd. The return value is stored as an Object.</p> <p>String username = (string) Call.invoke ("Loginuser", new object [] {new string ("andy"), new string ("passwd")});</p> <p>Return UserName;</p> <p>}</p> <p>}</p> <p>Note:.. Another way of invoking the loginUser method is to use Axis' JAXRPC Dynamic Invocation Interface implementation of the Service interface The Service class should be used as the starting point for accessing SOAP Web Services Typically, a Service will be created with a WSDL document, and along with a serviceName you can then ask for a Call object that will allow you to invoke the Web Service. Shown below is the other way of implementing the callWebService () method. Both versions of callWebService () method use the DII approach .private string callwebservice () THROWS Exception {</p> <p>// endpoint is buy for making the call</p> <p>String endpoint = "http: // localhost: 8080 / axis / services / myStoreLoginService";</p> <p>// The service object is the starting point for accessing the web service.</p> <p>Service service = new service ();</p> <p>// The call Object is buy to actally invoke the web service.</p> <p>Call call = (call) service.createcall ();</p> <p>// sets the call objects Endpoint Address</p> <p>Call.SetTargetendPointAddRess (endpoint);</p> <p>// sets the Operation name associated with this call object.</p> <p>Call.SetoperationName (New Qname ("Loginuser");</p> <p>// Calls the Object, Passing in the username and passwd. The return value is stored as an Object.</p> <p>Object returnval = call.invoke (new object [] {new string ("andy"), new string ("passwd")});</p> <p>Return (String) ReturnValue;</p> <p>}</p> <p>Note: The difference between the two approaches is that the Call interface provides support for the dynamic invocation of a service endpoint whereas the Service class acts as a factory for the Dynamic proxy for the target service endpoint.</p> <p>Also Shown Below Is Web.xml Where The Servlet's Access Name and ITS MAPPING Are Shown.</p> <p>Note: The steps to create a servlet are covered in chapter 8. Servlet Login is included in the OnlineStore web module.Now once you have completed the servlet, deploy the web module OnlineStore If there are no error messages in the console then the web. Module Has Been Deployed Succesfully.</p> <p>NOTE: The Steps Are Covered In Chapter 8 on how to deploy web modules.</p> <p>To invoke the login method on the public, http: // localhost: 8080 / onlinestore / login.</p> <p>If You Get The Following Screen Shown Below The Your Call is success.</p> <p>Until now we have seen how to access web services using web clients and Java clients from the same environment. Now to really experience the amazing power of Web Services we will invoke this web service using a .NET (Microsoft Client).</p> <p>Create VB.NET Client:</p> <p>Now, to create a vb.net client Create a New Windows Application Project for Visual Basic.Net Named DotNetClient As Shown Below in the figure.</p> <p>Click ON OK.</p> <p>Change the form name protection.</p> <p>Add The Following Controls to The Form with The Following Properties as Shown Below in The Figure.</p> <p>Label Control</p> <p>Name: lblname</p> <p>TEXT: NAME</p> <p>Label Control</p> <p>Name: lblpassword</p> <p>TEXT: Password</p> <p>Label Control</p> <p>Name: LBLRESULT</p> <p>Text: Result</p> <p>Label Control</p> <p>Name: lbloutput</p> <p>TEXT:</p> <p>TextBox Control</p> <p>Name: TextBoxName</p> <p>TEXT:</p> <p>TextBox Control</p> <p>Name: TextBoxpassword</p> <p>TEXT:</p> <p>Passwordchar: *</p> <p>Button Control</p> <p>Name: btngetid</p> <p>TEXT: GET ID</p> <p>Now, Add the Web Reference of the Web Services to the project.</p> <p>Right-Click On The DotNetClient from The Solution Explorer and Click ON Add Web Reference As Shown Below.</p> <p>Add the following URL of the Web Service, which is the location of the published web service http://xxx.yyy.zzz.aaa:8080/axis/services/MyStoreLoginService?wsdl.Note:. This URL is pointing to the machine WHERE The Web Service IS Published.</p> <p>Click On Go - As Shown Below In The Figure IT Will Show The Service With ITS Method (s) Available Under IT.</p> <p>Click On The Add Reference Button as Shown Above.</p> <p>This Will Bring a new screen with Web Reference Added to The Project Via Solution Explorer As Shown Below.</p> <p>Now, Double Click The Button Getid on the form editor to view the code as shown Below in the figure.</p> <p>Add The Following Code for the sub btngetid_click ().</p> <p>DIM STRRESULT AS STRING 'OUTPUT RESULT for ID</p> <p>Dim objWebref as new WebReference.StoreAccessLocalService</p> <p>'Call loginuser function and display the result id to the lbloutput control</p> <p>LBloutput.text = objwebref.loginuser (TextBoxName.Text, TextBoxPassword.text)</p> <p>Once you have added the code, go to the top level menu, select build> Select Build Solution As Shown Above in the figure.</p> <p>Now, Start The Application and You Will Get This Form Shown Below. Enter name as 'andy' and password as 'passwd'. Press the getid button and the result shouth be 'u2'.</p> <p>Now with this we have successfully run a .NET Client Accessing Our Web Services</p> <p>CREATE Perl Client:</p> <p>To create a perl client we need the soap :: lite module to invoke methods on deployed web services.</p> <p>First Version of Soap :: Lite and Follow The Standard Perl Module Installation Procedures by Entering The Very Familiar Command Sequence:</p> <p>Perl makefile.pl</p> <p>Make</p> <p>Make test</p> <p>Make Install</p> <p>If you have the cpan.pm module installed to the internet</p> <p>CPAN Shell - CPAN Exploration and Modules Installation (v1.61)</p> <p>Readline Support Available (Try 'Install bundle :: cpan')</p> <p>CPAN> Install Soap :: Lite</p> <p>CPAN: Storable Loaded OK</p> <p>CPAN: LWP :: UseRagent loaded OK</p> <p>Fetching with LWP:</p> <p>ftp://mirror.aarnet.edu.au/pub/perl/cpan/authors/01mailrc.txt.gz</p> <p>Going to read y / SOURCES / Authors / 01mailrc.txt.gz</p> <p>CPAN: Compress :: Zlib loaded OK</p> <p>Fetching with LWP:</p> <p>---------------------------------------------</p> <p>---------------------------------------------</p> <p>---------------------------------------------</p> <p>CPAN: Digest :: MD5 loading OK</p> <p>Fetching with LWP:</p> <p>FTP: / /MIRROR.AARNET.EDU.AU/Pub/perl/cpan/authors/id/k/ku/kulchenko/checksums</p> <p>Checksum for Y / Sources / Authors / ID / K / KU / KULCHENKO / SOAP-LITE-0.55.tar.gz OK</p> <p>Cpan> Bye</p> <p>Lockfile Removed.</p> <p>[Vishal @ Vishal Vishal] $</p> <p>IF you are useful ActiveState Perl on Windows The Equivalent Would Be The 'PPM' Command.</p> <p>Note: for more information on the soap :: lite module please refer to this site http://www.soaplite.com/beta/install.html.</p> <p>Now Let's Create a Perl Client To Invoke The Loginuser Method on The Deployed Web Service Named MyStoreLoginService.</p> <p>Create a file named WebServiceClient.pl and add the folowing code shown Below.</p> <p>#</p> <p># WebServiceClient.pl</p> <p>#</p> <p># Test Client for MyStoreLoginService Web Service</p> <p># Apache Axis - Chapter 9 'CREATING Web Services'</p> <p>#</p> <p>Use soap :: lite;</p> <p>MY $ myStoreloginService = soap :: lite-> service ('http: // localhost: 8080 / axis / services / mystoreloginservice? WSDL');</p> <p>My $ usrname = $ myStoreLoginService-> Loginuser ("Andy", "Passwd"); Print "MyStore login details: Andy's UserName IS: $ UserName / N";</p> <p>Save this file, And Execute It to see the result shown below.</p> <p>[Vishal @ Vishal Vishal] $ Perl WebServiceClient.pl</p> <p>MyStore login details: Andy's UserName IS: U2</p> <p>[Vishal @ Vishal Vishal] $</p> <p>NOW with this We Have SuccessFully Run a Perl Client Accessing The Web Service.</p></div><div class="text-center mt-3 text-grey"> 转载请注明原文地址:https://www.9cbs.com/read-121905.html</div><div class="plugin d-flex justify-content-center mt-3"></div><hr><div class="row"><div class="col-lg-12 text-muted mt-2"><i class="icon-tags mr-2"></i><span class="badge border border-secondary mr-2"><h2 class="h6 mb-0 small"><a class="text-secondary" href="tag-2.html">9cbs</a></h2></span></div></div></div></div><div class="card card-postlist border-white shadow"><div class="card-body"><div class="card-title"><div class="d-flex justify-content-between"><div><b>New Post</b>(<span class="posts">0</span>) </div><div></div></div></div><ul class="postlist list-unstyled"> </ul></div></div><div class="d-none threadlist"><input type="checkbox" name="modtid" value="121905" checked /></div></div></div></div></div><footer class="text-muted small bg-dark py-4 mt-3" id="footer"><div class="container"><div class="row"><div class="col">CopyRight © 2020 All Rights Reserved </div><div class="col text-right">Processed: <b>0.063</b>, SQL: <b>9</b></div></div></div></footer><script src="./lang/en-us/lang.js?2.2.0"></script><script src="view/js/jquery.min.js?2.2.0"></script><script src="view/js/popper.min.js?2.2.0"></script><script src="view/js/bootstrap.min.js?2.2.0"></script><script src="view/js/xiuno.js?2.2.0"></script><script src="view/js/bootstrap-plugin.js?2.2.0"></script><script src="view/js/async.min.js?2.2.0"></script><script src="view/js/form.js?2.2.0"></script><script> var debug = DEBUG = 0; var url_rewrite_on = 1; var url_path = './'; var forumarr = {"1":"Tech"}; var fid = 1; var uid = 0; var gid = 0; xn.options.water_image_url = 'view/img/water-small.png'; </script><script src="view/js/wellcms.js?2.2.0"></script><a class="scroll-to-top rounded" href="javascript:void(0);"><i class="icon-angle-up"></i></a><a class="scroll-to-bottom rounded" href="javascript:void(0);" style="display: inline;"><i class="icon-angle-down"></i></a></body></html><script> var forum_url = 'list-1.html'; var safe_token = 'c2EJtlGr5iLAOrPFiTdu1nm95QSnjVk9ikvsMFf1c23FBqWbmQsiZJRzX1EbR5Zwg3zhuk_2FELkEUooQiZBjusA_3D_3D'; var body = $('body'); body.on('submit', '#form', function() { var jthis = $(this); var jsubmit = jthis.find('#submit'); jthis.reset(); jsubmit.button('loading'); var postdata = jthis.serializeObject(); $.xpost(jthis.attr('action'), postdata, function(code, message) { if(code == 0) { location.reload(); } else { $.alert(message); jsubmit.button('reset'); } }); return false; }); function resize_image() { var jmessagelist = $('div.message'); var first_width = jmessagelist.width(); jmessagelist.each(function() { var jdiv = $(this); var maxwidth = jdiv.attr('isfirst') ? first_width : jdiv.width(); var jmessage_width = Math.min(jdiv.width(), maxwidth); jdiv.find('img, embed, iframe, video').each(function() { var jimg = $(this); var img_width = this.org_width; var img_height = this.org_height; if(!img_width) { var img_width = jimg.attr('width'); var img_height = jimg.attr('height'); this.org_width = img_width; this.org_height = img_height; } if(img_width > jmessage_width) { if(this.tagName == 'IMG') { jimg.width(jmessage_width); jimg.css('height', 'auto'); jimg.css('cursor', 'pointer'); jimg.on('click', function() { }); } else { jimg.width(jmessage_width); var height = (img_height / img_width) * jimg.width(); jimg.height(height); } } }); }); } function resize_table() { $('div.message').each(function() { var jdiv = $(this); jdiv.find('table').addClass('table').wrap('<div class="table-responsive"></div>'); }); } $(function() { resize_image(); resize_table(); $(window).on('resize', resize_image); }); var jmessage = $('#message'); jmessage.on('focus', function() {if(jmessage.t) { clearTimeout(jmessage.t); jmessage.t = null; } jmessage.css('height', '6rem'); }); jmessage.on('blur', function() {jmessage.t = setTimeout(function() { jmessage.css('height', '2.5rem');}, 1000); }); $('#nav li[data-active="fid-1"]').addClass('active'); </script>