Home » rampart-dist-1.4-src » org.apache.rampart.samples » sample09 » [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.samples.sample09;
   18   
   19   import org.apache.axiom.om.OMAbstractFactory;
   20   import org.apache.axiom.om.OMElement;
   21   import org.apache.axiom.om.OMFactory;
   22   import org.apache.axiom.om.OMNamespace;
   23   import org.apache.axis2.addressing.EndpointReference;
   24   import org.apache.axis2.client.Options;
   25   import org.apache.axis2.client.ServiceClient;
   26   import org.apache.axis2.context.ConfigurationContext;
   27   import org.apache.axis2.context.ConfigurationContextFactory;
   28   
   29   public class Client {
   30   
   31       public static void main(String[] args) throws Exception {
   32           
   33           if(args.length != 2) {
   34               System.out.println("Usage: $java Client endpoint_address client_repo_path");
   35           }
   36           
   37           ConfigurationContext ctx = ConfigurationContextFactory.createConfigurationContextFromFileSystem(args[1], args[1] + "/conf/axis2.xml");
   38           
   39           ServiceClient client = new ServiceClient(ctx, null);
   40           Options options = new Options();
   41           options.setAction("urn:echo");
   42           options.setTo(new EndpointReference(args[0]));
   43           client.setOptions(options);
   44           
   45           OMElement response = client.sendReceive(getPayload("Hello world"));
   46           
   47           System.out.println(response);
   48           
   49       }
   50       
   51       private static OMElement getPayload(String value) {
   52           OMFactory factory = OMAbstractFactory.getOMFactory();
   53           OMNamespace ns = factory.createOMNamespace("http://sample09.samples.rampart.apache.org","ns1");
   54           OMElement elem = factory.createOMElement("echo", ns);
   55           OMElement childElem = factory.createOMElement("param0", null);
   56           childElem.setText(value);
   57           elem.addChild(childElem);
   58           
   59           return elem;
   60       }
   61       
   62   }

Home » rampart-dist-1.4-src » org.apache.rampart.samples » sample09 » [javadoc | source]