About axisfault)

Source: Internet
Author: User
Tags apache tomcat
-06-26 axisfault description generally, exceptions may occur in the services of inevitable Web services. For example, after a service receives a SOAP request message and obtains the payload, perform a database update operation, and sqlexception occurs during the update operation. In this case, you need to tell the client (calling Web Service) that an exception has occurred, axis2 encapsulates the exception into an axisfault and throws it. Axis2 encapsulates exceptions of any type, regardless of whether the exception is a running exception or a custom exception. The following is an introduction to the axisfault API:
 
Public classAxisfaultExtends RemoteException
An exception which maps cleanly to a soap fault. This is a base class for exceptions which are mapped to faults. See also: Soap1.2 specification, soap1.1 faults Soap faults contain 1. A fault string 2. A fault code 3. A fault actor 4. Fault details; an XML tree of fault specific elements (the red part is required for an axisfault Construction) As soap1.2 faults are a superset of soap1.1 faults, this type holds soap1.2 fault information. When a soap1.1 fault is created, spurious information can be discarded. Mapping
 
Soap1.2 soap1.1
Node faultactor
 
Reason (0). Text faultstring
 
Faultcode. Value faultcode
 
Faultcode. subcode (discarded)
 
Detail detail
Role (discarded)
One of the constructors is: Axisfault (Org. apache. axiom. soap. soapfaultcode, org. apache. axiom. soap. soapfaultreason, org. apache. axiom. soap. soapfaultnode, org. apache. axiom. soap. soapfaultrole, org. apache. axiom. soap. soapfaultdetail) Because soapfault of soap 1.1 and soapfault of soap 1.2 have different structures, soapfault constructed in the form of 1.2 cannot be understood by soapfault of Version 1.1, resulting in exceptions, the exception content is often the following message:
 
Org. Apache. Axiom. Soap. soapprocessingexception: expecting soap 1.1 Implementation
Of soap fault code. But already ed some other implementation
Generally, soapfault is constructed through the factory class soapfactory, and soap11factory and soap12factory both inherit soapfactory and correspond to two different SOAP protocol versions. Soapfault of soap1.1 can be converted to soapfault of soap1.2, but it is troublesome. The following is an example of soapfault: 1. Create the testfault project, as shown in the directory structure. The class library uses the class library in the latest axis2software downloaded from http://ws.apache.org/axis2. Article The latest axis2 version is 1.1.1 ). Download and decompress the package. Copy all the jar files in the Lib folder in the decompressed directory to $ {eclipse. home}/workspace/testfault/src, the directory structure may be different. You only need to add these jar files to the build path of the testfault project. Compile the server and client classes: Faultservice. Java Package L. z. z; import javax. XML. namespace. QNAME; import Org. apache. axiom. om. omabstractfactory; import Org. apache. axiom. om. omelement; import Org. apache. axiom. soap. soap12constants; import Org. apache. axiom. soap. soapbody; import Org. apache. axiom. soap. soapenvelope; import Org. apache. axiom. soap. soapfactory; import Org. apache. axiom. soap. soapfault; import Org. apache. axiom. soap. soapfaultcode; import Org. apache. axiom. soap. soapfaultreason; import Org. apache. axiom. soap. soapfaulttext; import Org. apache. axiom. soap. soapfaultvalue; import Org. apache. axis2.axisfault; public class faultservice { Public omelement testfault (omelement soap) throws axisfault { If (soap. getlocalname (). Equals ("Satan ")){ Throw getaxisfault ("Satan "); } Throw getaxisfault ("God "); } Public axisfault getaxisfault (string message ){ Soapfactory factory = omabstractfactory. getsoap12factory (); Soapenvelope envelope = factory. createsoapenvelope (); Soapbody body = factory. createsoapbody (envelope ); Soapfault = factory. createsoapfault (body ); Soapfaultcode faultcode = factory. createsoapfaultcode (soapfault ); Soapfaultreason faultreason = Factory. createsoapfaultreason (soapfault ); Soapfaultvalue faultvalue = factory. createsoapfaultvalue (faultcode ); Soapfaulttext reasontext = Factory. createsoapfaulttext (faultreason ); QNAME value = New QNAME (soap12constants. soap_envelope_namespace_uri, Soap12constants. soap_fault_value_sender, Soap12constants. soap_default_namespace_prefix ); Faultvalue. settext (value ); Reasontext. settext (Message ); Axisfault = new axisfault (soapfault. getcode (), soapfault . Getreason (), null ); Return axisfault; } } Testfaultservice. Java Package L. z. z. test; import Java. io. fileinputstream; import Java. io. filenotfoundexception; import javax. XML. stream. factoryconfigurationerror; import javax. XML. stream. xmlinputfactory; import javax. XML. stream. xmlstreamexception; import javax. XML. stream. xmlstreamreader; import Org. apache. axiom. om. omelement; import Org. apache. axiom. om. impl. builder. staxombuilder; import Org. apache. axis2.axisfault; import Org. apache. axis2.addressing. endpointreference; import Org. apache. axis2.client. options; import Org. apache. axis2.client. serviceclient; public class testfaultservice { Private Static endpointreference targetepr = new endpointreference ( "Http: // localhost/axis2/services/faultservice "); Public static void main (string [] ARGs) throws filenotfoundexception, Factoryconfigurationerror, xmlstreamexception { Omelement requestsoapmessage = Getsoaprequestmessage ("Sample/Satan. xml "); Options = new options (); Options. setaction ("urn: testfault "); Options. setto (targetepr ); Serviceclient sender = NULL; Try { Sender = new serviceclient (); Sender. setoptions (options ); Sender. sendreceive (requestsoapmessage ); } Catch (axisfault e ){ System. Out. println (E. getmessage ()); } } Public static omelement getsoaprequestmessage (string filepath) Throws filenotfoundexception, xmlstreamexception, Factoryconfigurationerror { Xmlstreamreader reader = xmlinputfactory. newinstance () . Createxmlstreamreader (New fileinputstream (filepath )); Staxombuilder builder = new staxombuilder (Reader ); Omelement requestmessage = builder. getdocumentelement (); Return requestmessage; } } Then write the services. xml file with the following content: < ServiceGroup > < Service Name = "Faultservice" > < Description > This is the service for revoking certificate. </ Description > < Parameter Name = "Serviceclass" Locked = "False" > L. Z. Z. faultservice </ Parameter > < Operation Name = "Testfault" > < Messagereceiver Class = "Org. Apache. axis2.receivers. rawxmlinoutmessagereceiver" /> < Actionmapping > URN: testfault </ Actionmapping > </ Operation > </ Service > </ ServiceGroup > This article assumes that the reader has already had the foundation for axis2 to develop Web services. Therefore, we will not explain the above classes and configuration files. Please forgive me. Package it into the faultservice. AAR file, which contains the following content: faultservice. AAR --- L --- Z --- Z --- Faultservice. Class --- META-INF --- Manifest. MF --- Services. xml Place the AAR package in the $ {tomcat_home} \ webapps \ axis2 \ WEB-INF \ Services Directory. Start tomcat, go to http: // localhost: {port}/axis2, and select services to check whether the service is successfully deployed. If the deployment is successful, go to the next step. Otherwise, check the preceding steps again. The following figure shows the successful execution of the testfaultservice class. The error message is as follows: Code Refer to the classes listed above) Transport Error 500. error message is Apache Tomcat/5.5.17-Error Report

HTTP status 500-

type exception report

message

description the server encountered an internal error () that prevented it from fulfilling this request.

exception

<PRE> org. Apache. Axiom. Soap. soapprocessingexception: Expecting soap 1.1 Implementation of soap fault code. But already ed some other implementation Org. Apache. Axiom. Soap. impl. rawm. soap11.soap11faultimpl. setcode (Soap11faultimpl. Java: 81) Org. Apache. axis2.engine. axisengine. extractfaultinformationfrommessagecontext ( Axisengine. Java: 330 ) Org. Apache. axis2.engine. axisengine. createfaultmessagecontext ( Axisengine. Java: 249 ) Org. Apache. axis2.transport. http. axisservlet. handlefault ( Axisservlet. Java: 317 ) Org. Apache. axis2.transport. http. axisservlet. dopost ( Axisservlet. Java: 277 ) Javax. servlet. http. httpservlet. Service ( Httpservlet. Java: 709 ) Javax. servlet. http. httpservlet. Service ( Httpservlet. Java: 802 ) The red part is the key to the problem. This part means that the client expects a soap fault code of soap 1.1, but what we actually provide is a 1.2 Implementation, therefore, if the client cannot handle the error, an exception is thrown, and the actual exception is the blue font under the red font: Soap11faultimpl. setcode Because it is a soap fault code of soap1.2, it cannot be processed and can only run exceptions. The incoming SOAP request message observed by using soapmonitor is: note that axis2 automatically adds a layer of encapsulation to the incoming message during transmission (before the Web service method testfault is not reached) it is transmitted in this form, while axis2 uses the default soap version of 1.1. Therefore, no matter whether the axisfault constructed in the faultservice class is soap11 or soap12, in the end, we will try to convert it to the soap11 format. Once a version conflict occurs, an exception will occur. If axisfault has not been returned to the client, an exception has occurred (the content of soapresponse in it is null ). Solution 1: Convert the fault of soap12 to the fault of soap11, so that the soapfault constructed by soap11 can be transmitted. However, the name is the same as that of soap12 (for example, a server exception is not a "server" of soap11, but a "handler" of soap12 "). Although this method can be implemented, once the client is soap12, what should we do? Lack of connectivity. Solution 2: make a judgment when constructing soapfault. If the client uses soap12, use soap12factory to construct it; otherwise, use soap11 to construct it. In this case, you need to set the soap version used on the client. Use the following method: Options Options = New Options (); Options. setsoapversionuri (soap12constants. soap_envelope_namespace_uri ); In this way, you can set the soap encapsulation used during transmission to soap12. In this case, the SOAP request and response messages observed through soapmonitor are as follows: Options. setsoapversionuri ( Soap12constants. Soap_envelope_namespace_uri ); Set the version of the soap to be used. Some clients may not support the SOAP protocol of soap12, so sometimes it is necessary to install and replace soap11 to soap12.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.