axis-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Tania Marinova <taniamm2...@yahoo.com>
Subject Exception in thread "main" org.apache.axis2.AxisFault: 1
Date Sun, 14 Apr 2013 14:22:38 GMT
I try to consume an axis 2 web service with rampart security 
 
I'm stuck with thsi qustion for fthree days but know I get thsi exception: 
 
 
Exception in thread "main" org.apache.axis2.AxisFault: 1
at org.apache.axis2.util.Utils.getInboundFaultFromMessageContext(Utils.java:531)OutInAxisOperation.java:375)OutInAxisOperation.java:421)OutInAxisOperation.java:229)OperationClient.java:165)ServiceClient.java:555)ServiceClient.java:531)zltestcl.java:55)
 
---------------------------------------------------------------------------------------------
Here is my PWCBhanler,.java 
 packagetan;importorg.apache.ws.security.WSPasswordCallback;importjavax.security.auth.callback.Callback;importjavax.security.auth.callback.CallbackHandler;importjavax.security.auth.callback.UnsupportedCallbackException;importjava.io.IOException;public
UnsupportedCallbackException {classPWCBHandler implementsCallbackHandler {publicvoidhandle(Callback[]
callbacks) throwsIOException,for(inti = 0; i < callbacks.length; i++) {//When the server
side need to authenticate the userWSPasswordCallback pwcb = (WSPasswordCallback)callbacks[i];
pwcb.setPassword(
} 
}if(pwcb.getIdentifier().equals("bob") ) {"bobPW");}
}
 
 
 
 
here is my service.xml 
 <service name="ztest" >
<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">tan.ztest</parameter>
<wsp:Policy wsu:Id="UTOverTransport"
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:SignedSupportingTokens
xmlns:sp="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy">
<wsp:Policy>
<sp:UsernameToken
sp:IncludeToken="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy/IncludeToken/AlwaysToRecipient"
/>
</wsp:Policy>
</sp:SignedSupportingTokens>
<ramp:RampartConfig xmlns:ramp="http://ws.apache.org/rampart/policy">
<ramp:passwordCallbackClass>tan.PWCBHandler</ramp:passwordCallbackClass>
</ramp:RampartConfig>
</wsp:All>
</wsp:ExactlyOne>
</wsp:Policy>
</service>
 
 
---------------------------------------------------------------------------------------------------------------------------------
Here is my policy.xml 
 <wsp:Policy wsu:Id="UTOverTransport"
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:SignedSupportingTokens
xmlns:sp="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy">
<wsp:Policy>
<sp:UsernameToken
sp:IncludeToken="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy/IncludeToken/AlwaysToRecipient"
/>
</wsp:Policy>
</sp:SignedSupportingTokens>
<ramp:RampartConfig xmlns:ramp="http://ws.apache.org/rampart/policy">
<ramp:user>bob</ramp:user>
<ramp:passwordCallbackClass>tan.PWCBHandler</ramp:passwordCallbackClass>
</ramp:RampartConfig>
</wsp:All>
</wsp:ExactlyOne>
</wsp:Policy>
 
 
(the only difference is th added  <ramp:user > paramete4r   from services.xml
------------------------------------------------------------------------------------------------------------------------
 
and here is  my client.java 
 
package tan;
import org.apache.axiom.om.OMAbstractFactory;
import org.apache.axiom.om.OMElement;
import org.apache.axiom.om.OMFactory;
import org.apache.axiom.om.OMNamespace;
import org.apache.axiom.om.impl.builder.StAXOMBuilder;
import org.apache.axis2.addressing.EndpointReference;
import org.apache.axis2.client.Options;
import org.apache.axis2.client.ServiceClient;
import org.apache.axis2.context.ConfigurationContext;
import org.apache.axis2.context.ConfigurationContextFactory;
import org.apache.neethi.Policy;
import org.apache.neethi.PolicyEngine;
import org.apache.rampart.RampartMessageData;
import javax.xml.namespace.QName;
public class zltestcl {
    public static void main(String[] args) throws Exception {
        
        if(args.length != 3) {
            System.out.println("Usage: $java Client endpoint_address client_repo_path
policy_xml_path");
        }
        
        ConfigurationContext ctx = ConfigurationContextFactory.createConfigurationContextFromFileSystem(args[1],
null);
        
        ServiceClient client = new ServiceClient(ctx, null);
        Options options = new Options();
        options.setAction("urn:testws");
        options.setTo(new EndpointReference(args[0]));
        options.setProperty(RampartMessageData.KEY_RAMPART_POLICY,  loadPolicy(args[2]));
        client.setOptions(options);
        
        
        client.engageModule("rampart");
        
        OMElement response = client.sendReceive(getPayload("Hello world"));
        
        System.out.println(response);
        
    }
    
    private static Policy loadPolicy(String xmlPath) throws Exception {
        StAXOMBuilder builder = new StAXOMBuilder(xmlPath);
        return PolicyEngine.getPolicy(builder.getDocumentElement());
    }
    
    private static OMElement getPayload(String value) {
        OMFactory factory = OMAbstractFactory.getOMFactory();
        OMNamespace ns = factory.createOMNamespace("http://tan%22,%22ns1/");
        OMElement elem = factory.createOMElement("testws", ns);
        OMElement childElem = factory.createOMElement("param0", null);
        childElem.setText(value);
        elem.addChild(childElem);
        
        return elem;
    }
    
}

----------------------------------------------------
!!! note in my prvicy.xml I changd  the <ramp user_ and instead of bob I wrote mary
 
and I got the exception:
No password supplied by the callback handler for user: mari
 
 so it seems thart my client code is reading the policy.xml
 
 
 
 
at org.apache.axis2.description.OutInAxisOperationClient.handleResponse(
at org.apache.axis2.description.OutInAxisOperationClient.send(
at org.apache.axis2.description.OutInAxisOperationClient.executeImpl(
at org.apache.axis2.client.OperationClient.execute(
at org.apache.axis2.client.ServiceClient.sendReceive(
at org.apache.axis2.client.ServiceClient.sendReceive(
at tan.zltestcl.main(
Mime
View raw message