Tutorial for building J2EE Applications using JBOSS and ECLIPSE-9

Linux系统centos7安装网卡驱动 有时候我们装完Centos或Ubuntu系统会发现没有网卡信息,说明网卡驱动不配置,所以我们要重新安装。 首先去服务器主板官网下载网卡驱动,注意32位和64位。 先查看网卡型号 lspci | grep -i ethernet 我的网卡型号是 00:1f.6 Ethernet controller: Intel Corporation Device 0d55。 网上一找,压根没找到这型号的网卡,别说驱动了。怀着试一试的心态,就安装i219-v系的网卡驱动,还别说,成功了。 针对i21... 阅读详情

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 :

  1. An envelope (SOAP envelope) that defines a framework for describing what is in a message and how to process it.

  2. A set of encoding rules for expressing instances of application defined-dataypes.

  3. 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 (i.e. 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 evolving nature of the web services standards together with the various related 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 don't 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 platform. 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.

Both of these specifications will be integrated into the J2EE 1.4 specification. Together they serve as the basis of Web services for J2EE.

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.

Therefore for this tutorial we will use Apache-AXIS 1.1 for creating 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 then 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 lib LICENSE README release-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 commons-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 within Eclipse start your Application server (JBOSS) , if it isn't already running. If it is already running then don't restart it as it will hot-deploy the the axis.war.

Also make 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 commons-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 libraries 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 confusion.

Now go back to your Apache AXIS start page and select the list of already deployed Web services. By clicking on 'View the list of deployed Web services'.

Note : There are a few web services which come 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 successfully 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 doesn't 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 once this skeleton is created and deployed, AXIS generates WSDL and 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 au.com.tusc.WebService as shown below.




Add the following XML tags as shown below in the deploy.wsdd file, and then we will examine the contents of the file..


Lets analyze these deployment descriptors.

<service name="MyStoreLoginService" provider="java:EJB">

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 .

<parameter name="beanJndiName" value="StoreAccessLocal"/>

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. These are:

  1. Simpler programming model, no need to catch remote exceptions that can't happen in co-located deployment.

  2. 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.

  3. 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.

<parameter name="homeInterfaceName" value="au.com.tusc.session.StoreAccessLocalHome"/>

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.

<parameter name="remoteInterfaceName" value="au.com.tusc.session.StoreAccessLocal"/>

The parameter above is called remoteInterfaceName and it has as it's value the Remote Local Interface which is au.com.tusc.session.StoreAccessLocal.

<parameter name="allowedMethods" value="loginUser"/>

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 then 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 chapters).


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:/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 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 different port number then use the -p <port> 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
<Admin>Done processing</Admin>
[vishal@vishal WebService]$

If the message shown above is displayed then your web service is deployed succesfully.

Note : An admin client can be used both from the command line and programmatically.


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 below.



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 au.com.tusc.WebService as shown below.

Note : The Lomboz SOAP client wizard uses the "WSDL2Java" tool, which will build Java proxies and skeletons for services with WSDL descriptions. This tool comes with the Apache-AXIS distribution.




Now go back to Eclipse, and refresh your project. MyStore and MyStoreLoginService.wsdl will be present now as shown below.





Since the Web Service is deployed successfully it's time to create the test client.


Create Web Service Test Client :

Now, Lomboz (Both versions 2.1_02 & 2.1.1) provides 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, commons-logging.jar


Note : Lomboz 2.1_02 and 2.1.1 come with the libraries mentioned. Since we are using 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.

This will create the stub for the client comprising four files under au.com.tusc.WebService as shown below.



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 necessary methods can be invoked.

Note : There are four different styles of service in Axis 1.1 as specified in the user guide that comes with the Apache-AXIS distribution.

  1. 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.

  2. Document services do not use any encoding (so in particular, you won't see multiref object serialization or SOAP-style arrays on the wire) but DO still do XML<->Java databinding.

  3. 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.

  4. 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.

  1. 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 chapters.

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

  1. Using the Static Stub Client implemented in the client example discussed above.

  2. Dynamic Proxy Client.

  3. Dynamic Invocation Interface (DII) Client used in the Web client implemented 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
 * 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("<html><title>MyStore Login</title>");
           out.println("<body><b><h2>Welcome to MyStore </h2></b></body>");
           out.print("<body><h2>Login details : UserID is :   ");
           try {
               String username =    callWebService();
               out.print(username);              
           } catch (Exception e) {
                System.out.println("Exception in Login.processRequest ");
           }
           out.print("</h2></body></html>");
           if ( out != null ) out.close();                                                        
           System.out.println("Leaving Login.processRequest()");         
      }
     
      private String callWebService() throws Exception {
    
           // URL is used for creating the call, which uses the WSDL.  
           Call call = new Call( new URL("http://localhost:8080/axis/services/MyStoreLoginService?wsdl") );
              
           // Calls the object, passing in the username and passwd. The return value is stored as an object.
           String username = (String) call.invoke ("loginUser", new Object[] { new String("ANDY") , new String("PASSWD") } );
           return username;    
      }
}

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 {

           // Endpoint is used for making the call
           String endpoint = "http://localhost:8080/axis/services/MyStoreLoginService";

           // The Service object is the starting point for accessing the web service.
           Service service = new Service();

           // The call object is used to actually invoke the web service.
           Call call = (Call)service.createCall();

           // Sets the call objects endpoint address
           call.setTargetEndpointAddress(endpoint);

           // Sets the operation name associated with this Call object. 
           call.setOperationName(new QName("loginUser"));

           // Calls the object, passing in the username and passwd. The return value is stored as an object.
           Object returnValue = call.invoke(new Object[] { new String("ANDY") , new String("PASSWD") });
           return (String) returnValue;
     }

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.

Also shown below is web.xml where the servlet's access name and its mapping are shown.

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.

Note : The steps are covered in chapter 8 on how to deploy web modules.

To invoke the login method on the published web service go to this url http://localhost:8080/OnlineStore/login.

If you get the following screen shown below then your call is succesfull.




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).

Create VB.Net Client :

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.


Click on OK.

Change the form name property to DOTNETCLIENT.

Add the following controls to the form with the following properties as shown below in the figure.

Label Control
Name: lblName
Text: Name

Label Control
Name: lblPassword
Text: Password
Label Control
Name: lblResult
Text: Result

Label Control
Name: lblOutput
Text: 

TextBox Control
Name: TextBoxName
Text: 

TextBox Control
Name: TextBoxPassword
Text:
PasswordChar: *

Button Control
Name: btnGetID
Text: Get ID


Now, add the Web Reference of the Web Services to the Project.

Right-click on the DOTNETCLIENT from the Solution Explorer and click on Add Web Reference as shown below.


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.

Click on GO - as shown below in the figure it will show the service with its method(s) available under it.


Click on the Add Reference button as shown above.

This will bring a new screen with Web Reference added to the project via Solution Explorer as shown below.


Now, double click the button GetID on the form editor to view the code as shown below in the figure.

Add the following code for the Sub btnGetID_Click().

Dim strResult As String 'Output result for ID
Dim objWebRef As New WebReference.StoreAccessLocalService

'Call loginuser function and display the result ID to the lblOutput control
lblOutput.Text = objWebRef.loginUser(TextBoxName.Text, TextBoxPassword.Text)


Once you have added the code, go to the top level menu, select Build > select Build Solution as shown above in the figure.

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 should be 'U2'.


Now with this we have successfully run a .NET client accessing our web services



Create Perl Client :

To create a Perl client we need the SOAP::Lite module to invoke methods on deployed web services.

First of all download the latest version of SOAP::Lite and follow the standard Perl module installation procedures by entering the very familiar command sequence:

perl Makefile.PL
make
make test
make install


If you have the CPAN.pm module installed on your machine and you are connected to the Internet, then run the following sequence of commands as shown below:

[vishal@vishal vishal]$ perl -MCPAN -e shell
cpan shell -- CPAN exploration and modules installation (v1.61)
ReadLine support available (try 'install Bundle::CPAN')
cpan> install SOAP::Lite
CPAN: Storable loaded ok
CPAN: LWP::UserAgent loaded ok
Fetching with LWP:
ftp://mirror.aarnet.edu.au/pub/perl/CPAN/authors/01mailrc.txt.gz
Going to read y/sources/authors/01mailrc.txt.gz
CPAN: Compress::Zlib loaded ok
Fetching with LWP:
---------------------------------------------
---------------------------------------------
---------------------------------------------
CPAN: Digest::MD5 loaded ok
Fetching with LWP:
ftp://mirror.aarnet.edu.au/pub/perl/CPAN/authors/id/K/KU/KULCHENKO/CHECKSUMS
Checksum for y/sources/authors/id/K/KU/KULCHENKO/SOAP-Lite-0.55.tar.gz ok

cpan> bye
Lockfile removed.
[vishal@vishal vishal]$


If you are using ActiveState Perl on Windows the equivalent would be the 'ppm' command.

Note : For more information on the SOAP::Lite module please refer to this site http://www.soaplite.com/beta/install.html.

Now let's create a Perl client to invoke the logInUser method on the deployed web service named MyStoreLoginService.

Create a file named webServiceClient.pl and add the following code shown below.

#
# WebServiceClient.pl
#
# Test client for MyStoreLoginService Web service
# Apache Axis - Chapter 9 'Creating Web Services'
#
use SOAP::Lite ;

my $myStoreLoginService = SOAP::Lite->service('http://localhost:8080/axis/services/MyStoreLoginService?wsdl');
my $username = $myStoreLoginService->loginUser("ANDY","PASSWD");
print "MyStore login details : Andy's username is : $username /n";



Save this file, and execute it to see the result shown below.

[vishal@vishal vishal]$ perl WebServiceClient.pl
MyStore login details : Andy's username is : U2
[vishal@vishal vishal]$


Now with this we have successfully run a Perl client accessing the web service.

ros入门(八)---TF坐标转换 TF(TransForm),就是坐标转换,包括了位置和姿态两个方面的变换。 阅读详情

相关推荐

cadence—virtuosoic617的使用技巧收集区

cadence使用

qq_33599939的博客 3万+

JBOSS服务部署端口冲突问题

服务端口冲突问题的解决方法,一般修改如下三个文件中的部分端口就可以了。   1、jboss5/server/default/conf/bindingservice.beans/META-INF/bindings-jboss-beans.xml   2、./server/default/deploy/jbossweb.sar/server.xml   3、./server/defaul...

HogwartsRow 321

由异常的测试眼图引发的深入思考

信号测试中出现“双眼皮”的眼图测试效果,可能的导致因素总结如下:PCB通道阻抗设计不匹配,负载端出现严重反射;发射端采用了不当的信号预处理;接收器均衡处理不当;通道串扰严重... 基于以上的假设,本文就逐一分析下这些因素到底是如何对正常的信号眼图造成影响的。

一只豌豆象的博客 3067

eclipse离线安装spring tools suite (sts) -创建springboot项目

试过在线安装,没有成功。 1.我的eclipse版本: 下载sts插件:不一致可以修改版本或自行找插件下载。 http://download.springsource.com/release/TOOLS/update/3.8.2.RELEASE/e4.6/springsource-tool-suite-3.8.2.RELEASE-e4.6.1-updatesite.zip 2.打开eclipse 如下图:点击help--install new software 3.选择下载的插件 1

hsc从容的博客 1570

[Python图像处理] 一.图像处理基础知识及OpenCV入门函数

该系列文章是讲解Python OpenCV图像处理知识,前期主要讲解图像入门、OpenCV基础用法,中期讲解图像处理的各种算法,包括图像锐化算子、图像增强技术、图像分割等,后期结合深度学习研究图像识别、图像分类应用。希望文章对您有所帮助,如果有不足之处,还请海涵~ 同时推荐作者的C++图像系列知识: [数字图像处理] 一.MFC详解显示BMP格式图片 [数字图像处理] 二.MFC单文档分割窗...

杨秀璋的专栏 7万+

【局部规划模块曲线算法】曲线平滑介绍

本文先对轨迹平滑问题做个简单的介绍,具体内容后续再更,其他模块可以参考去我其他文章提示:以下是本篇文章正文内容(1)适合给移动机器人运动的路径【满足运动学,高阶平滑】(2)高阶的运动学不能够突变的【至少三阶的加速度不能突变,最好四阶的jerk和五阶的snap也不能突变】(3)在转弯的地方不会停下来(4)加减速均衡,节省能量(5)节省时间的。

qq_35635374的博客 5725

【JBoss】4. 配置JBoss Web服务器

JBoss Web服务器建立在Apache Tomcat 6.0的基础上,结合了Tomcat的多功能性和Apache HTTP服务器的速度。 配置URL路径 针对客户端传来的一个URL(协议 :// 域名 : 端口号 / 上下文路径 / 资源),JBoss Web服务器如何确定调用哪个应用程序? 1、server.xml配置连接器:协议、端口号 配置文件: \

Alpha's 学习笔记 7476

英飞凌TC3xx之一起认识GTM系列(一)先来认识GTM架构

本文讲述英飞凌TC3xx的通用计时器GTM的架构。

无所适从的我的博客 4605

集合排序,求出最大值,最小值,排序

package com.xuli.test;import java.util.ArrayList;import java.util.Collection;import java.util.Collections;import java.util.Iterator;import java.util.List;import java.util.Map;import java.util.Random;i

xulimessage的专栏 946

【即插即用模块】注意力篇 | TGRS 2025 | CDFIM:通道+空间多尺度注意力,双模态特征融合增强,性能翻倍!

C2DFF-Net提出了一种轻量级跨模态特征融合模块CDFIM,通过模态差异感知和多尺度深度滤波增强双模态互补信息。该模块采用通道-空间注意力协同机制,以极低计算成本(仅增加0.26M参数)提升多模态目标检测性能,在三个遥感数据集上平均提升mAP约1.7%。适用于无人机等边缘设备的实时检测任务,为跨模态融合提供高效解决方案。

主要更新底层视觉(去噪、超分等)相关的科研内容,形式为【论文精读】+【论文复现】 637

Python全栈入门到实战【基础篇 04】核心基础:变量与4种基础数据类型(int/float/str/bool)

本文介绍了Python编程中的变量和四种基础数据类型,作为后续所有语法的入门前提。变量是数据的“容器”,解决数据复用问题,而数据类型决定数据能进行的操作。文章详细讲解了变量的定义语法、命名规则(强制语法和推荐风格)、赋值与修改原理,并通过实操示例展示其应用场景。正确使用变量可以提升代码复用性、简化修改并增强可读性,是编程效率的核心原则。掌握这些基础知识能避免90%的新手语法错误,为学习更复杂的Python语法打下坚实基础。

那些看似不起波澜的日复一日,会在某天让你看到坚持的意义 4366

Access Webservice from Android

Supported Operating Systems Windows XP (32-bit) or Vista (32- or 64-bit)Mac OS X 10.5.8 or later (x86 only) Linux (tested on Linux Ubuntu Hardy Heron) Supported Development Environments Ecli

tomcat的专栏 789

从 Service Entry Sheet 按 PO 行项目追溯服务行:PACKNO 与 ESLL 层级解包实战

摘要: SAP MM模块中,外部服务采购的数据结构较为复杂,服务明细并非直接存储在采购订单行项目表EKPO中,而是通过PACKNO关联到服务包表ESLL。本文解析了从采购订单行项目EBELN+EBELP获取服务行号SRVPOS的方法,重点分析了服务包的层级结构(根包、子包SUB_PACKNO),并提供了兼容合同项目的ABAP代码实现。通过EKPO-PACKNO定位根包后,需结合ESUC和ESLL表逐层解析子包,最终获取服务明细数据,解决了服务采购场景下的数据关联难题。(149字)

2007 年 ~ 2025 年,深耕 SAP 技术 18 年 184

Tutorial for building J2EE Applications using JBOSS and ECLIPSE (9)

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 a

Zero'Coffee 1906

win10 跳过U8环境检测的IE WebControls.rar

win10 安装u8的时候 提示IE WebControls 不通过,这个工具可以欺骗u8的检查。 跳过U8环境检测的IE WebControls。提示导入失败后,重新检测通过。

文档:亲测可用解决vnc灰屏,黑屏,鼠标大黑叉情况

主要解决vnc-viewer灰屏,黑屏,鼠标大黑叉等现象,详细见文档。

Tutorial for building J2EE Applications using JBOSS and ECLIPSE -2

Chapter 2. Overview Of J2EE Technology and ConceptsThe Java 2 Enterprise Edition (J2EE) is a multitiered architecture for implementing enterprise-class applications and web based applications. T

阿龙专栏 2238

lwip-2.0.3

lwip是瑞典计算机科学院(SICS)的Adam Dunkels 开发的一个小型开源的TCP/IP协议栈。实现的重点是在保持TCP协议主要功能的基础上减少对RAM 的占用。

Tutorial for building J2EE Applications using JBOSS and ECLIPSE Chapter 3

在阅读这一章的时候,基本没有什么障碍,但是有一个地方文章是写错了。 在Create DAO Interface  那一节中“Go to src > add package named au.com.tusc.dao > Add a class StoreAcessDAOImpl in that package”红色字体错了,应该是StoreAccessDAOImpl。 还有就是因为使用不同版本的j

中国 IT 应用/ Adapting information technology in china 1206

STM32F407中文手册

STM32f407中文手册 本参考手册面向应用开发人员,提供有关使用 STM32F405xx/07xx、STM32F415xx/17xx、 STM32F42xxx 和 STM32F43xxx 微控制器存储器与外设的完整信息。STM32F405xx/07xx、STM32F415xx/17xx、STM32F42xxx 和 STM32F43xxx 构成一个微 控制器系列,各产品具有不同的存储器大小、封装和外设。有关订购信息以及器件的机械与电气特性,请参见数据手册。有关 ARM Cortex™-M4F 内核的信息,请参见《Cortex™-M4F 技术参考手册》。

Tutorial for building J2EE Applications using JBOSS and ECLIPSE -5

Chapter 5. Creating a BMP Entity BeanThis chapter describes how to create a Bean Managed Persistence (BMP) EJB component. We will create two BMP beans, Customer and Manager, as shown below. The

阿龙专栏 1733

Tutorial for building J2EE Applications using JBOSS and ECLIPSE

Table of ContentsTutorial.PrefaceAbout the AuthorsAcknowledgmentsDisclaimerIntroductionPrerequisites for this tutorialTools re

阿龙专栏 4632

Tutorial for building J2EE Applications using JBOSS and ECLIPSE -7

Chapter 7. Creating a Message Driven BeanThis chapter covers how to create a Message Driven Bean (MDB) EJB component. We will create two MDB beans, DeliverItems and RequestItems as shown below.

阿龙专栏 1499

Tutorial for building J2EE Applications using JBOSS and ECLIPSE -1

Chapter 1Configuration of ECLIPSE to use JBOSS and LOMBOZInstall Eclipse. First of all we have to set up Eclipse Integrated Development Environment (IDE) with JBOSS as our application server.

阿龙专栏 1951

Tutorial for building J2EE Applications using JBOSS and ECLIPSE(1)

Chapter 1Configuration of ECLIPSE to use JBOSS and LOMBOZInstall Eclipse. First of all we have to set up Eclipse Integrated Development Environment (IDE) with JBOSS as our application server.So go to

Zero'Coffee 1369

Tutorial for building J2EE Applications using JBOSS and ECLIPSE Chapter 1

现在才补回chapter的阅读经历是因为觉得有一个地方的确要提一下。 在安装配置的时候,资料上说明是使用jboss-3.2.1和lomboz.21_02,我决定使用jboss 3.2.5和lomboz 213。虽然对jboss新增的版本特性不清楚,但是我想既然能升级,已经是解决了已经遗留的问题。但是我在配置的时候却给我增添了麻烦。lobmboz 213并没有对jboss 3.2.5有相应的配置文件

中国 IT 应用/ Adapting information technology in china 1265

Tutorial for building J2EE Applications using JBOSS and ECLIPSE Chapter 2 part 2

J2EE中的分布式应用(Distributed Architecture in J2EE ) 刚好在huihoo论坛看了一篇文章说到如何提高jboss的RMI/IIOP的效率问题,“有个应用是客户端swing+j2ee SERVER ,跑在内网没问题的。现在有个客户,很多分支机构,都是通过adsl(2m带宽)连到总部。j2ee服务器放在总部,感觉特别慢”,这个问题我现在还找不到解决的方法。刚好又看

中国 IT 应用/ Adapting information technology in china 1930

Tutorial for building J2EE Applications using JBOSS and ECLIPSE(3)

Chapter 3. Creating a Stateless Session BeanThis chapter covers how to create a stateless session EJB component. This bean will be responsible for authenticating the user by communicating with the dat

Zero'Coffee 1136
上一篇: Tutorial for building J2EE Applications using JBOSS and ECLIPSE -8
下一篇: 采用Hibernate的简单数据访问层
jhlcss
博客等级 码龄25年 1粉丝 23原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值