help adding custom header with xfire only the client part - SAML

View: New views
2 Messages — Rating Filter:   Alert me  

help adding custom header with xfire only the client part - SAML

by ivi_333 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hello,

I am developing a client webservice with xfire but i have problems when i send the message.

I only need the client.

My code is the following:

1) Obtaing the client instance:

        Client client = Client.getInstance(updateService);
        client.addOutHandler(new OutHeaderHandler());

2) The class OutHeaderHandler:

public class OutHeaderHandler extends AbstractHandler {
       
        public void invoke(MessageContext ctx) throws Exception {
               
                Element headerE = ctx.getOutMessage().getOrCreateHeader();
               
                SAMLDataHCC samlData = SAMLUtilsHCC.generateSAML2();

                headerE.addContent(samlData.toString());

        }
}

Invoke the client and the server always response. The header not contain a valid header saml.

My message it would be something like:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <soapenv:Header>
    <saml:Assertion ID="_0bd2b65e330953070f41df477f6eb92f" IssueInstant="2009-08-12T09:05:18.421Z" Version="2.0" xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion">
       <.............>
       <.............>
     </saml:Asserton>
   </soapenv:Header>
   <soapenv:Body>
        <..........>
    </soapenv:Body>
</soapenv:Envelope>

No problems with the saml assertion, but i don't know how i create the structure <soapenv:Header>

Any idea or Any example how I create a custom header with xfire ?

Thanks in advance.

Regards

Re: help adding custom header with xfire only the client part - SAML

by ivi_333 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I solved the problem using SAX:

        public void invoke(MessageContext ctx) throws Exception {
       
        SAMLDataHCC samlData = SAMLUtilsHCC.generateSAML2();
        ByteArrayInputStream bais = new ByteArrayInputStream(samlData.getTicket().getEncryptedData().getEncryptedData().getBytes());
        Document doc = new SAXBuilder().build(bais);
        Element saml = doc.detachRootElement();
        Element element = ctx.getOutMessage().getOrCreateHeader();        
        element.addContent(saml);        
        }

Now, The addContent method is a Element type (jdom), before i was using addContent with String (no generate the correct structure, i don't know), but using SAX y JDOM its my solution.


ivi_333 wrote:
Hello,

I am developing a client webservice with xfire but i have problems when i send the message.

I only need the client.

My code is the following:

1) Obtaing the client instance:

        Client client = Client.getInstance(updateService);
        client.addOutHandler(new OutHeaderHandler());

2) The class OutHeaderHandler:

public class OutHeaderHandler extends AbstractHandler {
       
        public void invoke(MessageContext ctx) throws Exception {
               
                Element headerE = ctx.getOutMessage().getOrCreateHeader();
               
                SAMLDataHCC samlData = SAMLUtilsHCC.generateSAML2();

                headerE.addContent(samlData.toString());

        }
}

Invoke the client and the server always response. The header not contain a valid header saml.

My message it would be something like:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <soapenv:Header>
    <saml:Assertion ID="_0bd2b65e330953070f41df477f6eb92f" IssueInstant="2009-08-12T09:05:18.421Z" Version="2.0" xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion">
       <.............>
       <.............>
     </saml:Asserton>
   </soapenv:Header>
   <soapenv:Body>
        <..........>
    </soapenv:Body>
</soapenv:Envelope>

No problems with the saml assertion, but i don't know how i create the structure <soapenv:Header>

Any idea or Any example how I create a custom header with xfire ?

Thanks in advance.

Regards