Hi everyone,

I'm using the service given in sample03 of the Apache Rampart distro to
get the UserNameToken information at the service level. The service is
given below:

public class EchoService {

    MessageContext msgCtx;

    public void setOperationContext(OperationContext opContext)  throws
AxisFault {
        this.msgCtx =
opContext.getMessageContext(WSDLConstants.MESSAGE_LABEL_IN_VALUE);
    }

    public String echo(String arg) {
        Vector results = null;
        if ((results = (Vector) msgCtx
                .getProperty(WSHandlerConstants.RECV_RESULTS)) == null)
{
            System.out.println("No security results!!");
            throw new RuntimeException("No security results!!");
        } else {
            System.out.println("Number of results: " + results.size());
            for (int i = 0; i < results.size(); i++) {
                WSHandlerResult rResult = (WSHandlerResult)
results.get(i);
                Vector wsSecEngineResults = rResult.getResults();

                for (int j = 0; j < wsSecEngineResults.size(); j++) {
                    WSSecurityEngineResult wser =
(WSSecurityEngineResult) wsSecEngineResults.get(j);
                    if (wser.getAction() == WSConstants.UT
                            && wser.getPrincipal() != null) {
                        
                        //Extract the principal
                        WSUsernameTokenPrincipal principal =
(WSUsernameTokenPrincipal)wser.getPrincipal();
                        
                        //Get user/pass
                        String user = principal.getName();
                        String passwd = principal.getPassword();
                        
                        //Authenticate
                        if("sanjay".equals(user) &&
"wspwd".equals(passwd)) {
                            //Authentication successful
                                System.out.println("User was: " + user);
                            return arg;
                        } else {
                            throw new RuntimeException("Authentication
Faliure!!");
                        }
                        
                    }
                }
            }

            return arg;
        }

    }
}//end of EchoService



And my client code is:


public class Client {
        
        private static EndpointReference targetEPR = 
        new EndpointReference(
            "http://localhost:8080/axis2/services/EchoService";);
        
        private static String confPath = "C:\\rampart\\echo";

public static void main(String[] args) throws Exception {
        
         ConfigurationContext ctx = 
              ConfigurationContextFactory.
                    createConfigurationContextFromFileSystem(confPath,
confPath + "/conf/axis2.xml");
             
        ServiceClient client = new ServiceClient(ctx,null);
        Options options = new Options();
        options.setAction("urn:echo");
        options.setTo(targetEPR);
        client.setOptions(options);
        
        OMElement response = client.sendReceive(getPayload("Hello
world"));
        System.out.println(response);
        
    }
    
    private static OMElement getPayload(String value) {
        OMFactory factory = OMAbstractFactory.getOMFactory();
        OMNamespace ns =
factory.createOMNamespace("http://extract.rampart.apache.org","ns1";);
        OMElement elem = factory.createOMElement("echo", ns);
        OMElement childElem = factory.createOMElement("param0", null);
        childElem.setText(value);
        elem.addChild(childElem);
        
        return elem;
    }
}//end of Client


However, when I run the client (which is also from the sample03), I get
the following exceptions:

Exception in thread "main" org.apache.axis2.AxisFault: Exception
occurred while trying to invoke service method echo
        at
org.apache.axis2.util.Utils.getInboundFaultFromMessageContext(Utils.java
:486)
        at
org.apache.axis2.description.OutInAxisOperationClient.handleResponse(Out
InAxisOperation.java:343)
        at
org.apache.axis2.description.OutInAxisOperationClient.send(OutInAxisOper
ation.java:389)
        at
org.apache.axis2.description.OutInAxisOperationClient.executeImpl(OutInA
xisOperation.java:211)
        at
org.apache.axis2.client.OperationClient.execute(OperationClient.java:163
)
        at
org.apache.axis2.client.ServiceClient.sendReceive(ServiceClient.java:528
)
        at
org.apache.axis2.client.ServiceClient.sendReceive(ServiceClient.java:508
)
        at org.apache.rampart.extract.Client.main(Client.java:33)


Is there a reason for these exceptions? I can't really figure out what's
going wrong because the exceptions doesn't tell me much. In essence,
it's basically a simple EchoService but with the addition of security
processing code. Any ideas on how I should proceed? Cheers.


Regards
--------------
Sanjay Vivek
Web Analyst
Middleware Team
ISS
University of Newcastle Upon Tyne

Reply via email to