Hello As I'm really new and making my first steps in understanding axis 2 and
rampart I will be so pleased and glad if you look at my problem which I will
try to explain in the following letter.
1. I create a Dynamic web project with name 'testfn' (and of course I don't
forget to change the dynamic web module version to 2.5 and in configuration I
choose Axis 2 web service)
2. I add to my Dynamic web project these two classes :
testfn .java and PWCBHandler.java
here is the code for PWCBHandler.java
public class PWCBHandler implements CallbackHandler{
public void handle(Callback[] callbacks) throws IOException,
UnsupportedCallbackException {
for (int i = 0; i < callbacks.length;i++)
{
WSPasswordCallback pwcb = (WSPasswordCallback)callbacks[i];
if (pwcb.getIdentifier().equals("test") && pwcb.getPassword().equals("pass"))
{
return;
}
else
{
throw new UnsupportedCallbackException(callbacks[i],"Incorrect
login/password");
}
}
}
3. I right click on testfn.java -> New ->Other -> Web Service
to create my web service
4. I don't forget to copy all the jar files from rampart distribution to
testfn/ WebContent/WEB_INF/lib
and all .mar modules into testfn/ WebContent/WEB_INF/modules
5. I change services.xml file so it looks like:
<service name="testfn">
<module ref="rampart"/>
<Description>
Please Type your service description here
</Description>
<messageReceivers>
<messageReceiver mep="http://www.w3.org/2004/08/wsdl/in-only"
class="org.apache.axis2.rpc.receivers.RPCInOnlyMessageReceiver" />
<messageReceiver mep="http://www.w3.org/2004/08/wsdl/in-out"
class="org.apache.axis2.rpc.receivers.RPCMessageReceiver"/>
</messageReceivers>
<parameter name="ServiceClass" locked="false">axis2wstest.testfn</parameter>
<operation name="testws">
<messageReceiver
class="org.apache.axis2.rpc.receivers.RPCMessageReceiver"/>
</operation>
<!-- Server policy for Username Token with plaintext password -->
<wsp:Policy wsu:Id="UsernameToken" xmlns:wsu="http://docs.oasis/-
open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"
xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy">
<wsp:ExactlyOne>
<wsp:All>
<sp:TransportBinding
xmlns:sp="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy">
<wsp:Policy>
<sp:TransportToken>
<wsp:Policy>
<sp:HttpToken RequireClientCertificate="false"/>
</wsp:Policy>
</sp:TransportToken>
<sp:AlgorithmSuite>
<wsp:Policy>
<sp:Basic256/>
</wsp:Policy>
</sp:AlgorithmSuite>
</wsp:Policy>
</sp:TransportBinding>
<sp:SupportingTokens
xmlns:sp="http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200702">
<wsp:Policy>
<sp:UsernameToken
sp:IncludeToken="http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200702/IncludeToken/AlwaysToRecipient%22/>
</wsp:Policy>
</sp:SupportingTokens>
<ramp:RampartConfig xmlns:ramp="http://ws.apache.org/rampart/policy">
<ramp:passwordCallbackClass>axis2wstest.PWCBHandler</ramp:passwordCallbackClass>
</ramp:RampartConfig>
</wsp:All>
</wsp:ExactlyOne>
</wsp:Policy>
</service>
(so I think I have engaged rampart module and added teh security policy)
6. I right click on testfn -> RUN AS _> Run on Server (and my web service is
deployed successfully)
7. Next I should create Web Service Client - so I choose -
File -> New -> Other -> Web Service Client
and in Service Definition I paste the url of the wsdl file of SimpleService
( http://localhost:9091/testf/services/testfn?wsdl)
8. I add testwscl.java class to my web-service client. Here is the code
public class testwscl {
public static void main(String[] args) throws RemoteException,
XMLStreamException {
ConfigurationContext ctx;
ctx =
ConfigurationContextFactory.createConfigurationContextFromFileSystem("C:/Users/gismo2/workspace/testfnclient/WebContent/WEB-INF",
null);
try
{
TestfnStub stub = new TestfnStub(ctx);
Testws cl = new Testws();
cl.setX(5);
ServiceClient client = stub._getServiceClient();
client.engageModule("rampart");
Options o = client.getOptions();
o.setPassword("pass");
o.setUserName("test");
client.addHeader(omSecurityElement);
TestwsResponse resp = stub.testws(cl);
System.out.println("Response" + resp.get_return());
}
catch (Exception ex)
{
ex.printStackTrace();
}
}
10. But when I run testwscl as Java Application it gives me an exception
org.apache.axis2.AxisFault: <faultstring>Missing wsse:Security header in
request</faultstring>
at
org.apache.axis2.util.Utils.getInboundFaultFromMessageContext(Utils.java:536)
at
org.apache.axis2.description.OutInAxisOperationClient.handleResponse(OutInAxisOperation.java:375)
at
org.apache.axis2.description.OutInAxisOperationClient.send(OutInAxisOperation.java:421)
at
org.apache.axis2.description.OutInAxisOperationClient.executeImpl(OutInAxisOperation.java:229)
at org.apache.axis2.client.OperationClient.execute(OperationClient.java:165)
at axis2wstest.TestfnStub.testws(TestfnStub.java:198)
at axis2wstest.testwscl.main(testwscl.java:76)
Thank you in advance