FAQ when using Apache Axis deploys a web service and its solution

xiaoxiao2021-03-06  46

November 2003

This article details common issues and solutions when deploying web services as a Web service platform in a Linux environment. I sincerely hope this article developers in Web services or readers who are interested in Web services can play a certain help.

1 Introduction With the development and maturity of web service technology, its convenience and ease of use have gradually been accepted by people, and more and more partners have started using Web services to achieve data interfaces between partners. Using the Apache Axis and Linux platforms are a low-cost web service solution, but the FAQ of the Apache Axis document is not rich enough to developers. This article organizes the issues and solutions you encounter when using Axis. Developers dedicated to Web services and readers who are interested in this aim to help everyone save some valuable time. Basic knowledge about Web services, readers can read documents recommended in the reference. The author has not introduced the installation method of Apache and Resin in the text, and the reader can refer to the documentation of the relevant website.

The software environment used by the author is as follows.

Operating system: Red Hat Linux 7.2

Web server: Apache 1.3.27

Application Server: Resin 2.1.8 (http://www.caucho.com/)

SOAP server: Apache Axis 1.1

XML parser: XERCES 2.5.0, Xalan 2.5.1

JDK version: JDK 1.4.1

2 Frequently asked questions and solutions when using AXIS

2.1 What JAR files needed to run on AXIS

After the AXIS is unpack, copy the JAR file under the AXIS-1_1 / WebApps / Axis / Web-INF / LIB / directory to the / usr / local / apache / htdocs / web-inf / lib directory (the directory of web applications) ). The following JAR files should be included.

Axis-ant.jar

Axis.jar

Commons-discovery.jar

Commons-logging.jar

Jaxrpc.jar

Log4j-1.2.8.jar

Name.txt

saaj.jar

Wsdl4j.jar

If you need to use the Test page provided by AXIS, copy the files in the AXIS-1_1 / WebApps / Axis / Directory to the / usr / local / apache / htdocs / axis / directory. The following documents should be included.

Echoheaders.jws

Fingerprint.jsp

Happyaxis.jsp

INDEX.HTML

2.2 Which XML parser should be used?

The XML parser selection is not properly caused to cause some inexplicable issues when using Apache Axis.

Since Apache Axis does not test the XML parser built into the RESIN, it is recommended that the reader uses the Xerces XML parser that has been tested. You can download the Xalan's Java version XLT processor from http://xml.apache.org/xalan-j/index.html, which contains Xerces's Java version XML parser, and does not need to download the XML parser separately.

After Xalan 2.5.1 Unpack, copy the XerceptImpl.jar, XML-APIS. Jar and Xalan.jar under the bin / directory to the lib / directory of the RESIN installation directory, such as / usr / local / resin / lib.

Edit the Profile file under the / etc / directory, find the location where the ClassPath environment variable is set, and then add the following content (B shell).

XmlParser = $ RESIN_HOME / LIB / Xalan.jar: $ RESIN_HOME / LIB / XERCESIMPL.JAR: $ RESIN_HOME / LIB / XML-APIS. JAR

Export ClassPath = $ XMLPARSER: $ ClassPath 2.2.1 Precautions If the other XML parser settings in the ClassPath should be removed from the set of ClassPath environment variables to avoid conflicts.

2.3 How to use Xerces XML parser in RESIN

The XMLPARSER of RESIN will be replaced with Xerces's XMLParser by modifying resin.conf. Add the following settings to the web application configuration corresponding to Resin.conf.

Restart RESIN after the configuration is complete.

2.4 How to troubleshoot an exception in the XML parser

2.4.1 Problem Description

Use http://test.com/axis to view the deployed service, the AXIS internal error is displayed, and the exception information about the WSDD configuration is displayed. If you delete server-config.wsdd under the web-inf directory, you can see it normally, but you can only see the default services of Administice and Version, and the service that is later deployed.

2.4.2 Analysis of Causes

AXIS automatically generates an XML file for a name Server-Config.WSDD in a web application's web-inf / directory, which records deployed Web services. When each deployment of a new web service, AXIS adds the description information of the new service to Server-Config.wsdd.

The XMLParser used by the fault site is RESIN's built-in XMLParser, and Axis does not have a compatibility test to view the web service information, and you need to obtain deployed Web service description information when viewing web service information. When Server-Config.WSDD is more complicated, RESIN has an abnormal XMLParser due to some reasons, causing an internal error in Axis. The web service description information recorded in Server-Config.WSDD does not exceed less.

2.4.3 Solution

Modify resin.conf, replace the XMLPARSER of Resin to XMLParser. See Section 2.3 of the replacement method.

2.4.4 Small knot

If the AXIS report is an error related to an XML parser, it is recommended that the reader replaces the XML parser of the application server with reference to this section, will help the problem solving.

2.5 How to integrate AXIS to RESIN or other application servers

Axis is running in a servlet, and RESIN is equivalent to a servlets container, so as long as it is configured, the AXIS can be run in the Resin environment, which is also applicable to other application servers other than RESIN. The method of configuring the AXIS in RESIN is as follows.

Copy the servlet configuration item in AXIS-1_1 / WebApps / Axis / Web-INF / Web.xml to the corresponding web application configuration in Resin.conf. The following is usually included.

Axisservlet

apache-axis servlet

Org.apache.axis.transport.http.axisservlet

adminServlet

Axis Admin Servlet

Org.apache.axis.transport.http.adminservlet

100

SOAPMONITORSERVICE

SOAPMONITORSERVICE

Org.apache.axis.monitor.soapmonitorService

SOAPMonitorport

5001

100

Axisservlet

/ axis / servlet / axisservlet

Axisservlet

*. jws

Axisservlet

/ services / *

SOAPMONITORSERVICE

/ soapmonitor

adminServlet

/ axis / servlet / adminservlet

->

http://www.w3.org/tr/2003/wd-wsdl12-20030303/#ietf-draft

For now We go with the basic 'it's xml' response ->

WSDL

text / xml

XSD

text / xml

2.6 What development tools have been provided in AXIS?

Apache Axis provides two development tools for WSDL2JAVA and Java2WSDL.

WSDL2JAVA generates server and client code using known WSDL files. The WSDL file can be provided by partners, or it can be generated using Java2WSDL. Java2WSDL generates a WSDL file according to the existing Java class file, and the Java class file can be an interface class file and does not need to be detailed.

In addition, Axis also provides SOAPMONITORAPPLET and TCPMON tools to monitor web services.

2.7 How to Generate Web Services Services and Client Codes

2.7.1 Generate or obtain WSDL files

Java2wsdl is a tool for AXIS to get a WSDL file using Java class files. Class files can be compiled using interface files, such as the following interface files Softwareprice.java.

Package Samples.userGuide.example6;

/ **

* Interface Describing a Web Service To Set and Get Software Prices.

** /

Public interface softwareprice {

Public void setWidgetPrice (String SoftwareName);

Public String getWidgetPrice (String SoftwareName);

Compile SoftwarePrice.java.

Javac SoftwarePrice.java

Copy softwareprice.class to the correct Package path.

Execute the following command:

Java Org.Apache.axis.wsdl.java2wsdl -o sp.wsdl -l "http://test.com:80/services/softwareprice" -n "urn: softwareprice"

-p "Samples.userGuide.example6" "URN: EXAMPLE6" Samples.userGuide.example6.software Price The meaning of each parameter is as follows.

-o: Specifies the file name of the WSDL file output.

-l: The location of the specified service.

-n: The target namespace of the WSDL file.

-p: Specifies a mapping from Package to the namespace, where there is a plurality of mappings.

The last class file contains the interface of the web service.

After the command is executed, the sp.wsdl file will be generated.

If you can't find the specified class file by setting the set of ClassPath, Axis will report an exception, as shown below.

Java.lang.classNotFoundException: Samples.userGuide.example6.softwareprice

AT java.net.urlclassloader $ 1.Run (urlclassloader.java:198)

AT java.security.accessController.doprivileged (Native Method)

......

If the above problem occurs, check if the class file is copied to the correct location or the ClassPath settings is correct.

After generating a WSDL file, you can use the WSDL2JAVA tool provided by Axis to generate server code for web services and client code.

2.7.1.1 Precautions

WSDL files can also be provided by partners. In this case, partners are often a provider or standard interface of the web service, and developers can generate clients or server code according to the established WSDL file.

2.7.2 Generate a client or server code

The WSDL2JAVA tool is used to generate a client memory code, a server frame (SKELETON) code, and the data type file in the WSDL (generated Java code). Developers only need to add relevant business logic code to the frame code to get a complete web service code, so the tool greatly reduces the company's encoded burden. WSDL2JAVA use is as follows.

Java org.apache.axis.wsdl.wsdl2java --server-side --skeletondeploy true myservice.wsdl

The following file will be generated after performing the above command.

Interface file deployment descriptor file No. File usage 1.deploy.wsddMyService services 2.MyService.javaMyService services 3.MyServiceService.java get MyService service interface file 4.MyServiceServiceLocator.java achieve MyServiceService interfaces 5.MyServiceSoapBindingImpl.java achieve MyService Interface , wherein the service end should 6.MyServiceSoapBindingSkeleton.javaMyService supplementary service logic service framework code to achieve MyService, the client stub code org.apache.axis.wsdl.Skeleton 7.MyServiceSoapBindingStub.javaMyService interfaces and services, implement the interface 8.undeploy MyService .wsdd logouts the deployment description file for MyService service

2.7.3 Write a web service client code

The client program for the web service completes the call to the web service, and the program structure is as follows.

Import com.chinavnet.zx.service.v1_0. *; // WSDL2JAVA generated package space;

Public class testclient {

Public static void main (string [] args) Throws Exception

{

Com.chinavnet.zx.service.v1_0.spinterfaceForvnetLocator Locator = new spinterfaceForvnetLocator (); // Get a Locator object locator.setMainTainSession (TRUE);

com.chinavnet.zx.service.v1_0.spinterfaceForvnetSoap service = locator.getspinterfaceForvnetSoAP (); // Get service objects

Com.chinavnet.zx.service.v1_0.detailledgerfeedbackResult feedbackres = null;

// Initialize the data type defined in the web service

Try {

Feedbackres = service.generalledgerfeedback (); // Call the web service method and get the return value

System.out.println ("FeedbackResult:");

IF (feedbackres! = null)

{

System.out.println ("SPID:" feedback ());

System.out.println ("ErrorDesc:" feedbackres.GeterRORDESBACKRES.GETERRORDESCRIPTION ());

System.out.println ("Result:" feedbackres.getResult ());

Else

{

System.out.println ("FeedbackRes is Null!");

}

} catch (java.rmi.RemoteException Re) {

// throw new junit.framework.assertionFaileDError ("Remote Exception Caught: RE);

Re.printStackTrace ();

}

} // end of main ()

} // end of testclient class

Testing client programs is very simple, compiling client programs, execute "java testclient".

2.8 How to write server code

After adding related business logic code to MyServiceSoapBindingImpl.java, compile the source program generated by WSDL2JAVA, package into a JAR file, copy it to / usr / local / apache / htdocs / web-inf / lib / directory.

2.9 How to Publish Web Services

With the deploy.wsdd file and prepare a good class file, you can post a MyService service. AXIS automatically releases adminservice after installation, using it to publish a new web service. Methods as below.

Java org.apache.axis.client.adminClient -lhttp: // localhost: 80 / service / adminservice deploy.wsdd

After the above command is executed, there is a prompt.

Processing file deploy.wsdd

done processing

2.10 Report "Types" Types are deserved but undefined "

2.10.1 Problem Description

Report the following exception when performing WSDL2JAVA:

Java.io.IOException: type {http://schemas.xmlsoap.org/wsdl/} ArrayoffaileDrecord Is Reference But not defined.2.10.2 Analysis of Cause Analysis

The above cases may be:

The type is not defined.

Used the wrong namespace.

An input error exists in the WSDL file.

2.10.3 Solution

After careful inspection, I discover the WSDL file.

S0 in Type = "S0: ArrayoffailedRecord" has a space in front, and the problem is solved after deleting the space.

2.10.4 small knot

An editing error that appears in the WSDL file may result in a "type reference but undefined" error when performing WSDL2JAVA.

2.11 What is the role of Server-config.wsdd?

Server-config.wsdd records the description of the AXIS published web service.

2.12 Report Report "Exception :: (404) Not Found"

2.12.1 Problem Description

Perform a java org.apache.axis.client.adminClient -lhttp: // localhost: 80 / service / adminservice deploy.wsdd command reports the following contents.

Processing file deploy.wsdd

Exception :: (404) Not found

Apache's Access_log is shown below.

127.0.0.1 - - [17 / SEP / 2003: 15: 56: 33 0800] "Post / Services / Adminaservice HTTP / 1.0" 404 293

2.12.2 Analysis of Causes

The relatively simple reason for this problem may be that the port is incorrect, or the URL path is not pair (for example, the directory in the path), Axis's SOAPMonitor service does not find Adminaservice by specified port or URL, you need to check the correct port number and URL path.

The relatively deep reason is much more complicated.

The author encountered by this article is the following.

Adminaservice is a published web service.

AdminClient communicates with the SOAP protocol, and you need to locate Adminaservice by specified port and URL, and there are two web-app configuration items in the resin.conf, and the summary of configuring A is as follows.

/ USR / Local / Apache / HTDOCS /

The summary of configuring B is as follows.

/ usr / local / apache / htdocs / esales /

AXIS is configured in configuration b.

DocumentRoot in httpd.conf is / usr / local / apache / htdocs /.

When using java org.apache.axis.client.adminClient -lhttp: // localhost: 80 / service / adminservice deploy.wsdd, you need to parse the URL: // localhost: 80 / service / adminservice by HTTP protocol. Because there is no services / directory in the htdocs / directory (Services is servlet-mapping in resin.conf), the application server is positioned to locate adminservice by the configuration in resin.conf, because the host named Localhost, so Resin is not The URL will be positioned in (configure B), but to configure A, there is no AXIS configuration in configuring A, not finding the URL associated with adminservice, so The previously described abnormal situation is reported. 2.12.3 Solution

After you know the reason, you can solve it as follows.

Moving all of the configuration B for Axis on configuring A, pay attention to the value of the ClassPath variable in / etc / profile accordingly.

After saving resin.conf, log in to the server (make the new ClassPath take effect), restart RESIN. Release the web service again.

Java org.apache.axis.client.adminClient -lhttp: // localhost: 80 / service / adminservice deploy.wsdd

The screen is shown below.

Processing file deploy.wsdd

done processing

The Web service is finally released.

The following Log will be seen in the Apache's Access_Log in the case of successful issuance:

TAIL -F Access_log | GREP VICE

127.0.0.1 - - [17 / SEP / 2003: 16: 05: 00 0800] "POST / Services / Adminaservice HTTP / 1.0" 200 296 "-" "AXIS / 1.1"

2.12.4 small knot

The problem description in this section may be the most abnormality that the reader encounters, but the reason is not unique. When encountering this problem, it is recommended that the reader's calm analysis of the possible causes, more experiments, and finally can be successful!

2.13 How to monitor SOAP requests and response streams

2.13.1 Introduction

How to observe request and response data after the web service is released? Recording Run Log is a traditional and effective way, but it is not convenient and intuitive for debugging. It is gratifying that AXIS provides us with tool SOAPMonitor to observe SOAP requests and response stream data, after appropriate configuration, the SOAP request and response data of the web service can be observed in real time. SOAPMonitor is a Java Applet program that is downloaded to the client via the browser. Here, you will introduce the configuration and how to use SOAPMonitor.

2.13.2 Preparing SOAPMonitor Applications

In Axis 1.1, there is no compilation of the SOAPMonitor.java program for us, but we can find the name of the SOAPMONITORAPPLET.JAVA in the AXIS-1_1 / WebApps / Axis / directory, compile themselves. After the program is compiled, the following class file is generated:

SOAPMONITORAPPLET.CLASS

SOAPMONITORAPPLET $ serviceFILTERPANEL.CLASS

SOAPMONITORAPPLET $ SOAPMONITORDATA.CLASSOAPMONITORAPPLET $ SOAPMONITORFILTER.CLASS

SOAPMONITORAPPLET $ SOAPMONITORPAGE.CLASS

SOAPMONITORAPPLET $ SOAPMONITORTABLEMODEL.CLASS

SOAPMONITORAPPLET $ SOAPMONITORTEXTAREA.CLASS

The reader needs to copy the above file to its own web application directory, this example is / usr / local / apache / htdocs / directory.

Enter the address of SOAPMonitor in the browser address, such as http://test.com/soapmonitor, the browser prompts the user to download the Applet program, after the download is complete, the reader can see in the browser window as shown in Figure 4-1. The user interface shown. If the location of the above file is incorrect, the browser reports the "Can't find the class" error. At this point, you should check if the above files have been copied to the correct directory.

Figure 2-1 Interface of SOAPMonitor

2.13.3 Release SOAPMONITOR service

After the SOAPMonitor interface shown in Figure 2-1, it does not mean that the SOAP request stream of the web service can be observed, and the SOAPMONITORSERVICE is required first. The web service is provided by AXIS, but it needs to be published by the user, the method is as follows.

Get the WSDD file deploy.wsdd of the SOAPMonitor service, as follows (you can also get to http://www.sosnoski.com/presents/java-xml/axis/axis-monitor.html copy this file):

XMLns: java = "http://xml.apache.org/axis/wsdd/providers/java">

TYPE = "java: org.apache.axis.handlers.soapmonitorhandler">

Value = "/ axis / soapmonitorservice-impl.wsdl" />

Value = "http://tempuri.org/wsdl/2001/12/soapmonitorservice-impl.wsdl" />

Value = "org.apache.axis.monitor.soapmonitorvice" />

Publish SOAPMonitor service:

Java org.apache.axis.client.adminClient -lhttp: // localhost: 80 / service / adminservice deploy.wsdd

2.13.4 Modify deploy.wsdd

Once the SOAPMonitor service is released, the monitored web service is also configured. The method is to log out of the web service, then modify the WSDD file corresponding to the service, increasing the request stream and response stream, otherwise the SOAP request and response stream is not observed.

The method of logging out of Web services is as follows.

Enter the directory where the Undeploy.wsdd file is located, execute

Java org.apache.axis.client.adminClient -lhttp: // localhost: 80 / service / adminservice undeploy.wsdd

The way to modify the WSDD file is as follows.

Take the MyService provided by AXIS as an example, make the following modifications to myService's WSDD files.

before fixing:

...

...

After the revision: (with undersired line is the newly added content)

...

...

After modifying the WSDD file, re-release the MyService service:

Java org.apache.axis.client.adminClient -lhttp: // localhost: 80 / service / adminservice deploy.wsdd

2.13.5 Start SOAPMonitor Applications

Start the SOAPMonitor applet on the method described in Section 2.13.2.

Use the client program to test myService service:

# Java Samples.userGuide.example3.client -lhttp: //vnet.sohu.com/services/myservice "test" results are: You Typed: TEST

Note that you must first start the SOAPMonitor applet, then call the Web service to observe the SOAP request and response stream.

2.13.6 Observation SOAP request and response stream

At this time, SOAP and request and response messages can be observed in the window of the SOAPMonitorApplet, as shown in Figure 2-2.

Figure 2-2 SOAP request and response of MyService

2.4 Report When using the client program to test the Web service "Exception :: (404) Not found

2.14.1 Problem Description

After the Web service interface is written and released, the client test program does not receive the return result of the web service, and the access record can also be seen in the LOG of Apache or Resin. However, the test program returns to 0 (success). In the case where the Web service is not deployed, it is also the result, so that the call is the WSDL file provider's Web service interface, which may be provided with the other party. The file is related.

2.14.2 Cause Analysis

Partner calls Web services can be successful, from the web service host's own client call, it does not receive data, estimates that the WSDL file provided with partners is related to the client STUB code generated by WSDL2JAVA. Check the stub code and find that its SOAPAction points to the test address of the partner.

2.14.3 Solution

Modify the soapaction in the stub code to change to SP (Service Provider) its own web service URL. Re-compile the program and issue web services, and the problem is resolved.

_Call.SetSoAPactionuri ("SP own web service address");

2.14.4 Small knot

The problem description of this section appears in the WSDL file that the Web service provider is provided by the WSDL file provided by the partner unified. If you encounter such problems, readers can directly check the relevant parts of the code that WSDL2JAVA automatically generates.

You can see settings similar to the following contents in the WSDL file.

among them

That is, the URL of the published Web service is used for client calls.

2.15 How to list the published web services

Use the following command:

Java org.apache.axis.client.adminClient -lhttp: // localhost: 80 / service / list

In fact, the output of this command is the content of the server-config.wsdd file.

2.16 Report "Call the target exception" when publishing the web service

2.16.1 Problem Description

Report When deploying a Web service: java.lang.reflect.InvocationTargeTexception exception.

2.16.2 Analysis of Causes

Custom name space in the WSDL file conflict with the Services name of Axis.

2.16.3 Solution

Modify the WSDL file and change the Services to another name.

2.17 The role of TargetNameSpace in the WSDL file is what targetnamespace indicates the target namespace to verify the XML document.

In the WSDL file, TargetNameSpace in should be consistent with the targetnamespace in .

2.18 Web service is deployed, but not detected

2.19 Client Program Can't find available web services

2.19.1 Problem Description

carried out

Java org.apache.axis.client.adminClient -lhttp: // localhost: 80 / service / adminservice deploy.wsdd

When done processing is displayed, it can't check that the new service is not seen in the server-config.wsdd file in the web-inf / directory.

2.19.2 Analysis of the reason

The new Web service class file is not recompiled and copied to the correct location.

2.19.3 Solution

The web service class file can be packaged as a JAR file. Set the path to the JAR file correctly in the CLASSPATH environment variable. E.g:

JAR CVF Spinterfacesoap.jar COM / ZX / Service / V1_0 / *. Class

Copy spinterfacesoap.jar to the web-inf / lib / directory, re-release the web service.

2.20 How to troubleshoot unclear errors

Sometimes, there is a bad mistake when performing client testing for web services. In order to ensure that the environment is correct, you can use the steps below to troubleshoot errors.

1. Undeploy is tested service

Java org.apache.axis.client.adminClient -lhttp: // localhost: 80 / service / adminservice undeploy.wsdd

2. Restart resin: /usr/local/resin/bin/httpd.sh restart (if you are other application servers, please restart according to the appropriate method)

3. Re-release the web service

4. Test

3 Summary currently have a lot of application servers and web service platform software, this article only introduces questions that may encounter in the process of deploying Web services as an example, which is not discussed in Web services as an example of Apache Axis and Resin. Safety problem. For how to efficiently develop and deploy web services and how to ensure the security of Web services, readers who are interested in this are also hoped to participate in the discussion. For the mistakes and shortcomings existing in the text, I hope that readers can not criticize.

Reference

Http://xml.apache.org/xerces2-j/index.html http://xml.apache.org/xalan-j/INDEX.html http://ws.apache.org/axis/ http: // Www.w3.org/tr/SOAP/ http://www.w3c.org/tr/wsdl.html http://www.caucho.com/

转载请注明原文地址:https://www.9cbs.com/read-81243.html

New Post(0)