• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Axis2 - Handlers for SOAP headers

 
Ranch Hand
Posts: 279
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a service created using contract first approach in Axis2.

Now the client, needs to pass header information to this service with the user credentials. Only if the user is valid the service call should succeed. Otherwise a fault should be raised.
To add information to header (in the request), I have created the following handler-chain.xml


and the following handler on the client side



but this header is not getting called. Seems it is not able to locate the handler-chain.xml

Can someone please let me know how to correct this.

Thank you

 
Ranch Hand
Posts: 263
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Anjali,

You are not using axis2 handler. To qualify as asix2 handler either you have to extend and AbstactHandler or implement handler. And then you need to register it in axis2.config(inside phase) to make sure it's getting picked.
 
Anjali S Sharma
Ranch Hand
Posts: 279
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

shivendra tripathi wrote:Anjali,

You are not using axis2 handler. To qualify as asix2 handler either you have to extend and AbstactHandler or implement handler. And then you need to register it in axis2.config(inside phase) to make sure it's getting picked.



Thank you.
Where can I find the axis2.config file? Are you referring to Axis2.xml

If you are referring to Axis2.xml, then under which phase should I put my handler.


 
shivendra tripathi
Ranch Hand
Posts: 263
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have implemented a simple handler for adding soap headers. Find below the changes needed.

This is my handler.


Changes done in axis2.xml


Following is my soap envelope



 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi shivendra tripathi, i am getting messageContext value as null, please provide help if you have any solution
 
Saloon Keeper
Posts: 15510
363
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to CodeRanch, Faizan!

Please show us the handler you're having problems with, and your Axis2 configuration.
 
Stephan van Hulst
Saloon Keeper
Posts: 15510
363
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
By the way, if this is a new project and you're not maintaining an old Axis2 application, you might prefer using JAX-WS, a specification that's part of Java EE. In my professional opinion it's much easier to use than Axis2.
 
faizan khan
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Stephan van Hulst,
Thanks for replying, actually this is not a new project and we wanted to add a handler. Below i have attached all details:-

Handler class:-

package org.apache.axis2.handlers.creditsoap;

import java.util.Iterator;

import javax.xml.soap.SOAPElement;
import javax.xml.soap.SOAPMessage;

import org.apache.axiom.soap.SOAPEnvelope;
import org.apache.axis2.AxisFault;
import org.apache.axis2.context.MessageContext;
import org.apache.axis2.engine.Handler;
import org.apache.axis2.handlers.AbstractHandler;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.axiom.soap.SOAPEnvelope;
import org.apache.commons.lang.StringUtils;

public class MyHandler extends AbstractHandler implements Handler{
private static final Log log1 = LogFactory.getLog(MyHandler.class);
@Override
public InvocationResponse invoke(MessageContext arg0) throws AxisFault {
log.info(arg0.getClass());
log.info(arg0.getLogIDString());
log.info(arg0.getEnvelope().toString());

log.info(arg0.getCurrentMessageContext());
log.info(arg0.getCurrentMessageContext().getAxisService());

return InvocationResponse.CONTINUE;
}

}


HandlerModule class:-

package org.apache.axis2.handlers.creditsoap;

import org.apache.axis2.AxisFault;
import org.apache.axis2.context.ConfigurationContext;
import org.apache.axis2.description.AxisDescription;
import org.apache.axis2.description.AxisModule;
import org.apache.axis2.modules.Module;
import org.apache.neethi.Assertion;
import org.apache.neethi.Policy;

public class MyHandlerModule implements Module{

@Override
public void applyPolicy(Policy arg0, AxisDescription arg1) throws AxisFault {
// TODO Auto-generated method stub

}

@Override
public boolean canSupportAssertion(Assertion arg0) {
// TODO Auto-generated method stub
return true;
}

@Override
public void engageNotify(AxisDescription arg0) throws AxisFault {
// TODO Auto-generated method stub

}

@Override
public void init(ConfigurationContext arg0, AxisModule arg1) throws AxisFault {
// TODO Auto-generated method stub

}

@Override
public void shutdown(ConfigurationContext arg0) throws AxisFault {
// TODO Auto-generated method stub

}

}

module.xml:-
<!--
 ~ Licensed to the Apache Software Foundation (ASF) under one
 ~ or more contributor license agreements. See the NOTICE file
 ~ distributed with this work for additional information
 ~ regarding copyright ownership. The ASF licenses this file
 ~ to you 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.
 -->

<module name="creditsoap" class="org.apache.axis2.handlers.creditsoap.MyHandlerModule">
   <InFlow>
       <handler name="InFlowCreditSoapHandler" class="org.apache.axis2.handlers.creditsoap.MyHandler">
           <order phase="creditSoapPhase"/>
       </handler>
   </InFlow>

   <OutFlow>
       <handler name="OutFlowCreditSoapHandler" class="org.apache.axis2.handlers.creditsoap.MyHandler">
           <order phase="creditSoapPhase"/>
       </handler>
   </OutFlow>

   <OutFaultFlow>
       <handler name="FaultOutFlowCreditSoapHandler" class="org.apache.axis2.handlers.creditsoap.MyHandler">
           <order phase="creditSoapPhase"/>
       </handler>
   </OutFaultFlow>

   <InFaultFlow>
       <handler name="FaultInFlowCreditSoapHandler" class="org.apache.axis2.handlers.creditsoap.MyHandler">
           <order phase="creditSoapPhase"/>
       </handler>
   </InFaultFlow>
</module>

axis2.xml:-
<phaseOrder type="InFlow">
       <!--  System predefined phases       -->
       <phase name="Transport">
           <handler name="RequestURIBasedDispatcher"
                    class="org.apache.axis2.dispatchers.RequestURIBasedDispatcher">
               <order phase="Transport"/>
           </handler>
           <handler name="SOAPActionBasedDispatcher"
                    class="org.apache.axis2.dispatchers.SOAPActionBasedDispatcher">
               <order phase="Transport"/>
           </handler>
       </phase>
       <phase name="Addressing">
           <handler name="AddressingBasedDispatcher"
                    class="org.apache.axis2.dispatchers.AddressingBasedDispatcher">
               <order phase="Addressing"/>
           </handler>
       </phase>
       <phase name="Security"/>
       <phase name="PreDispatch"/>
       <phase name="Dispatch" class="org.apache.axis2.engine.DispatchPhase">
           <handler name="RequestURIBasedDispatcher"
                    class="org.apache.axis2.dispatchers.RequestURIBasedDispatcher"/>
           <handler name="SOAPActionBasedDispatcher"
                    class="org.apache.axis2.dispatchers.SOAPActionBasedDispatcher"/>
           <handler name="RequestURIOperationDispatcher"
                    class="org.apache.axis2.dispatchers.RequestURIOperationDispatcher"/>
           <handler name="SOAPMessageBodyBasedDispatcher"
                    class="org.apache.axis2.dispatchers.SOAPMessageBodyBasedDispatcher"/>
           <handler name="HTTPLocationBasedDispatcher"
                    class="org.apache.axis2.dispatchers.HTTPLocationBasedDispatcher"/>
           <handler name="GenericProviderDispatcher"
                    class="org.apache.axis2.jaxws.dispatchers.GenericProviderDispatcher"/>
           <handler name="MustUnderstandValidationDispatcher"
                    class="org.apache.axis2.jaxws.dispatchers.MustUnderstandValidationDispatcher"/>
       </phase>
       <phase name="RMPhase"/>
       <!--  System predefined phases       -->
       <!--   After Postdispatch phase module author or service author can add any phase he want      -->
       <phase name="creditSoapPhase"/>
        <phase name="OperationInPhase">
           <handler name="MustUnderstandChecker"
                    class="org.apache.axis2.jaxws.dispatchers.MustUnderstandChecker">
 
faizan khan
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Output:-
creditsoap.MyHandler:26 - null
creditsoap.MyHandler:27 - [MessageContext: logID=1322a5dc9e7e05ce88b7cfd80253104399d001e5e79bc6ca]
creditsoap.MyHandler:28 - null
 
reply
    Bookmark Topic Watch Topic
  • New Topic