here is a dirt simple ServiceClient that works with rampart engaged
/*
 * Copyright 2004,2005 The Apache Software Foundation.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.apache.rampart.samples.policy.sample04;

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.Constants;
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 Client {

    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:echo");
        options.setTo(new EndpointReference(args[0]));
        options.setProperty(RampartMessageData.KEY_RAMPART_POLICY,  
loadPolicy(args[2]));
        client.setOptions(options);
        
        client.engageModule("addressing");
        client.engageModule("rampart");

        OMElement response = client.sendReceive(getPayload("Hello world1"));
        System.out.println("Response 1 : " + response);
        response = client.sendReceive(getPayload("Hello world2"));
        System.out.println("Response 2 : " + response);
        response = client.sendReceive(getPayload("Hello world3"));
        System.out.println("Response 3 : " + response);

        System.out.println("Sending cancel request");
        options.setProperty(RampartMessageData.CANCEL_REQUEST, 
Constants.VALUE_TRUE);
        response = client.sendReceive(getPayload("Hello world3"));
        System.out.println("Cancel response: " + 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://sample04.policy.samples.rampart.apache.org/xsd","ns1";);
        OMElement elem = factory.createOMElement("echo", ns);
        OMElement childElem = factory.createOMElement("param0", null);
        childElem.setText(value);
        elem.addChild(childElem);
        
        return elem;
    }
    
}

if you think your rampart mar is META-INF only (generally 2k size or less)
best to download rampart from sourceforge
http://axis.apache.org/axis2/java/rampart/

and build the rampart.mar for policy,trust and rampart-VERSION

you're going to need to place
rampart-policy-<VERSION>.mar
rampart-trust-<VERSION>.mar
rampart-<VERSION>.mar 
in WEB-INF\modules folder

generally 1.5.1 was the last blessed Rampart version..i havent tried 1.6

Martin Gainty 
______________________________________________ 
Jogi és Bizalmassági kinyilatkoztatás/Verzicht und 
Vertraulichkeitanmerkung/Note de déni et de confidentialité
 Ez az
üzenet bizalmas.  Ha nem ön az akinek szánva volt, akkor kérjük, hogy
jelentse azt nekünk vissza. Semmiféle továbbítása vagy másolatának
készítése nem megengedett.  Ez az üzenet csak ismeret cserét szolgál és
semmiféle jogi alkalmazhatósága sincs.  Mivel az electronikus üzenetek
könnyen megváltoztathatóak, ezért minket semmi felelöség nem terhelhet
ezen üzenet tartalma miatt.

Diese Nachricht ist vertraulich. Sollten Sie nicht der vorgesehene Empfaenger 
sein, so bitten wir hoeflich um eine Mitteilung. Jede unbefugte Weiterleitung 
oder Fertigung einer Kopie ist unzulaessig. Diese Nachricht dient lediglich dem 
Austausch von Informationen und entfaltet keine rechtliche Bindungswirkung. 
Aufgrund der leichten Manipulierbarkeit von E-Mails koennen wir keine Haftung 
fuer den Inhalt uebernehmen.
Ce message est confidentiel et peut être privilégié. Si vous n'êtes pas le 
destinataire prévu, nous te demandons avec bonté que pour satisfaire informez 
l'expéditeur. N'importe quelle diffusion non autorisée ou la copie de ceci est 
interdite. Ce message sert à l'information seulement et n'aura pas n'importe 
quel effet légalement obligatoire. Étant donné que les email peuvent facilement 
être sujets à la manipulation, nous ne pouvons accepter aucune responsabilité 
pour le contenu fourni.


Date: Thu, 4 Aug 2011 10:49:33 -0400
Subject: Re: Having trouble interfacing with WCF
From: not...@gmail.com
To: java-dev@axis.apache.org



On Thu, Aug 4, 2011 at 9:57 AM, Jay Sullivan <not...@gmail.com> wrote:



On Wed, Aug 3, 2011 at 9:22 PM, Hasini Gunasinghe <hasi7...@gmail.com> wrote:


Hi Jay,

Have you engaged Rampart, and provided the rampart configuration properly in 
the Axis2 client side?

You can refer to rampart samples[1] to verify this.

Also, the article[2] on message level security with Rampart may help.

[1] 
http://svn.apache.org/repos/asf/axis/axis2/java/rampart/trunk/modules/rampart-samples/policy/



[2] http://wso2.org/library/3415

Thanks,

Hasini.


I read somewhere that it's not necessary to engage rampart; that it would 
engage itself when needed.  Is this wrong?  

I'm using axis-1.5.5, and rampart-1.6.0.  When I try to explicitly engage 
rampart, I get this error:


    
    Exception in thread "main" org.apache.axis2.AxisFault: Unable to engage 
module : rampart

And yes I have a repository configured properly, as I can load the 
"addressing-1.5.5" module without trouble, and they're in the same directory.  
Am I running into a version conflict?



-- 
Jay Sullivan


I've tried using axis-1.6.0, and rampart-1.6.0.  Same issue.  

Here's what I did.  I generated a web service client stub by running:

    $AXIS2_HOME/bin/wsdl2java.sh -uw -o . -uri http://path/to/my/service.wsdl

I then created this client program which relies on the stub :

package org.tempuri;

import org.apache.axis2.context.ConfigurationContext;
import org.apache.axis2.context.ConfigurationContextFactory;
import org.apache.axis2.client.ServiceClient;
import org.apache.axis2.client.Options;
import org.apache.axis2.AxisFault;

import org.apache.log4j.Logger;
import org.apache.log4j.Level;
import org.apache.axis2.transport.http.HttpTransportProperties;
import org.apache.axis2.transport.http.HttpTransportProperties.Authenticator;
public class MagicEightBallServiceCGClient

{
    public static void main(String[] args) throws Exception
    {
        Logger.getRootLogger().setLevel(Level.OFF);

        /* Get repository context */
        ConfigurationContext ctx = 
ConfigurationContextFactory.createConfigurationContextFromFileSystem(System.getenv("AXIS2_HOME")
 + "/repository",null);


        /* Get Service stub */
        MagicEightBallServiceStub stub = new MagicEightBallServiceStub(ctx);

        /* Engage addressing and rampart modules */
        ServiceClient sc = stub._getServiceClient();

        sc.engageModule("addressing"); 
        sc.engageModule("rampart");

        /* Set options */
        Options options = sc.getOptions();
        options.setUserName("USERNAME");

        options.setPassword("PASSWORD");

        /* Consume service */
        System.out.println(stub.getAdvice());
    }
}

Notice how my service is called "MagicEightBallService", and has a single void 
service method called "getAdvice()", (it returns a magic eight ball fortune).  


Located within $AXIS2_HOME/repository/modules/ are the files:

modules.list  addressing-1.6.0.mar  ping-1.6.0.mar  rampart-1.6.0.mar  
soapmonitor-1.6.0.mar

mex-1.6.0.mar  mtompolicy-1.6.0.mar  rahas-1.6.0.mar  scripting-1.6.0.mar

I then run the program with :


java -cp build/lib/MagicEightBallService-test-client.jar:$AXIS2_HOME/lib/* 
org.tempuri.MagicEightBallServiceCGClient

And the result is this error:


Exception in thread "main" org.apache.axis2.AxisFault: Unable to engage module 
: rampart
        at 
org.apache.axis2.client.ServiceClient.engageModule(ServiceClient.java:363)
        at 
org.tempuri.MagicEightBallServiceCGClient.main(MagicEightBallServiceCGClient.java:26)


 Note that I don't get an error if I don't try to engage rampart, i.e., a 
non-secure web client.  What am I doing wrong?

-- 
Jay Sullivan
                                          

Reply via email to