Home » rampart-dist-1.4-src » org.apache.rampart.tomcat » sample » [javadoc | source]

    1   /*
    2    * Copyright 2004,2005 The Apache Software Foundation.
    3    *
    4    * Licensed under the Apache License, Version 2.0 (the "License");
    5    * you may not use this file except in compliance with the License.
    6    * You may obtain a copy of the License at
    7    *
    8    *      http://www.apache.org/licenses/LICENSE-2.0
    9    *
   10    * Unless required by applicable law or agreed to in writing, software
   11    * distributed under the License is distributed on an "AS IS" BASIS,
   12    * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   13    * See the License for the specific language governing permissions and
   14    * limitations under the License.
   15    */
   16   
   17   package org.apache.rampart.tomcat.sample;
   18   
   19   import java.util.Iterator;
   20   import java.util.List;
   21   
   22   import org.apache.axiom.om.OMAbstractFactory;
   23   import org.apache.axiom.om.OMElement;
   24   import org.apache.axiom.om.OMFactory;
   25   import org.apache.axiom.om.OMNamespace;
   26   import org.apache.axiom.om.impl.builder.StAXOMBuilder;
   27   import org.apache.axis2.addressing.EndpointReference;
   28   import org.apache.axis2.client.Options;
   29   import org.apache.axis2.client.ServiceClient;
   30   import org.apache.axis2.context.ConfigurationContext;
   31   import org.apache.axis2.context.ConfigurationContextFactory;
   32   import org.apache.neethi.Assertion;
   33   import org.apache.neethi.Policy;
   34   import org.apache.neethi.PolicyEngine;
   35   import org.apache.rampart.RampartMessageData;
   36   
   37   import javax.xml.namespace.QName;
   38   
   39   public class Client {
   40   
   41       public static void main(String[] args) throws Exception {
   42           
   43           if(args.length != 3) {
   44               System.out.println("Usage: $java Client endpoint_address client_repo_path policy_xml_path");
   45           }
   46           
   47          ConfigurationContext ctx = ConfigurationContextFactory.createConfigurationContextFromFileSystem(args[1], null);
   48           
   49           ServiceClient client = new ServiceClient(ctx, null);
   50           Options options = new Options();
   51           options.setAction("urn:echo");
   52           options.setTo(new EndpointReference(args[0]));
   53           options.setProperty(RampartMessageData.KEY_RAMPART_POLICY, loadPolicy(args[2]));
   54           client.setOptions(options);
   55           
   56           client.engageModule("addressing");
   57           client.engageModule("rampart");	
   58           OMElement response = client.sendReceive(getPayload("Hello world"));
   59           System.out.println(response);
   60           
   61       }
   62   
   63       private static Policy loadPolicy(String xmlPath) throws Exception {
   64           StAXOMBuilder builder = new StAXOMBuilder(xmlPath);
   65           OMElement elem = builder.getDocumentElement();
   66           return PolicyEngine.getPolicy(builder.getDocumentElement());
   67       }
   68       
   69       private static OMElement getPayload(String value) {
   70           OMFactory factory = OMAbstractFactory.getOMFactory();
   71           OMNamespace ns = factory.createOMNamespace("http://sample.tomcat.rampart.apache.org","ns1");
   72           OMElement elem = factory.createOMElement("echo", ns);
   73           OMElement childElem = factory.createOMElement("param0", null);
   74           childElem.setText(value);
   75           elem.addChild(childElem);
   76           return elem;
   77       }
   78       
   79   }

Home » rampart-dist-1.4-src » org.apache.rampart.tomcat » sample » [javadoc | source]