MessageContext.getCurrentContext() is null

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

MessageContext.getCurrentContext() is null

plork123


Hello all

I have a web service with some methods - when i publish it not all methods
will be exposed, but those that are exposed will call the unexposed methods

One unexposed method is addSOAPHeader, which gets called when a user is
validated.

When I call the addSOAPHeader method i need to call the
handleRequest/Response method with the MessageContext.

I'm doing it like this but doesn't work - the MesaageContext is null

MessageContext context = MessageContext.getCurrentContext();

handleResponse(context);

Am i missing something in my addSOAPHeader method?

Any help greatly appreciated






public static String addSOAPHeader(String token) throws Exception
{
  Service service = new Service();

  Call call = (Call)service.createCall();

  SOAPHeaderElement tokenHeader = new SOAPHeaderElement("","TokenHeader");

  tokenHeader.setObjectValue(token);

  call.addHeader(tokenHeader);

  MessageContext context = MessageContext.getCurrentContext();

  SOAPHandler.handleRequest(context);

  return token;
}



SOAPHandler class

public void invoke(MessageContext msgContext) throws AxisFault
    {
     handleResponse(msgContext);
        super.invoke(msgContext);
    }


public static boolean handleResponse(MessageContext msgContext)
    {
        try
        {
            Message message = msgContext.getResponseMessage();
            SOAPEnvelope responseEnvelope = message.getSOAPEnvelope();
            SOAPHeaderElement headerElement =
responseEnvelope.getHeaderByName("","TokenHeader");

            if (headerElement != null)
            {
                String headerElementValue =
(String)headerElement.getValue();

                // make sure the headerElementValue is valid
                validateTokenValue(headerElementValue);

            }
            else
            {
                // something's gone wrong

            }
        }
        catch(Exception e)
        {
            System.out.println(e);
        }

        return true;
    }

    public static boolean handleRequest(MessageContext msgContext)
    {
           try
        {
            Message message = msgContext.getRequestMessage();
            SOAPEnvelope requestEnvelope = message.getSOAPEnvelope();
            SOAPHeaderElement headerElement =
requestEnvelope.getHeaderByName("","TokenHeader");

            if (headerElement != null)
            {
                String headerElementValue =
(String)headerElement.getValue();

                // make sure the headerElementValue is valid
                validateTokenValue(headerElementValue);
            }
            else
            {
                // something's gone wrong

            }
        }
        catch(Exception e)
        {
            System.out.println(e);
        }

        return true;
    }

_________________________________________________________________
Want to block unwanted pop-ups? Download the free MSN Toolbar now!  
http://toolbar.msn.co.uk/