axis-java-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Lasantha Bandara <lasanthasridin...@gmail.com>
Subject Re: how to call web service with rampart?
Date Sat, 26 Feb 2011 03:49:47 GMT
One simple solution is to add required java libraries into your project.
Those are in \axis2-1.5.1-bin\axis2-1.5.1\lib folder. It will solve many
problems.

On Fri, Feb 25, 2011 at 7:31 PM, andrew vn <andrewvn2010@gmail.com> wrote:

> Dear all,
>
> I'm new to axis2 and web service. I've already written a *Converter*service genertated
with tools:
>
>    - eclipse-helio
>    - jdk1.6.0_23
>    - axis2-1.5
>    - rapart-1.5.1
>
> Then, i'm writing a client to call this service, and now i want to use *
> rampart* module to encrypt and sign the message.
>
> *Here is my service Converter code:*
>
> *Converter.java*
> package wtp;
> public class Converter
> {
>   public float celsiusToFarenheit ( float celsius )
>   {
>     return (celsius * 9 / 5) + 32;
>   }
>
>   public float farenheitToCelsius ( float farenheit )
>   {
>     return (farenheit - 32) * 5 / 9;
>   }
> }
> *PWCBHandler.java*
> package wtp;
>
> import org.apache.ws.security.WSPasswordCallback;
> import javax.security.auth.callback.Callback;
> import javax.security.auth.callback.CallbackHandler;
> import javax.security.auth.callback.UnsupportedCallbackException;
> import java.io.IOException;
>
> public class PWCBHandler implements CallbackHandler {
>
>      @SuppressWarnings("deprecation")
>     public void handle(Callback[] callbacks) throws IOException,
>      UnsupportedCallbackException {
>
>  for (int i = 0; i < callbacks.length; i++) {
>
>      //When the server side need to authenticate the user
>      WSPasswordCallback pwcb = (WSPasswordCallback)callbacks[i];
>      if (pwcb.getUsage() == WSPasswordCallback.USERNAME_TOKEN_UNKNOWN) {
>          if(pwcb.getIdentifer().equals("apache") &&
> pwcb.getPassword().equals("password")) {
>              //If authentication successful, simply return
>              return;
>          } else {
>              throw new UnsupportedCallbackException(callbacks[i], "check
> failed");
>          }
>      }
>      //When the client requests for the password to be added in to the
>      //UT element
>      pwcb.setPassword("password");
>  }
> }
> }
> *services.xml*
> <service name="Converter" >
>     <Description>
>         Test WS-Security
>     </Description>
>     <module ref="rampart"/>
>     <parameter name="InflowSecurity">
>       <action>
>         <items>UsernameToken</items>
>         <user>apache</user>
>         <passwordCallbackClass>wtp.PWCBHandler</passwordCallbackClass>
>         <passwordType>PasswordText</passwordType>
>       </action>
>     </parameter>
>     <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">wtp.Converter</parameter>
> </service>
>
> *Here is my client code:*
> *
> ConverterClient.java*
>
> package wtp;
>
> import java.rmi.RemoteException;
>
> import org.apache.axis2.AxisFault;
> import org.apache.axis2.Constants;
> import org.apache.axis2.context.ConfigurationContext;
> import org.apache.axis2.context.ConfigurationContextFactory;
>
> import wtp.ConverterStub.CelsiusToFarenheit;
> import wtp.ConverterStub.CelsiusToFarenheitResponse;
>
> public class ConverterClient {
>
>         public static void main(String[] args) {
>                 try {
>                         float celsiusValue = 100;
>                        //ConverterStub stub = new ConverterStub("
> http://localhost:1234/ConverterProj/services/Converter");
>                         String axis2repository =
> "/home/hp/Downloads/metadata/.metadata/ConverterClient/WebContent/WEB-INF";
>                         //String axis2xml =
> "/home/hp/Downloads/metadata/.metadata/ConverterClient/WebContent/WEB-INF/conf/axis2.xml";
>
>                         ConfigurationContext configContext =
> ConfigurationContextFactory.createConfigurationContextFromFileSystem(axis2repository,null);
>                         ConverterStub stub = new
> ConverterStub(configContext, "
> http://localhost:8081/ConverterProj/services/Converter");
>                         //String targetEpr = "
> http://localhost:8081/ConverterProj/services/Converter";
>                         stub._getServiceClient().engageModule("rampart");
>
>
> stub._getServiceClient().getOptions().setUserName("apache");
>
> stub._getServiceClient().getOptions().setPassword("password");
>
> stub._getServiceClient().getOptions().setTransportInProtocol(Constants.TRANSPORT_HTTP);
>                         CelsiusToFarenheit c2f = new CelsiusToFarenheit();
>                         c2f.setCelsius(celsiusValue);
>                         CelsiusToFarenheitResponse res =
> stub.celsiusToFarenheit(c2f);
>                         System.out.println("Celsius : "+celsiusValue+" =
> "+"Farenheit : "+res.get_return());
>                 } catch (AxisFault e) {
>                         e.printStackTrace();
>                 } catch (RemoteException e) {
>                         e.printStackTrace();
>                 }
>
>         }
> }
>
>
> When i run client, it has the following errors:
>
> [ERROR] org/jaxen/JaxenException
> java.lang.NoClassDefFoundError: org/jaxen/JaxenException
>     at org.apache.rampart.RampartEngine.process(RampartEngine.java:75)
>     at
> org.apache.rampart.handler.RampartReceiver.invoke(RampartReceiver.java:92)
>     at org.apache.axis2.engine.Phase.invoke(Phase.java:318)
>     at org.apache.axis2.engine.AxisEngine.invoke(AxisEngine.java:254)
>     at org.apache.axis2.engine.AxisEngine.receive(AxisEngine.java:160)
>     at
> org.apache.axis2.transport.http.HTTPTransportUtils.processHTTPPostRequest(HTTPTransportUtils.java:173)
>     at
> org.apache.axis2.transport.http.AxisServlet.doPost(AxisServlet.java:144)
>     at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
>     at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
>     at
> org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
>     at
> org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
>     at
> org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
>     at
> org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
>     at
> org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
>     at
> org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
>     at
> org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
>     at
> org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
>     at
> org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:859)
>     at
> org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
>     at
> org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
>     at java.lang.Thread.run(Thread.java:662)
> Caused by: java.lang.ClassNotFoundException: org.jaxen.JaxenException
>     at
> org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1680)
>     at
> org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1526)
>     ... 21 more
>
> Please show me the way to resove this problems.
>
> Thanks
>



-- 
*
Lasantha Bandara,
Computer Science and Engineering,
University of Moratuwa,
Sri Lanka.
*
blog: http://lasanthasri.blogspot.com/
gtalk: lasanthasridinesh
skype: lasanthasridinesh

Mime
View raw message