Deploying WebService notes based on Axis 1.4 (4)

Source: Internet
Author: User

The preceding three chapters provide examples of WebService server and client that generate Java code through the WSDL file. Next we will encrypt WebService through wss4j.

 

1. Download wss4j. jar or use Google to download it.

2. Put wss4j. Jar under vacsyncservice_wss4j Project/webcontent/WEB-INF/lib. The vacsyncservice_wss4j project may be a bit dizzy. In fact, this is the name of the vacsyncservice project we used earlier.

3. Configure deploy. WSDD in Web-info.

<! -- Use this file to deploy some handlers/chains and services -->
<! -- Two ways to do this: -->
<! -- Java org. Apache. axis. Client. adminclient deploy. WSDD -->
<! -- After the Axis server is running -->
<! -- Or -->
<! -- Java org. Apache. axis. utils. Admin Client | Server deploy. WSDD -->
<! -- From the same directory that the axis engine runs -->

<Deployment
Xmlns = "http://xml.apache.org/axis/wsdd"
Xmlns: Java = "http://xml.apache.org/axis/wsdd/providers/java">

<! -- Services from syncnotifyspserviceservice WSDL service -->

<Service name = "syncpolicysp" provider = "Java: RPC" style = "RPC" use = "encoded">
<Requestflow>
<Handler type = "Java: org. Apache. ws. axis. Security. wsdoallreceiver">
<Parameter name = "passwordcallbackclass" value = "pwcallback"/>
<Parameter name = "action" value = "userNameToken"/>
</Handler>
</Requestflow>
<Parameter name = "wsdltargetnamespace" value = "http://soap.bossagent.vac.unicom.com"/>
<Parameter name = "wsdlserviceelement" value = "syncpolicyspserviceservice"/>
<Parameter name = "schemaunqualified" value = "http://rsp.sync.soap.bossagent.vac.unicom.com, http://req.sync.soap.bossagent.vac.unicom.com"/>
<Parameter name = "wsdlserviceport" value = "syncpolicysp"/>
<Parameter name = "classname" value = "com. Unicom. VAC. bossagent. Soap. syncpolicyspsoapbindingskeleton"/>
<Parameter name = "wsdlporttype" value = "syncpolicyspservice"/>
<Parameter name = "typemappingversion" value = "1.2"/>
<Parameter name = "allowedmethods" value = "*"/>
<Parameter name = "Scope" value = "session"/>

<Typemapping
Xmlns: NS = "http://rsp.sync.soap.bossagent.vac.unicom.com"
QNAME = "ns: orderrelationupdatenotifyresponse"
Type = "Java: COM. Unicom. VAC. bossagent. Soap. Sync. RSP. orderrelationupdatenotifyresponse"
Serializer = "org. Apache. axis. encoding. Ser. beanserializerfactory"
Deserializer = "org. Apache. axis. encoding. Ser. beandeserializerfactory"
Encodingstyle = "http://schemas.xmlsoap.org/soap/encoding"
/>
<Typemapping
Xmlns: NS = "http://req.sync.soap.bossagent.vac.unicom.com"
QNAME = "ns: orderrelationupdatenotifyrequest"
Type = "Java: COM. Unicom. VAC. bossagent. Soap. Sync. Req. orderrelationupdatenotifyrequest"
Serializer = "org. Apache. axis. encoding. Ser. beanserializerfactory"
Deserializer = "org. Apache. axis. encoding. Ser. beandeserializerfactory"
Encodingstyle = "http://schemas.xmlsoap.org/soap/encoding"
/>
</Service>
</Deployment>

The red font is the added part.

 

4. Let's write encryption classes.

Import java. Io. ioexception;

Import javax. Security. Auth. Callback. Callback;
Import javax. Security. Auth. Callback. callbackhandler;
Import javax. Security. Auth. Callback. unsupportedcallbackexception;

Import org. Apache. ws. Security. wspasswordcallback;

 

Public class pwcallback implements callbackhandler {

 

 

Public void handle (callback [] callbacks) throws ioexception,
Unsupportedcallbackexception {

For (INT I = 0; I <Callbacks. length; I ++ ){

 

If (callbacks [I] instanceof wspasswordcallback ){

 

Wspasswordcallback Pc = (wspasswordcallback) callbacks [I];

// Set the password given a username

If ("user". Equals (PC. getidentifer ())){

 

PC. setpassword ("pawd ");

}

 

} Else {

 

Throw new unsupportedcallbackexception (callbacks [I], "Unrecognized callback ");

 

}

 

}

}

 

}

 

This is the server-side Encryption Class. You can see that the user is the user, and the password is the pawd. Here you can use the encryptor or algorithm class to process it as needed.

 

5. Start tomcat in myeclipse. Open CMD and enter:

C:/Apache-Tomcat-6.0.32/webapps/vacsyncservice_wss4j/WEB-INF> JAVA-djava. Ext. dir
S = "D:/workspace/vacsyncservice_wss4j/webcontent/WEB-INF/lib" org. Apache. axis. cli
Ent. adminclient-lhttp: // localhost: 8080/vacsyncservice_wss4j/services/adminservi
Ce deploy. WSDD

The WEB-INF is generated under/Apache-Tomcat-6.0.32/webapps/vacsyncservice_wss4j/server-config.wsdd/

 

6. At present, the server-side encrypted user authentication has been completed. If we call this WebService using the previous client class, the following error will be thrown:

Axisfault
Faultcode: {http://schemas.xmlsoap.org/soap/envelope/}server.generalexception
Faultsubcode:
Faultstring: wshandler: cannot load password callback class: pwcallback; Nested exception is:
Java. Lang. classnotfoundexception: pwcallback; Nested exception is:
Org. Apache. ws. Security. wssecurityexception: wshandler: cannot load password callback class: pwcallback; Nested exception is:
Java. Lang. classnotfoundexception: pwcallback
Faultactor:
Faultnode:
Faultdetail:
{Http://xml.apache.org/axis/?hostname:3abf8bc3b424428

Wshandler: cannot load password callback class: pwcallback; Nested exception is:
Java. Lang. classnotfoundexception: pwcallback; Nested exception is:
Org. Apache. ws. Security. wssecurityexception: wshandler: cannot load password callback class: pwcallback; Nested exception is:
Java. Lang. classnotfoundexception: pwcallback
At org. Apache. axis. Message. soapfaultbuilder. createfault (soapfaultbuilder. Java: 222)
At org. Apache. axis. Message. soapfaultbuilder. endelement (soapfaultbuilder. Java: 129)
At org. Apache. axis. encoding. deserializationcontext. endelement (deserializationcontext. Java: 1087)
At com.sun.org. Apache. xerces. Internal. parsers. abstractsaxparser. endelement (abstractsaxparser. Java: 601)
At com.sun.org. Apache. xerces. Internal. impl. xmldocumentfragmentscannerimpl. scanendelement (xmldocumentfragmentscannerimpl. Java: 1774)
At com.sun.org. Apache. xerces. Internal. impl. xmldocumentfragmentscannerimpl $ fragmentcontentdriver. Next (xmldocumentfragmentscannerimpl. Java: 2930)
At com.sun.org. Apache. xerces. Internal. impl. xmldocumentscannerimpl. Next (xmldocumentscannerimpl. Java: 648)
At com.sun.org. Apache. xerces. Internal. impl. xmlnsdocumentscannerimpl. Next (xmlnsdocumentscannerimpl. Java: 140)
At com.sun.org. Apache. xerces. Internal. impl. xmldocumentfragmentscannerimpl. scandocument (xmldocumentfragmentscannerimpl. Java: 510)
At com.sun.org. Apache. xerces. Internal. parsers. xml11configuration. parse (xml11configuration. Java: 807)
At com.sun.org. Apache. xerces. Internal. parsers. xml11configuration. parse (xml11configuration. Java: 737)
At com.sun.org. Apache. xerces. Internal. parsers. xmlparser. parse (xmlparser. Java: 107)
At com.sun.org. Apache. xerces. Internal. parsers. abstractsaxparser. parse (abstractsaxparser. Java: 1205)
At com.sun.org. Apache. xerces. Internal. JAXP. saxparserimpl $ jaxpsaxparser. parse (saxparserimpl. Java: 522)
At javax. xml. parsers. saxparser. parse (saxparser. Java: 395)
At org. Apache. axis. encoding. deserializationcontext. parse (deserializationcontext. Java: 227)
At org. Apache. axis. soappart. getassoapenvelope (soappart. Java: 696)
At org. Apache. axis. Message. getsoapenvelope (message. Java: 435)
At org. Apache. axis. Handlers. Soap. mustunderstandchecker. Invoke (mustunderstandchecker. Java: 62)
At org. Apache. axis. Client. axisclient. Invoke (axisclient. Java: 206)
At org. Apache. axis. Client. Call. invokeengine (call. Java: 2784)
At org. Apache. axis. Client. Call. Invoke (call. Java: 2767)
At org. Apache. axis. Client. Call. Invoke (call. Java: 2443)
At org. Apache. axis. Client. Call. Invoke (call. Java: 2366)
At org. Apache. axis. Client. Call. Invoke (call. Java: 1812)
At com. Unicom. VAC. bossagent. Soap. syncnotifyspsoapbindingstub. orderrelationupdateno133 (syncpolicyspsoapbindingstub. Java: 160)
At com. Unicom. VAC. bossagent. Soap. webserviceclient. setrequest (webserviceclient. Java: 41)
At com. Unicom. VAC. bossagent. Soap. webserviceclient. Main (webserviceclient. Java: 59)

Next we will write the client verification code.

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.