You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-user@axis.apache.org by Daniel Herbison <he...@nortel.com> on 2007/05/09 23:26:54 UTC

Creating Axis2 SOAP Header

I'm trying to add the SOAP header, described in comment in code below, to a
RPC call to a service.  First of all I really do not know if the code to
create the header is correct, i think it is in the ball park(?)  But I get a
run time error of:

Exception in thread "main" java.lang.ClassCastException:
org.apache.axiom.om.impl.OMNamespaceImpl
        at
org.apache.axiom.soap.impl.dom.SOAPHeaderBlockImpl.<init>(SOAPHeaderBlockImpl.java:54)
        at
org.apache.axiom.soap.impl.dom.soap12.SOAP12HeaderBlockImpl.<init>(SOAP12HeaderBlockImpl.java:45)
        at rpcAxSys.main(Unknown Source)

the line causing the run time error is marked below, why is this doing this? 
Also, is the header creation correct?

code------------------
RPCServiceClient serviceClient = new RPCServiceClient();
Options options = serviceClient.getOptions();
EndpointReference targetEPR = new
EndpointReference("https://xyz/Authorize/Service.asmx");
options.setTo(targetEPR);

/* header build
 <soap:Header>
  <BasicCredentials xmlns="beta">
   <serviceId>string1</serviceId>    
   <serviceKey>string2</serviceKey>  
  </BasicCredentials>
 </soap:Header>
 */
OMFactory fac = OMAbstractFactory.getOMFactory();
OMNamespace omNs = fac.createOMNamespace("beta", "xmlns"); 

SOAPFactory soapFactory = new SOAP12Factory(); 
SOAPHeaderBlock soapHeaderBlock = new
SOAP12HeaderBlockImpl("Security",omNs,soapFactory); 
soapHeaderBlock.setMustUnderstand(true); 

OMElement basicCredentials = fac.createOMElement("BasicCredentials", omNs); 

OMElement serviceId = fac.createOMElement("serviceId", omNs); 
OMText serviceIdText = fac.createOMText(serviceId, agentID);
serviceId.addChild(serviceIdText); 

OMElement serviceKey = fac.createOMElement("serviceKey", omNs); 
OMText serviceKeyText = fac.createOMText(serviceKey, agentToken);
serviceKey.addChild(serviceKeyText); 

basicCredentials.addChild(serviceId); 
basicCredentials.addChild(serviceKey); 

soapHeaderBlock.addChild(basicCredentials); 

serviceClient.addHeader(soapHeaderBlock); 
// end header build

QName opSetClaim = new QName("beta", "GetClaim" );

Object[] opSetParams = new Object[] { agentID, agentToken, requestor };
Class[] returnTypes = new Class[] { Object.class };

Object[] response = serviceClient.invokeBlocking(opSetClaim, opSetParams,
returnTypes);

-- 
View this message in context: http://www.nabble.com/Creating-Axis2-SOAP-Header-tf3718396.html#a10403132
Sent from the Axis - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-user-help@ws.apache.org


Re: [Axis2] Creating Axis2 SOAP Header

Posted by Daniel Herbison <he...@nortel.com>.
Thank you!

That has solved the runtime exception.


Eran Chinthaka wrote:
> 
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
> 
> Do this.
> 
> instead of serviceClient.addHeader(header)
> 
> put serviceClient.addHeader(basicCredentials).
> 
> The addHeader method can not accept an instance of Header class (arghh
> !! I better check this inside the code)
> 
> If this doesn't solve your problem, I need to re-create the problem and
> see. So please create a JIRA issue and upload your code there.
> 
> Chinthaka
> 
> Daniel Herbison wrote:
>> Thank you so far for your help!
>> 
>> The code is getting to the call (invokeBlocking) but is failing with this
>> exception:
>> 
>> Exception in thread "main" org.apache.axiom.soap.SOAPProcessingException:
>> Expecting an implementation of SOAP Envelope as the parent. But received
>> some other implementation
>> 
>> Could the header be causing this?
>> 
>> When I print the header I see (this looks ok):
>> <soapenv:Header xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope">
>>  <BasicCredentials xmlns="beta">
>>   <serviceId>string1</serviceId>
>>   <serviceKey>string2</serviceKey>
>>  </BasicCredentials>
>> </soapenv:Header>
>> 
>> current code:
>> RPCServiceClient serviceClient = new RPCServiceClient();
>> Options options = serviceClient.getOptions();
>> options.setSoapVersionURI(org.apache.axis2.namespace.Constants.URI_SOAP12_ENV);
>> options.setTo(targetEPR);
>> 
>> // start header build
>> SOAPFactory factory = (SOAPFactory) OMAbstractFactory.getSOAP12Factory();
>> OMNamespace omNs = factory.createOMNamespace("beta", ""); 
>> SOAPHeader header = factory.createSOAPHeader();
>> OMElement basicCredentials = factory.createOMElement("BasicCredentials",
>> omNs); 
>> OMElement serviceId = factory.createOMElement("serviceId", omNs); 
>> OMText serviceIdText = factory.createOMText(serviceId, agentID);
>> serviceId.addChild(serviceIdText); 
>> OMElement serviceKey = factory.createOMElement("serviceKey", omNs); 
>> OMText serviceKeyText = factory.createOMText(serviceKey, agentToken);
>> serviceKey.addChild(serviceKeyText); 
>> basicCredentials.addChild(serviceId);
>> basicCredentials.addChild(serviceKey);
>> header.addChild(basicCredentials);
>> // end header build
>> 
>> serviceClient.addHeader(header);
>> QName opSetClaim = new QName("beta", "GetClaim" );
>> Object[] opSetParams = new Object[] { agentID, agentToken, requestor };
>> Class[] returnTypes = new Class[] { Object.class };
>> Exception occuring on next line
>> Object[] response = serviceClient.invokeBlocking(opSetClaim, opSetParams,
>> returnTypes);
>> 
>> 
>> Eran Chinthaka wrote:
>> Ok, the first advice is *never* use impl classes inside Axiom. Always
>> use the factories. The reason is we have multiple implementations of
>> them.
>> 
>> To correct your problem, the easiest way is to create an OMElement
>> rather than a SOAPHeaderBlock and call
>> serviceClient.addHeader(OMElement).
>> 
>> The second option is to use the created SOAP12Factory to create
>> SOAPHeaderBlock.
>> use soapFactory.createSOAPHeaderBlock(...)
>> 
>> HTH.
>> Chinthaka
>> 
>> Daniel Herbison wrote:
>>>>> I'm trying to add the SOAP header, described in comment in code below,
>>>>> to
>>>>> a
>>>>> RPC call to a service.  First of all I really do not know if the code
>>>>> to
>>>>> create the header is correct, i think it is in the ball park(?)  But I
>>>>> get a
>>>>> run time error of:
>>>>>
>>>>> Exception in thread "main" java.lang.ClassCastException:
>>>>> org.apache.axiom.om.impl.OMNamespaceImpl
>>>>>         at
>>>>> org.apache.axiom.soap.impl.dom.SOAPHeaderBlockImpl.<init>(SOAPHeaderBlockImpl.java:54)
>>>>>         at
>>>>> org.apache.axiom.soap.impl.dom.soap12.SOAP12HeaderBlockImpl.<init>(SOAP12HeaderBlockImpl.java:45)
>>>>>         at rpcAxSys.main(Unknown Source)
>>>>>
>>>>> the line causing the run time error is marked below, why is this doing
>>>>> this? 
>>>>> Also, is the header creation correct?
>>>>>
>>>>> code------------------
>>>>> RPCServiceClient serviceClient = new RPCServiceClient();
>>>>> Options options = serviceClient.getOptions();
>>>>> EndpointReference targetEPR = new
>>>>> EndpointReference("https://xyz/Authorize/Service.asmx");
>>>>> options.setTo(targetEPR);
>>>>>
>>>>> /* header build
>>>>>  <soap:Header>
>>>>>   <BasicCredentials xmlns="beta">
>>>>>    <serviceId>string1</serviceId>    
>>>>>    <serviceKey>string2</serviceKey>  
>>>>>   </BasicCredentials>
>>>>>  </soap:Header>
>>>>>  */
>>>>> OMFactory fac = OMAbstractFactory.getOMFactory();
>>>>> OMNamespace omNs = fac.createOMNamespace("beta", "xmlns"); 
>>>>>
>>>>> SOAPFactory soapFactory = new SOAP12Factory(); 
>>>>> SOAPHeaderBlock soapHeaderBlock = new
>>>>> SOAP12HeaderBlockImpl("Security",omNs,soapFactory); 
>>>>> soapHeaderBlock.setMustUnderstand(true); 
>>>>>
>>>>> OMElement basicCredentials = fac.createOMElement("BasicCredentials",
>>>>> omNs); 
>>>>>
>>>>> OMElement serviceId = fac.createOMElement("serviceId", omNs); 
>>>>> OMText serviceIdText = fac.createOMText(serviceId, agentID);
>>>>> serviceId.addChild(serviceIdText); 
>>>>>
>>>>> OMElement serviceKey = fac.createOMElement("serviceKey", omNs); 
>>>>> OMText serviceKeyText = fac.createOMText(serviceKey, agentToken);
>>>>> serviceKey.addChild(serviceKeyText); 
>>>>>
>>>>> basicCredentials.addChild(serviceId); 
>>>>> basicCredentials.addChild(serviceKey); 
>>>>>
>>>>> soapHeaderBlock.addChild(basicCredentials); 
>>>>>
>>>>> serviceClient.addHeader(soapHeaderBlock); 
>>>>> // end header build
>>>>>
>>>>> QName opSetClaim = new QName("beta", "GetClaim" );
>>>>>
>>>>> Object[] opSetParams = new Object[] { agentID, agentToken, requestor
>>>>> };
>>>>> Class[] returnTypes = new Class[] { Object.class };
>>>>>
>>>>> Object[] response = serviceClient.invokeBlocking(opSetClaim,
>>>>> opSetParams,
>>>>> returnTypes);
>>>>>
>>>
> - ---------------------------------------------------------------------
> To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
> For additional commands, e-mail: axis-user-help@ws.apache.org
>>>
>>>
>>>
> 
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.3 (GNU/Linux)
> Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
> 
> iD8DBQFGRU7bjON2uBzUhh8RAsnpAJ4gKItRxT9WzcBZnzmq0NmUhBqJEgCgj11k
> +8NtQclVduzU9J76Mi8I0Hk=
> =acAh
> -----END PGP SIGNATURE-----
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
> For additional commands, e-mail: axis-user-help@ws.apache.org
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Creating-Axis2-SOAP-Header-tf3718396.html#a10603729
Sent from the Axis - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-user-help@ws.apache.org


Re: [Axis2] Creating Axis2 SOAP Header

Posted by Eran Chinthaka <ch...@opensource.lk>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Do this.

instead of serviceClient.addHeader(header)

put serviceClient.addHeader(basicCredentials).

The addHeader method can not accept an instance of Header class (arghh
!! I better check this inside the code)

If this doesn't solve your problem, I need to re-create the problem and
see. So please create a JIRA issue and upload your code there.

Chinthaka

Daniel Herbison wrote:
> Thank you so far for your help!
> 
> The code is getting to the call (invokeBlocking) but is failing with this
> exception:
> 
> Exception in thread "main" org.apache.axiom.soap.SOAPProcessingException:
> Expecting an implementation of SOAP Envelope as the parent. But received
> some other implementation
> 
> Could the header be causing this?
> 
> When I print the header I see (this looks ok):
> <soapenv:Header xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope">
>  <BasicCredentials xmlns="beta">
>   <serviceId>string1</serviceId>
>   <serviceKey>string2</serviceKey>
>  </BasicCredentials>
> </soapenv:Header>
> 
> current code:
> RPCServiceClient serviceClient = new RPCServiceClient();
> Options options = serviceClient.getOptions();
> options.setSoapVersionURI(org.apache.axis2.namespace.Constants.URI_SOAP12_ENV);
> options.setTo(targetEPR);
> 
> // start header build
> SOAPFactory factory = (SOAPFactory) OMAbstractFactory.getSOAP12Factory();
> OMNamespace omNs = factory.createOMNamespace("beta", ""); 
> SOAPHeader header = factory.createSOAPHeader();
> OMElement basicCredentials = factory.createOMElement("BasicCredentials",
> omNs); 
> OMElement serviceId = factory.createOMElement("serviceId", omNs); 
> OMText serviceIdText = factory.createOMText(serviceId, agentID);
> serviceId.addChild(serviceIdText); 
> OMElement serviceKey = factory.createOMElement("serviceKey", omNs); 
> OMText serviceKeyText = factory.createOMText(serviceKey, agentToken);
> serviceKey.addChild(serviceKeyText); 
> basicCredentials.addChild(serviceId);
> basicCredentials.addChild(serviceKey);
> header.addChild(basicCredentials);
> // end header build
> 
> serviceClient.addHeader(header);
> QName opSetClaim = new QName("beta", "GetClaim" );
> Object[] opSetParams = new Object[] { agentID, agentToken, requestor };
> Class[] returnTypes = new Class[] { Object.class };
> Exception occuring on next line
> Object[] response = serviceClient.invokeBlocking(opSetClaim, opSetParams,
> returnTypes);
> 
> 
> Eran Chinthaka wrote:
> Ok, the first advice is *never* use impl classes inside Axiom. Always
> use the factories. The reason is we have multiple implementations of them.
> 
> To correct your problem, the easiest way is to create an OMElement
> rather than a SOAPHeaderBlock and call serviceClient.addHeader(OMElement).
> 
> The second option is to use the created SOAP12Factory to create
> SOAPHeaderBlock.
> use soapFactory.createSOAPHeaderBlock(...)
> 
> HTH.
> Chinthaka
> 
> Daniel Herbison wrote:
>>>> I'm trying to add the SOAP header, described in comment in code below, to
>>>> a
>>>> RPC call to a service.  First of all I really do not know if the code to
>>>> create the header is correct, i think it is in the ball park(?)  But I
>>>> get a
>>>> run time error of:
>>>>
>>>> Exception in thread "main" java.lang.ClassCastException:
>>>> org.apache.axiom.om.impl.OMNamespaceImpl
>>>>         at
>>>> org.apache.axiom.soap.impl.dom.SOAPHeaderBlockImpl.<init>(SOAPHeaderBlockImpl.java:54)
>>>>         at
>>>> org.apache.axiom.soap.impl.dom.soap12.SOAP12HeaderBlockImpl.<init>(SOAP12HeaderBlockImpl.java:45)
>>>>         at rpcAxSys.main(Unknown Source)
>>>>
>>>> the line causing the run time error is marked below, why is this doing
>>>> this? 
>>>> Also, is the header creation correct?
>>>>
>>>> code------------------
>>>> RPCServiceClient serviceClient = new RPCServiceClient();
>>>> Options options = serviceClient.getOptions();
>>>> EndpointReference targetEPR = new
>>>> EndpointReference("https://xyz/Authorize/Service.asmx");
>>>> options.setTo(targetEPR);
>>>>
>>>> /* header build
>>>>  <soap:Header>
>>>>   <BasicCredentials xmlns="beta">
>>>>    <serviceId>string1</serviceId>    
>>>>    <serviceKey>string2</serviceKey>  
>>>>   </BasicCredentials>
>>>>  </soap:Header>
>>>>  */
>>>> OMFactory fac = OMAbstractFactory.getOMFactory();
>>>> OMNamespace omNs = fac.createOMNamespace("beta", "xmlns"); 
>>>>
>>>> SOAPFactory soapFactory = new SOAP12Factory(); 
>>>> SOAPHeaderBlock soapHeaderBlock = new
>>>> SOAP12HeaderBlockImpl("Security",omNs,soapFactory); 
>>>> soapHeaderBlock.setMustUnderstand(true); 
>>>>
>>>> OMElement basicCredentials = fac.createOMElement("BasicCredentials",
>>>> omNs); 
>>>>
>>>> OMElement serviceId = fac.createOMElement("serviceId", omNs); 
>>>> OMText serviceIdText = fac.createOMText(serviceId, agentID);
>>>> serviceId.addChild(serviceIdText); 
>>>>
>>>> OMElement serviceKey = fac.createOMElement("serviceKey", omNs); 
>>>> OMText serviceKeyText = fac.createOMText(serviceKey, agentToken);
>>>> serviceKey.addChild(serviceKeyText); 
>>>>
>>>> basicCredentials.addChild(serviceId); 
>>>> basicCredentials.addChild(serviceKey); 
>>>>
>>>> soapHeaderBlock.addChild(basicCredentials); 
>>>>
>>>> serviceClient.addHeader(soapHeaderBlock); 
>>>> // end header build
>>>>
>>>> QName opSetClaim = new QName("beta", "GetClaim" );
>>>>
>>>> Object[] opSetParams = new Object[] { agentID, agentToken, requestor };
>>>> Class[] returnTypes = new Class[] { Object.class };
>>>>
>>>> Object[] response = serviceClient.invokeBlocking(opSetClaim, opSetParams,
>>>> returnTypes);
>>>>
>>
- ---------------------------------------------------------------------
To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-user-help@ws.apache.org
>>
>>
>>

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.3 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFGRU7bjON2uBzUhh8RAsnpAJ4gKItRxT9WzcBZnzmq0NmUhBqJEgCgj11k
+8NtQclVduzU9J76Mi8I0Hk=
=acAh
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-user-help@ws.apache.org


Re: [Axis2] Creating Axis2 SOAP Header

Posted by Daniel Herbison <he...@nortel.com>.
Thank you so far for your help!

The code is getting to the call (invokeBlocking) but is failing with this
exception:

Exception in thread "main" org.apache.axiom.soap.SOAPProcessingException:
Expecting an implementation of SOAP Envelope as the parent. But received
some other implementation

Could the header be causing this?

When I print the header I see (this looks ok):
<soapenv:Header xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope">
 <BasicCredentials xmlns="beta">
  <serviceId>string1</serviceId>
  <serviceKey>string2</serviceKey>
 </BasicCredentials>
</soapenv:Header>

current code:
RPCServiceClient serviceClient = new RPCServiceClient();
Options options = serviceClient.getOptions();
options.setSoapVersionURI(org.apache.axis2.namespace.Constants.URI_SOAP12_ENV);
options.setTo(targetEPR);

// start header build
SOAPFactory factory = (SOAPFactory) OMAbstractFactory.getSOAP12Factory();
OMNamespace omNs = factory.createOMNamespace("beta", ""); 
SOAPHeader header = factory.createSOAPHeader();
OMElement basicCredentials = factory.createOMElement("BasicCredentials",
omNs); 
OMElement serviceId = factory.createOMElement("serviceId", omNs); 
OMText serviceIdText = factory.createOMText(serviceId, agentID);
serviceId.addChild(serviceIdText); 
OMElement serviceKey = factory.createOMElement("serviceKey", omNs); 
OMText serviceKeyText = factory.createOMText(serviceKey, agentToken);
serviceKey.addChild(serviceKeyText); 
basicCredentials.addChild(serviceId);
basicCredentials.addChild(serviceKey);
header.addChild(basicCredentials);
// end header build

serviceClient.addHeader(header);
QName opSetClaim = new QName("beta", "GetClaim" );
Object[] opSetParams = new Object[] { agentID, agentToken, requestor };
Class[] returnTypes = new Class[] { Object.class };
Exception occuring on next line
Object[] response = serviceClient.invokeBlocking(opSetClaim, opSetParams,
returnTypes);


Eran Chinthaka wrote:
> 
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
> 
> Ok, the first advice is *never* use impl classes inside Axiom. Always
> use the factories. The reason is we have multiple implementations of them.
> 
> To correct your problem, the easiest way is to create an OMElement
> rather than a SOAPHeaderBlock and call serviceClient.addHeader(OMElement).
> 
> The second option is to use the created SOAP12Factory to create
> SOAPHeaderBlock.
> use soapFactory.createSOAPHeaderBlock(...)
> 
> HTH.
> Chinthaka
> 
> Daniel Herbison wrote:
>> I'm trying to add the SOAP header, described in comment in code below, to
>> a
>> RPC call to a service.  First of all I really do not know if the code to
>> create the header is correct, i think it is in the ball park(?)  But I
>> get a
>> run time error of:
>> 
>> Exception in thread "main" java.lang.ClassCastException:
>> org.apache.axiom.om.impl.OMNamespaceImpl
>>         at
>> org.apache.axiom.soap.impl.dom.SOAPHeaderBlockImpl.<init>(SOAPHeaderBlockImpl.java:54)
>>         at
>> org.apache.axiom.soap.impl.dom.soap12.SOAP12HeaderBlockImpl.<init>(SOAP12HeaderBlockImpl.java:45)
>>         at rpcAxSys.main(Unknown Source)
>> 
>> the line causing the run time error is marked below, why is this doing
>> this? 
>> Also, is the header creation correct?
>> 
>> code------------------
>> RPCServiceClient serviceClient = new RPCServiceClient();
>> Options options = serviceClient.getOptions();
>> EndpointReference targetEPR = new
>> EndpointReference("https://xyz/Authorize/Service.asmx");
>> options.setTo(targetEPR);
>> 
>> /* header build
>>  <soap:Header>
>>   <BasicCredentials xmlns="beta">
>>    <serviceId>string1</serviceId>    
>>    <serviceKey>string2</serviceKey>  
>>   </BasicCredentials>
>>  </soap:Header>
>>  */
>> OMFactory fac = OMAbstractFactory.getOMFactory();
>> OMNamespace omNs = fac.createOMNamespace("beta", "xmlns"); 
>> 
>> SOAPFactory soapFactory = new SOAP12Factory(); 
>> SOAPHeaderBlock soapHeaderBlock = new
>> SOAP12HeaderBlockImpl("Security",omNs,soapFactory); 
>> soapHeaderBlock.setMustUnderstand(true); 
>> 
>> OMElement basicCredentials = fac.createOMElement("BasicCredentials",
>> omNs); 
>> 
>> OMElement serviceId = fac.createOMElement("serviceId", omNs); 
>> OMText serviceIdText = fac.createOMText(serviceId, agentID);
>> serviceId.addChild(serviceIdText); 
>> 
>> OMElement serviceKey = fac.createOMElement("serviceKey", omNs); 
>> OMText serviceKeyText = fac.createOMText(serviceKey, agentToken);
>> serviceKey.addChild(serviceKeyText); 
>> 
>> basicCredentials.addChild(serviceId); 
>> basicCredentials.addChild(serviceKey); 
>> 
>> soapHeaderBlock.addChild(basicCredentials); 
>> 
>> serviceClient.addHeader(soapHeaderBlock); 
>> // end header build
>> 
>> QName opSetClaim = new QName("beta", "GetClaim" );
>> 
>> Object[] opSetParams = new Object[] { agentID, agentToken, requestor };
>> Class[] returnTypes = new Class[] { Object.class };
>> 
>> Object[] response = serviceClient.invokeBlocking(opSetClaim, opSetParams,
>> returnTypes);
>> 
> 
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.3 (GNU/Linux)
> Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
> 
> iD8DBQFGQ/jSjON2uBzUhh8RAqVZAKC0exk4tKs9zIALPgI65NYyo+AbxQCePUqQ
> xt15TCLceO7fDJe517267k8=
> =duG+
> -----END PGP SIGNATURE-----
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
> For additional commands, e-mail: axis-user-help@ws.apache.org
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Creating-Axis2-SOAP-Header-tf3718396.html#a10432841
Sent from the Axis - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-user-help@ws.apache.org


Re: [Axis2] Creating Axis2 SOAP Header

Posted by Eran Chinthaka <ch...@opensource.lk>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Ok, the first advice is *never* use impl classes inside Axiom. Always
use the factories. The reason is we have multiple implementations of them.

To correct your problem, the easiest way is to create an OMElement
rather than a SOAPHeaderBlock and call serviceClient.addHeader(OMElement).

The second option is to use the created SOAP12Factory to create
SOAPHeaderBlock.
use soapFactory.createSOAPHeaderBlock(...)

HTH.
Chinthaka

Daniel Herbison wrote:
> I'm trying to add the SOAP header, described in comment in code below, to a
> RPC call to a service.  First of all I really do not know if the code to
> create the header is correct, i think it is in the ball park(?)  But I get a
> run time error of:
> 
> Exception in thread "main" java.lang.ClassCastException:
> org.apache.axiom.om.impl.OMNamespaceImpl
>         at
> org.apache.axiom.soap.impl.dom.SOAPHeaderBlockImpl.<init>(SOAPHeaderBlockImpl.java:54)
>         at
> org.apache.axiom.soap.impl.dom.soap12.SOAP12HeaderBlockImpl.<init>(SOAP12HeaderBlockImpl.java:45)
>         at rpcAxSys.main(Unknown Source)
> 
> the line causing the run time error is marked below, why is this doing this? 
> Also, is the header creation correct?
> 
> code------------------
> RPCServiceClient serviceClient = new RPCServiceClient();
> Options options = serviceClient.getOptions();
> EndpointReference targetEPR = new
> EndpointReference("https://xyz/Authorize/Service.asmx");
> options.setTo(targetEPR);
> 
> /* header build
>  <soap:Header>
>   <BasicCredentials xmlns="beta">
>    <serviceId>string1</serviceId>    
>    <serviceKey>string2</serviceKey>  
>   </BasicCredentials>
>  </soap:Header>
>  */
> OMFactory fac = OMAbstractFactory.getOMFactory();
> OMNamespace omNs = fac.createOMNamespace("beta", "xmlns"); 
> 
> SOAPFactory soapFactory = new SOAP12Factory(); 
> SOAPHeaderBlock soapHeaderBlock = new
> SOAP12HeaderBlockImpl("Security",omNs,soapFactory); 
> soapHeaderBlock.setMustUnderstand(true); 
> 
> OMElement basicCredentials = fac.createOMElement("BasicCredentials", omNs); 
> 
> OMElement serviceId = fac.createOMElement("serviceId", omNs); 
> OMText serviceIdText = fac.createOMText(serviceId, agentID);
> serviceId.addChild(serviceIdText); 
> 
> OMElement serviceKey = fac.createOMElement("serviceKey", omNs); 
> OMText serviceKeyText = fac.createOMText(serviceKey, agentToken);
> serviceKey.addChild(serviceKeyText); 
> 
> basicCredentials.addChild(serviceId); 
> basicCredentials.addChild(serviceKey); 
> 
> soapHeaderBlock.addChild(basicCredentials); 
> 
> serviceClient.addHeader(soapHeaderBlock); 
> // end header build
> 
> QName opSetClaim = new QName("beta", "GetClaim" );
> 
> Object[] opSetParams = new Object[] { agentID, agentToken, requestor };
> Class[] returnTypes = new Class[] { Object.class };
> 
> Object[] response = serviceClient.invokeBlocking(opSetClaim, opSetParams,
> returnTypes);
> 

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.3 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFGQ/jSjON2uBzUhh8RAqVZAKC0exk4tKs9zIALPgI65NYyo+AbxQCePUqQ
xt15TCLceO7fDJe517267k8=
=duG+
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-user-help@ws.apache.org


Re: Creating Axis2 SOAP Header

Posted by Michele Mazzucco <Mi...@ncl.ac.uk>.
What about env.serialize(System.out)?, where env is a SOAPEnvelope
object?

Michele

On Thu, 2007-05-10 at 07:55 -0700, Daniel Herbison wrote:
> I changed this:
> 
> SOAPFactory factory = (SOAPFactory) OMAbstractFactory.getSOAP12Factory();
> 
> and got rid of the error but it is failing on the call with:
> 
> Exception in thread "main" org.apache.axiom.soap.SOAPProcessingException:
> Expecting an implementation of SOAP Envelope as the parent. But received
> some other implementation
>         at
> org.apache.axiom.soap.impl.llom.SOAPHeaderImpl.checkParent(SOAPHeaderImpl.java:369)
>         at
> org.apache.axiom.soap.impl.llom.SOAPElement.setParent(SOAPElement.java:75)
>         at
> org.apache.axiom.om.impl.llom.OMElementImpl.addChild(OMElementImpl.java:236)
>         at
> org.apache.axiom.om.impl.llom.OMElementImpl.addChild(OMElementImpl.java:192)
>         at
> org.apache.axis2.client.ServiceClient.addHeadersToEnvelope(ServiceClient.java:647)
>         at
> org.apache.axis2.client.ServiceClient.fillSOAPEnvelope(ServiceClient.java:633)
>         at
> org.apache.axis2.client.ServiceClient.sendReceive(ServiceClient.java:517)
>         at
> org.apache.axis2.client.ServiceClient.sendReceive(ServiceClient.java:500)
>         at
> org.apache.axis2.rpc.client.RPCServiceClient.invokeBlocking(RPCServiceClient.java:97)
>         at rpcAxSys.main(rpcAxSys.java:51)
> 
> Is there a way to print the soap message out before calling invokeBlocking?
> 
> Code excluding header code, same as before.
> 
> rpcAxSys rpc = new rpcAxSys(args[0],args[1],args[2]);
> EndpointReference targetEPR = new
> EndpointReference("https://pcary571.corp.nortel.com/Authorize/Service.asmx");
> RPCServiceClient serviceClient = new RPCServiceClient();
> Options options = serviceClient.getOptions();
> options.setTo(targetEPR);
> serviceClient.addHeader(rpc.header2());  // header2 has header generation
> code below
> QName opSetClaim = new QName("beta", "GetClaim" );
> Object[] opSetParams = new Object[] { rpc.agentID, rpc.agentToken,
> rpc.requestor };
> Class[] returnTypes = new Class[] { Object.class };
> Object[] response = serviceClient.invokeBlocking(opSetClaim, opSetParams,
> returnTypes); FAILING HERE 
> 
> 
> 
> 
> Michele Mazzucco-2 wrote:
> > 
> > Daniel,
> > 
> > could you please enable the debug  of javac (it is enabled by default,
> > remove the -g:none option) and tell us which line causes the problem?
> > 
> > Michele
> > 
> > On Thu, 2007-05-10 at 05:28 -0700, Daniel Herbison wrote:
> >> Thank you for your replies!
> >> I tried the code below and still get a runtime casting error.
> >> 
> >> Exception in thread "main" java.lang.ClassCastException:
> >> org.apache.axiom.soap.impl.llom.soap12.SOAP12Factory
> >>         at rpcAxSys.header2(Unknown Source)
> >>         at rpcAxSys.main(Unknown Source)
> >> 
> >> SOAP12Factory factory = (SOAP12Factory)
> >> OMAbstractFactory.getSOAP12Factory();
> >> OMNamespace omNs = factory.createOMNamespace("beta.va.nortel.com",
> >> "xmlns"); 
> >> 
> >> SOAPHeader header = factory.createSOAPHeader();
> >> 
> >> SOAPHeaderBlock block = factory.createSOAPHeaderBlock("BasicCredentials",
> >> omNs);
> >> 
> >> OMElement serviceId = factory.createOMElement("serviceId", omNs); 
> >> OMText serviceIdText = factory.createOMText(serviceId, agentID);
> >> serviceId.addChild(serviceIdText); 
> >> 
> >> OMElement serviceKey = factory.createOMElement("serviceKey", omNs); 
> >> OMText serviceKeyText = factory.createOMText(serviceKey, agentToken);
> >> serviceKey.addChild(serviceKeyText); 
> >> 
> >> block.addChild(serviceId);
> >> block.addChild(serviceKey);
> >> 
> >> header.addChild(block);
> >> 
> >> 
> >> Amila Suriarachchi wrote:
> >> > 
> >> > I am not sure about your problem.
> >> > but add this code to specifically set the soap12 for service client.
> >> > 
> >> > clientOptions = new Options();
> >> >
> >> clientOptions.setSoapVersionURI(SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI
> >> > );
> >> > serviceClient.setOptions(clientOptions);
> >> > 
> >> > On 5/10/07, Michele Mazzucco <Mi...@ncl.ac.uk> wrote:
> >> >>
> >> >> Daniel,
> >> >>
> >> >> I think the way you create the SOAPHeaderBlock is not correct. Can
> >> >> you try this way please?
> >> >>
> >> >> SOAP12Factory factory = (SOAP12Factory)
> >> >> OMAbstractFactory.getSOAP12Factory();
> >> >> OMNamespace omNs = factory.createOMNamespace(
> >> >>                         "http://...",
> >> >>                         "..."
> >> >>                 );
> >> >>
> >> >> SOAPEnvelope env = factory.createSOAPEnvelope();
> >> >> SOAPHeader header = factory.createSOAPHeader();
> >> >> SOAPHeaderBlock block = factory.createSOAPHeaderBlock(
> >> >>         SOAPHeaderConstants.ELEM_QOSP_HEADER_BLOCK, omNs);
> >> >> OMElement type = factory.createOMElement(
> >> >>                 SOAPHeaderConstants.ELEM_MESSAGE_TYPE, omNs);
> >> >>
> >> >> type.setText(MessageType.UPLOAD.value());
> >> >> block.addChild(type);
> >> >> header.addChild(block);
> >> >>
> >> >> SOAPBody body = factory.createSOAPBody();
> >> >> OMElement method = factory.createOMElement(SOAPUtils.UPLOAD_SERVICE,
> >> >> omNs);
> >> >>
> >> >> OMElement name = factory.createOMElement(
> >> >>         SOAPUtils.UPLOAD_SERVICE_FILE_NAME, omNs);
> >> >> name.setText(this.fileName);
> >> >>
> >> >> method.addChild(name);
> >> >> body.addChild(method);
> >> >> env.addChild(header);
> >> >> env.addChild(body);
> >> >>
> >> >>
> >> >> Michele
> >> >>
> >> >>
> >> >>
> >> >>
> >> >> On 9 May 2007, at 22:26, Daniel Herbison wrote:
> >> >>
> >> >> >
> >> >> > I'm trying to add the SOAP header, described in comment in code
> >> >> > below, to a
> >> >> > RPC call to a service.  First of all I really do not know if the
> >> >> > code to
> >> >> > create the header is correct, i think it is in the ball park(?)
> >> >> > But I get a
> >> >> > run time error of:
> >> >> >
> >> >> > Exception in thread "main" java.lang.ClassCastException:
> >> >> > org.apache.axiom.om.impl.OMNamespaceImpl
> >> >> >         at
> >> >> > org.apache.axiom.soap.impl.dom.SOAPHeaderBlockImpl.<init>
> >> >> > (SOAPHeaderBlockImpl.java:54)
> >> >> >         at
> >> >> > org.apache.axiom.soap.impl.dom.soap12.SOAP12HeaderBlockImpl.<init>
> >> >> > (SOAP12HeaderBlockImpl.java:45)
> >> >> >         at rpcAxSys.main(Unknown Source)
> >> >> >
> >> >> > the line causing the run time error is marked below, why is this
> >> >> > doing this?
> >> >> > Also, is the header creation correct?
> >> >> >
> >> >> > code------------------
> >> >> > RPCServiceClient serviceClient = new RPCServiceClient();
> >> >> > Options options = serviceClient.getOptions();
> >> >> > EndpointReference targetEPR = new
> >> >> > EndpointReference("https://xyz/Authorize/Service.asmx");
> >> >> > options.setTo(targetEPR);
> >> >> >
> >> >> > /* header build
> >> >> >  <soap:Header>
> >> >> >   <BasicCredentials xmlns="beta">
> >> >> >    <serviceId>string1</serviceId>
> >> >> >    <serviceKey>string2</serviceKey>
> >> >> >   </BasicCredentials>
> >> >> >  </soap:Header>
> >> >> >  */
> >> >> > OMFactory fac = OMAbstractFactory.getOMFactory();
> >> >> > OMNamespace omNs = fac.createOMNamespace("beta", "xmlns");
> >> >> >
> >> >> > SOAPFactory soapFactory = new SOAP12Factory();
> >> >> > SOAPHeaderBlock soapHeaderBlock = new
> >> >> > SOAP12HeaderBlockImpl("Security",omNs,soapFactory);
> >> >> > soapHeaderBlock.setMustUnderstand(true);
> >> >> >
> >> >> > OMElement basicCredentials = fac.createOMElement
> >> >> > ("BasicCredentials", omNs);
> >> >> >
> >> >> > OMElement serviceId = fac.createOMElement("serviceId", omNs);
> >> >> > OMText serviceIdText = fac.createOMText(serviceId, agentID);
> >> >> > serviceId.addChild(serviceIdText);
> >> >> >
> >> >> > OMElement serviceKey = fac.createOMElement("serviceKey", omNs);
> >> >> > OMText serviceKeyText = fac.createOMText(serviceKey, agentToken);
> >> >> > serviceKey.addChild(serviceKeyText);
> >> >> >
> >> >> > basicCredentials.addChild(serviceId);
> >> >> > basicCredentials.addChild(serviceKey);
> >> >> >
> >> >> > soapHeaderBlock.addChild(basicCredentials);
> >> >> >
> >> >> > serviceClient.addHeader(soapHeaderBlock);
> >> >> > // end header build
> >> >> >
> >> >> > QName opSetClaim = new QName("beta", "GetClaim" );
> >> >> >
> >> >> > Object[] opSetParams = new Object[] { agentID, agentToken,
> >> >> > requestor };
> >> >> > Class[] returnTypes = new Class[] { Object.class };
> >> >> >
> >> >> > Object[] response = serviceClient.invokeBlocking(opSetClaim,
> >> >> > opSetParams,
> >> >> > returnTypes);
> >> >> >
> >> >> > --
> >> >> > View this message in context: http://www.nabble.com/Creating-Axis2-
> >> >> > SOAP-Header-tf3718396.html#a10403132
> >> >> > Sent from the Axis - User mailing list archive at Nabble.com.
> >> >> >
> >> >> >
> >> >> >
> >> ---------------------------------------------------------------------
> >> >> > To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
> >> >> > For additional commands, e-mail: axis-user-help@ws.apache.org
> >> >> >
> >> >>
> >> >>
> >> >> ---------------------------------------------------------------------
> >> >> To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
> >> >> For additional commands, e-mail: axis-user-help@ws.apache.org
> >> >>
> >> >>
> >> > 
> >> > 
> >> > -- 
> >> > Amila Suriarachchi,
> >> > WSO2 Inc.
> >> > 
> >> > 
> >> 
> > 
> > 
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
> > For additional commands, e-mail: axis-user-help@ws.apache.org
> > 
> > 
> > 
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-user-help@ws.apache.org


Re: Creating Axis2 SOAP Header

Posted by Daniel Herbison <he...@nortel.com>.
I changed this:

SOAPFactory factory = (SOAPFactory) OMAbstractFactory.getSOAP12Factory();

and got rid of the error but it is failing on the call with:

Exception in thread "main" org.apache.axiom.soap.SOAPProcessingException:
Expecting an implementation of SOAP Envelope as the parent. But received
some other implementation
        at
org.apache.axiom.soap.impl.llom.SOAPHeaderImpl.checkParent(SOAPHeaderImpl.java:369)
        at
org.apache.axiom.soap.impl.llom.SOAPElement.setParent(SOAPElement.java:75)
        at
org.apache.axiom.om.impl.llom.OMElementImpl.addChild(OMElementImpl.java:236)
        at
org.apache.axiom.om.impl.llom.OMElementImpl.addChild(OMElementImpl.java:192)
        at
org.apache.axis2.client.ServiceClient.addHeadersToEnvelope(ServiceClient.java:647)
        at
org.apache.axis2.client.ServiceClient.fillSOAPEnvelope(ServiceClient.java:633)
        at
org.apache.axis2.client.ServiceClient.sendReceive(ServiceClient.java:517)
        at
org.apache.axis2.client.ServiceClient.sendReceive(ServiceClient.java:500)
        at
org.apache.axis2.rpc.client.RPCServiceClient.invokeBlocking(RPCServiceClient.java:97)
        at rpcAxSys.main(rpcAxSys.java:51)

Is there a way to print the soap message out before calling invokeBlocking?

Code excluding header code, same as before.

rpcAxSys rpc = new rpcAxSys(args[0],args[1],args[2]);
EndpointReference targetEPR = new
EndpointReference("https://pcary571.corp.nortel.com/Authorize/Service.asmx");
RPCServiceClient serviceClient = new RPCServiceClient();
Options options = serviceClient.getOptions();
options.setTo(targetEPR);
serviceClient.addHeader(rpc.header2());  // header2 has header generation
code below
QName opSetClaim = new QName("beta", "GetClaim" );
Object[] opSetParams = new Object[] { rpc.agentID, rpc.agentToken,
rpc.requestor };
Class[] returnTypes = new Class[] { Object.class };
Object[] response = serviceClient.invokeBlocking(opSetClaim, opSetParams,
returnTypes); FAILING HERE 




Michele Mazzucco-2 wrote:
> 
> Daniel,
> 
> could you please enable the debug  of javac (it is enabled by default,
> remove the -g:none option) and tell us which line causes the problem?
> 
> Michele
> 
> On Thu, 2007-05-10 at 05:28 -0700, Daniel Herbison wrote:
>> Thank you for your replies!
>> I tried the code below and still get a runtime casting error.
>> 
>> Exception in thread "main" java.lang.ClassCastException:
>> org.apache.axiom.soap.impl.llom.soap12.SOAP12Factory
>>         at rpcAxSys.header2(Unknown Source)
>>         at rpcAxSys.main(Unknown Source)
>> 
>> SOAP12Factory factory = (SOAP12Factory)
>> OMAbstractFactory.getSOAP12Factory();
>> OMNamespace omNs = factory.createOMNamespace("beta.va.nortel.com",
>> "xmlns"); 
>> 
>> SOAPHeader header = factory.createSOAPHeader();
>> 
>> SOAPHeaderBlock block = factory.createSOAPHeaderBlock("BasicCredentials",
>> omNs);
>> 
>> OMElement serviceId = factory.createOMElement("serviceId", omNs); 
>> OMText serviceIdText = factory.createOMText(serviceId, agentID);
>> serviceId.addChild(serviceIdText); 
>> 
>> OMElement serviceKey = factory.createOMElement("serviceKey", omNs); 
>> OMText serviceKeyText = factory.createOMText(serviceKey, agentToken);
>> serviceKey.addChild(serviceKeyText); 
>> 
>> block.addChild(serviceId);
>> block.addChild(serviceKey);
>> 
>> header.addChild(block);
>> 
>> 
>> Amila Suriarachchi wrote:
>> > 
>> > I am not sure about your problem.
>> > but add this code to specifically set the soap12 for service client.
>> > 
>> > clientOptions = new Options();
>> >
>> clientOptions.setSoapVersionURI(SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI
>> > );
>> > serviceClient.setOptions(clientOptions);
>> > 
>> > On 5/10/07, Michele Mazzucco <Mi...@ncl.ac.uk> wrote:
>> >>
>> >> Daniel,
>> >>
>> >> I think the way you create the SOAPHeaderBlock is not correct. Can
>> >> you try this way please?
>> >>
>> >> SOAP12Factory factory = (SOAP12Factory)
>> >> OMAbstractFactory.getSOAP12Factory();
>> >> OMNamespace omNs = factory.createOMNamespace(
>> >>                         "http://...",
>> >>                         "..."
>> >>                 );
>> >>
>> >> SOAPEnvelope env = factory.createSOAPEnvelope();
>> >> SOAPHeader header = factory.createSOAPHeader();
>> >> SOAPHeaderBlock block = factory.createSOAPHeaderBlock(
>> >>         SOAPHeaderConstants.ELEM_QOSP_HEADER_BLOCK, omNs);
>> >> OMElement type = factory.createOMElement(
>> >>                 SOAPHeaderConstants.ELEM_MESSAGE_TYPE, omNs);
>> >>
>> >> type.setText(MessageType.UPLOAD.value());
>> >> block.addChild(type);
>> >> header.addChild(block);
>> >>
>> >> SOAPBody body = factory.createSOAPBody();
>> >> OMElement method = factory.createOMElement(SOAPUtils.UPLOAD_SERVICE,
>> >> omNs);
>> >>
>> >> OMElement name = factory.createOMElement(
>> >>         SOAPUtils.UPLOAD_SERVICE_FILE_NAME, omNs);
>> >> name.setText(this.fileName);
>> >>
>> >> method.addChild(name);
>> >> body.addChild(method);
>> >> env.addChild(header);
>> >> env.addChild(body);
>> >>
>> >>
>> >> Michele
>> >>
>> >>
>> >>
>> >>
>> >> On 9 May 2007, at 22:26, Daniel Herbison wrote:
>> >>
>> >> >
>> >> > I'm trying to add the SOAP header, described in comment in code
>> >> > below, to a
>> >> > RPC call to a service.  First of all I really do not know if the
>> >> > code to
>> >> > create the header is correct, i think it is in the ball park(?)
>> >> > But I get a
>> >> > run time error of:
>> >> >
>> >> > Exception in thread "main" java.lang.ClassCastException:
>> >> > org.apache.axiom.om.impl.OMNamespaceImpl
>> >> >         at
>> >> > org.apache.axiom.soap.impl.dom.SOAPHeaderBlockImpl.<init>
>> >> > (SOAPHeaderBlockImpl.java:54)
>> >> >         at
>> >> > org.apache.axiom.soap.impl.dom.soap12.SOAP12HeaderBlockImpl.<init>
>> >> > (SOAP12HeaderBlockImpl.java:45)
>> >> >         at rpcAxSys.main(Unknown Source)
>> >> >
>> >> > the line causing the run time error is marked below, why is this
>> >> > doing this?
>> >> > Also, is the header creation correct?
>> >> >
>> >> > code------------------
>> >> > RPCServiceClient serviceClient = new RPCServiceClient();
>> >> > Options options = serviceClient.getOptions();
>> >> > EndpointReference targetEPR = new
>> >> > EndpointReference("https://xyz/Authorize/Service.asmx");
>> >> > options.setTo(targetEPR);
>> >> >
>> >> > /* header build
>> >> >  <soap:Header>
>> >> >   <BasicCredentials xmlns="beta">
>> >> >    <serviceId>string1</serviceId>
>> >> >    <serviceKey>string2</serviceKey>
>> >> >   </BasicCredentials>
>> >> >  </soap:Header>
>> >> >  */
>> >> > OMFactory fac = OMAbstractFactory.getOMFactory();
>> >> > OMNamespace omNs = fac.createOMNamespace("beta", "xmlns");
>> >> >
>> >> > SOAPFactory soapFactory = new SOAP12Factory();
>> >> > SOAPHeaderBlock soapHeaderBlock = new
>> >> > SOAP12HeaderBlockImpl("Security",omNs,soapFactory);
>> >> > soapHeaderBlock.setMustUnderstand(true);
>> >> >
>> >> > OMElement basicCredentials = fac.createOMElement
>> >> > ("BasicCredentials", omNs);
>> >> >
>> >> > OMElement serviceId = fac.createOMElement("serviceId", omNs);
>> >> > OMText serviceIdText = fac.createOMText(serviceId, agentID);
>> >> > serviceId.addChild(serviceIdText);
>> >> >
>> >> > OMElement serviceKey = fac.createOMElement("serviceKey", omNs);
>> >> > OMText serviceKeyText = fac.createOMText(serviceKey, agentToken);
>> >> > serviceKey.addChild(serviceKeyText);
>> >> >
>> >> > basicCredentials.addChild(serviceId);
>> >> > basicCredentials.addChild(serviceKey);
>> >> >
>> >> > soapHeaderBlock.addChild(basicCredentials);
>> >> >
>> >> > serviceClient.addHeader(soapHeaderBlock);
>> >> > // end header build
>> >> >
>> >> > QName opSetClaim = new QName("beta", "GetClaim" );
>> >> >
>> >> > Object[] opSetParams = new Object[] { agentID, agentToken,
>> >> > requestor };
>> >> > Class[] returnTypes = new Class[] { Object.class };
>> >> >
>> >> > Object[] response = serviceClient.invokeBlocking(opSetClaim,
>> >> > opSetParams,
>> >> > returnTypes);
>> >> >
>> >> > --
>> >> > View this message in context: http://www.nabble.com/Creating-Axis2-
>> >> > SOAP-Header-tf3718396.html#a10403132
>> >> > Sent from the Axis - User mailing list archive at Nabble.com.
>> >> >
>> >> >
>> >> >
>> ---------------------------------------------------------------------
>> >> > To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
>> >> > For additional commands, e-mail: axis-user-help@ws.apache.org
>> >> >
>> >>
>> >>
>> >> ---------------------------------------------------------------------
>> >> To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
>> >> For additional commands, e-mail: axis-user-help@ws.apache.org
>> >>
>> >>
>> > 
>> > 
>> > -- 
>> > Amila Suriarachchi,
>> > WSO2 Inc.
>> > 
>> > 
>> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
> For additional commands, e-mail: axis-user-help@ws.apache.org
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Creating-Axis2-SOAP-Header-tf3718396.html#a10414907
Sent from the Axis - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-user-help@ws.apache.org


Re: Creating Axis2 SOAP Header

Posted by Michele Mazzucco <Mi...@ncl.ac.uk>.
Daniel,

could you please enable the debug  of javac (it is enabled by default,
remove the -g:none option) and tell us which line causes the problem?

Michele

On Thu, 2007-05-10 at 05:28 -0700, Daniel Herbison wrote:
> Thank you for your replies!
> I tried the code below and still get a runtime casting error.
> 
> Exception in thread "main" java.lang.ClassCastException:
> org.apache.axiom.soap.impl.llom.soap12.SOAP12Factory
>         at rpcAxSys.header2(Unknown Source)
>         at rpcAxSys.main(Unknown Source)
> 
> SOAP12Factory factory = (SOAP12Factory)
> OMAbstractFactory.getSOAP12Factory();
> OMNamespace omNs = factory.createOMNamespace("beta.va.nortel.com", "xmlns"); 
> 
> SOAPHeader header = factory.createSOAPHeader();
> 
> SOAPHeaderBlock block = factory.createSOAPHeaderBlock("BasicCredentials",
> omNs);
> 
> OMElement serviceId = factory.createOMElement("serviceId", omNs); 
> OMText serviceIdText = factory.createOMText(serviceId, agentID);
> serviceId.addChild(serviceIdText); 
> 
> OMElement serviceKey = factory.createOMElement("serviceKey", omNs); 
> OMText serviceKeyText = factory.createOMText(serviceKey, agentToken);
> serviceKey.addChild(serviceKeyText); 
> 
> block.addChild(serviceId);
> block.addChild(serviceKey);
> 
> header.addChild(block);
> 
> 
> Amila Suriarachchi wrote:
> > 
> > I am not sure about your problem.
> > but add this code to specifically set the soap12 for service client.
> > 
> > clientOptions = new Options();
> > clientOptions.setSoapVersionURI(SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI
> > );
> > serviceClient.setOptions(clientOptions);
> > 
> > On 5/10/07, Michele Mazzucco <Mi...@ncl.ac.uk> wrote:
> >>
> >> Daniel,
> >>
> >> I think the way you create the SOAPHeaderBlock is not correct. Can
> >> you try this way please?
> >>
> >> SOAP12Factory factory = (SOAP12Factory)
> >> OMAbstractFactory.getSOAP12Factory();
> >> OMNamespace omNs = factory.createOMNamespace(
> >>                         "http://...",
> >>                         "..."
> >>                 );
> >>
> >> SOAPEnvelope env = factory.createSOAPEnvelope();
> >> SOAPHeader header = factory.createSOAPHeader();
> >> SOAPHeaderBlock block = factory.createSOAPHeaderBlock(
> >>         SOAPHeaderConstants.ELEM_QOSP_HEADER_BLOCK, omNs);
> >> OMElement type = factory.createOMElement(
> >>                 SOAPHeaderConstants.ELEM_MESSAGE_TYPE, omNs);
> >>
> >> type.setText(MessageType.UPLOAD.value());
> >> block.addChild(type);
> >> header.addChild(block);
> >>
> >> SOAPBody body = factory.createSOAPBody();
> >> OMElement method = factory.createOMElement(SOAPUtils.UPLOAD_SERVICE,
> >> omNs);
> >>
> >> OMElement name = factory.createOMElement(
> >>         SOAPUtils.UPLOAD_SERVICE_FILE_NAME, omNs);
> >> name.setText(this.fileName);
> >>
> >> method.addChild(name);
> >> body.addChild(method);
> >> env.addChild(header);
> >> env.addChild(body);
> >>
> >>
> >> Michele
> >>
> >>
> >>
> >>
> >> On 9 May 2007, at 22:26, Daniel Herbison wrote:
> >>
> >> >
> >> > I'm trying to add the SOAP header, described in comment in code
> >> > below, to a
> >> > RPC call to a service.  First of all I really do not know if the
> >> > code to
> >> > create the header is correct, i think it is in the ball park(?)
> >> > But I get a
> >> > run time error of:
> >> >
> >> > Exception in thread "main" java.lang.ClassCastException:
> >> > org.apache.axiom.om.impl.OMNamespaceImpl
> >> >         at
> >> > org.apache.axiom.soap.impl.dom.SOAPHeaderBlockImpl.<init>
> >> > (SOAPHeaderBlockImpl.java:54)
> >> >         at
> >> > org.apache.axiom.soap.impl.dom.soap12.SOAP12HeaderBlockImpl.<init>
> >> > (SOAP12HeaderBlockImpl.java:45)
> >> >         at rpcAxSys.main(Unknown Source)
> >> >
> >> > the line causing the run time error is marked below, why is this
> >> > doing this?
> >> > Also, is the header creation correct?
> >> >
> >> > code------------------
> >> > RPCServiceClient serviceClient = new RPCServiceClient();
> >> > Options options = serviceClient.getOptions();
> >> > EndpointReference targetEPR = new
> >> > EndpointReference("https://xyz/Authorize/Service.asmx");
> >> > options.setTo(targetEPR);
> >> >
> >> > /* header build
> >> >  <soap:Header>
> >> >   <BasicCredentials xmlns="beta">
> >> >    <serviceId>string1</serviceId>
> >> >    <serviceKey>string2</serviceKey>
> >> >   </BasicCredentials>
> >> >  </soap:Header>
> >> >  */
> >> > OMFactory fac = OMAbstractFactory.getOMFactory();
> >> > OMNamespace omNs = fac.createOMNamespace("beta", "xmlns");
> >> >
> >> > SOAPFactory soapFactory = new SOAP12Factory();
> >> > SOAPHeaderBlock soapHeaderBlock = new
> >> > SOAP12HeaderBlockImpl("Security",omNs,soapFactory);
> >> > soapHeaderBlock.setMustUnderstand(true);
> >> >
> >> > OMElement basicCredentials = fac.createOMElement
> >> > ("BasicCredentials", omNs);
> >> >
> >> > OMElement serviceId = fac.createOMElement("serviceId", omNs);
> >> > OMText serviceIdText = fac.createOMText(serviceId, agentID);
> >> > serviceId.addChild(serviceIdText);
> >> >
> >> > OMElement serviceKey = fac.createOMElement("serviceKey", omNs);
> >> > OMText serviceKeyText = fac.createOMText(serviceKey, agentToken);
> >> > serviceKey.addChild(serviceKeyText);
> >> >
> >> > basicCredentials.addChild(serviceId);
> >> > basicCredentials.addChild(serviceKey);
> >> >
> >> > soapHeaderBlock.addChild(basicCredentials);
> >> >
> >> > serviceClient.addHeader(soapHeaderBlock);
> >> > // end header build
> >> >
> >> > QName opSetClaim = new QName("beta", "GetClaim" );
> >> >
> >> > Object[] opSetParams = new Object[] { agentID, agentToken,
> >> > requestor };
> >> > Class[] returnTypes = new Class[] { Object.class };
> >> >
> >> > Object[] response = serviceClient.invokeBlocking(opSetClaim,
> >> > opSetParams,
> >> > returnTypes);
> >> >
> >> > --
> >> > View this message in context: http://www.nabble.com/Creating-Axis2-
> >> > SOAP-Header-tf3718396.html#a10403132
> >> > Sent from the Axis - User mailing list archive at Nabble.com.
> >> >
> >> >
> >> > ---------------------------------------------------------------------
> >> > To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
> >> > For additional commands, e-mail: axis-user-help@ws.apache.org
> >> >
> >>
> >>
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
> >> For additional commands, e-mail: axis-user-help@ws.apache.org
> >>
> >>
> > 
> > 
> > -- 
> > Amila Suriarachchi,
> > WSO2 Inc.
> > 
> > 
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-user-help@ws.apache.org


Re: Creating Axis2 SOAP Header

Posted by Daniel Herbison <he...@nortel.com>.
Thank you for your replies!
I tried the code below and still get a runtime casting error.

Exception in thread "main" java.lang.ClassCastException:
org.apache.axiom.soap.impl.llom.soap12.SOAP12Factory
        at rpcAxSys.header2(Unknown Source)
        at rpcAxSys.main(Unknown Source)

SOAP12Factory factory = (SOAP12Factory)
OMAbstractFactory.getSOAP12Factory();
OMNamespace omNs = factory.createOMNamespace("beta.va.nortel.com", "xmlns"); 

SOAPHeader header = factory.createSOAPHeader();

SOAPHeaderBlock block = factory.createSOAPHeaderBlock("BasicCredentials",
omNs);

OMElement serviceId = factory.createOMElement("serviceId", omNs); 
OMText serviceIdText = factory.createOMText(serviceId, agentID);
serviceId.addChild(serviceIdText); 

OMElement serviceKey = factory.createOMElement("serviceKey", omNs); 
OMText serviceKeyText = factory.createOMText(serviceKey, agentToken);
serviceKey.addChild(serviceKeyText); 

block.addChild(serviceId);
block.addChild(serviceKey);

header.addChild(block);


Amila Suriarachchi wrote:
> 
> I am not sure about your problem.
> but add this code to specifically set the soap12 for service client.
> 
> clientOptions = new Options();
> clientOptions.setSoapVersionURI(SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI
> );
> serviceClient.setOptions(clientOptions);
> 
> On 5/10/07, Michele Mazzucco <Mi...@ncl.ac.uk> wrote:
>>
>> Daniel,
>>
>> I think the way you create the SOAPHeaderBlock is not correct. Can
>> you try this way please?
>>
>> SOAP12Factory factory = (SOAP12Factory)
>> OMAbstractFactory.getSOAP12Factory();
>> OMNamespace omNs = factory.createOMNamespace(
>>                         "http://...",
>>                         "..."
>>                 );
>>
>> SOAPEnvelope env = factory.createSOAPEnvelope();
>> SOAPHeader header = factory.createSOAPHeader();
>> SOAPHeaderBlock block = factory.createSOAPHeaderBlock(
>>         SOAPHeaderConstants.ELEM_QOSP_HEADER_BLOCK, omNs);
>> OMElement type = factory.createOMElement(
>>                 SOAPHeaderConstants.ELEM_MESSAGE_TYPE, omNs);
>>
>> type.setText(MessageType.UPLOAD.value());
>> block.addChild(type);
>> header.addChild(block);
>>
>> SOAPBody body = factory.createSOAPBody();
>> OMElement method = factory.createOMElement(SOAPUtils.UPLOAD_SERVICE,
>> omNs);
>>
>> OMElement name = factory.createOMElement(
>>         SOAPUtils.UPLOAD_SERVICE_FILE_NAME, omNs);
>> name.setText(this.fileName);
>>
>> method.addChild(name);
>> body.addChild(method);
>> env.addChild(header);
>> env.addChild(body);
>>
>>
>> Michele
>>
>>
>>
>>
>> On 9 May 2007, at 22:26, Daniel Herbison wrote:
>>
>> >
>> > I'm trying to add the SOAP header, described in comment in code
>> > below, to a
>> > RPC call to a service.  First of all I really do not know if the
>> > code to
>> > create the header is correct, i think it is in the ball park(?)
>> > But I get a
>> > run time error of:
>> >
>> > Exception in thread "main" java.lang.ClassCastException:
>> > org.apache.axiom.om.impl.OMNamespaceImpl
>> >         at
>> > org.apache.axiom.soap.impl.dom.SOAPHeaderBlockImpl.<init>
>> > (SOAPHeaderBlockImpl.java:54)
>> >         at
>> > org.apache.axiom.soap.impl.dom.soap12.SOAP12HeaderBlockImpl.<init>
>> > (SOAP12HeaderBlockImpl.java:45)
>> >         at rpcAxSys.main(Unknown Source)
>> >
>> > the line causing the run time error is marked below, why is this
>> > doing this?
>> > Also, is the header creation correct?
>> >
>> > code------------------
>> > RPCServiceClient serviceClient = new RPCServiceClient();
>> > Options options = serviceClient.getOptions();
>> > EndpointReference targetEPR = new
>> > EndpointReference("https://xyz/Authorize/Service.asmx");
>> > options.setTo(targetEPR);
>> >
>> > /* header build
>> >  <soap:Header>
>> >   <BasicCredentials xmlns="beta">
>> >    <serviceId>string1</serviceId>
>> >    <serviceKey>string2</serviceKey>
>> >   </BasicCredentials>
>> >  </soap:Header>
>> >  */
>> > OMFactory fac = OMAbstractFactory.getOMFactory();
>> > OMNamespace omNs = fac.createOMNamespace("beta", "xmlns");
>> >
>> > SOAPFactory soapFactory = new SOAP12Factory();
>> > SOAPHeaderBlock soapHeaderBlock = new
>> > SOAP12HeaderBlockImpl("Security",omNs,soapFactory);
>> > soapHeaderBlock.setMustUnderstand(true);
>> >
>> > OMElement basicCredentials = fac.createOMElement
>> > ("BasicCredentials", omNs);
>> >
>> > OMElement serviceId = fac.createOMElement("serviceId", omNs);
>> > OMText serviceIdText = fac.createOMText(serviceId, agentID);
>> > serviceId.addChild(serviceIdText);
>> >
>> > OMElement serviceKey = fac.createOMElement("serviceKey", omNs);
>> > OMText serviceKeyText = fac.createOMText(serviceKey, agentToken);
>> > serviceKey.addChild(serviceKeyText);
>> >
>> > basicCredentials.addChild(serviceId);
>> > basicCredentials.addChild(serviceKey);
>> >
>> > soapHeaderBlock.addChild(basicCredentials);
>> >
>> > serviceClient.addHeader(soapHeaderBlock);
>> > // end header build
>> >
>> > QName opSetClaim = new QName("beta", "GetClaim" );
>> >
>> > Object[] opSetParams = new Object[] { agentID, agentToken,
>> > requestor };
>> > Class[] returnTypes = new Class[] { Object.class };
>> >
>> > Object[] response = serviceClient.invokeBlocking(opSetClaim,
>> > opSetParams,
>> > returnTypes);
>> >
>> > --
>> > View this message in context: http://www.nabble.com/Creating-Axis2-
>> > SOAP-Header-tf3718396.html#a10403132
>> > Sent from the Axis - User mailing list archive at Nabble.com.
>> >
>> >
>> > ---------------------------------------------------------------------
>> > To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
>> > For additional commands, e-mail: axis-user-help@ws.apache.org
>> >
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
>> For additional commands, e-mail: axis-user-help@ws.apache.org
>>
>>
> 
> 
> -- 
> Amila Suriarachchi,
> WSO2 Inc.
> 
> 

-- 
View this message in context: http://www.nabble.com/Creating-Axis2-SOAP-Header-tf3718396.html#a10412374
Sent from the Axis - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-user-help@ws.apache.org


Re: Creating Axis2 SOAP Header

Posted by Samisa Abeysinghe <sa...@wso2.com>.
Eran Chinthaka wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> Samisa Abeysinghe wrote:
>   
>> Amila Suriarachchi wrote:
>>     
>>> I am not sure about your problem.
>>> but add this code to specifically set the soap12 for service client.
>>>
>>> clientOptions = new Options();
>>> clientOptions.setSoapVersionURI(SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI
>>> );
>>>       
>> Why not simplify the API to something like:
>> clientOptions.setSoap12();
>>     
>
> Look at the number of properties inside Options. So are you suggesting
> to have one setter and a getter method of all of those params? 
Not exactly! Just make the common case simple. As an example, setting 
SOAP version, enabling MTOM, REST are more common. Leave all other more 
complex stuff to params.

Samisa...

-- 
Samisa Abeysinghe : http://www.wso2.org/ (WSO2 Oxygen Tank - Web Services Developers' Portal)


---------------------------------------------------------------------
To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-user-help@ws.apache.org


Re: Creating Axis2 SOAP Header

Posted by Eran Chinthaka <ch...@opensource.lk>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Samisa Abeysinghe wrote:
> Amila Suriarachchi wrote:
>> I am not sure about your problem.
>> but add this code to specifically set the soap12 for service client.
>>
>> clientOptions = new Options();
>> clientOptions.setSoapVersionURI(SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI
>> );
> Why not simplify the API to something like:
> clientOptions.setSoap12();

Look at the number of properties inside Options. So are you suggesting
to have one setter and a getter method of all of those params? And what
about API changes whenever we add a new property.

Hmm, the best option we thought was to use properties like this so that
there are no problems to API and you won't see hundreds of methods
inside options.

Thanks,
Chinthaka

> 
> Samisa...
>> serviceClient.setOptions(clientOptions);
>>
> 

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.3 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFGQ/eCjON2uBzUhh8RAn6DAJ9P1rsJPsuo9IX0XmCuYDWDc5ZytQCfRQ6H
z0cOZBaE9B85sKHfqQQB9RY=
=+Ma2
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-user-help@ws.apache.org


Re: Creating Axis2 SOAP Header

Posted by Samisa Abeysinghe <sa...@gmail.com>.
Amila Suriarachchi wrote:
> I am not sure about your problem.
> but add this code to specifically set the soap12 for service client.
>
> clientOptions = new Options();
> clientOptions.setSoapVersionURI(SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI 
> );
Why not simplify the API to something like:
clientOptions.setSoap12();

Samisa...
> serviceClient.setOptions(clientOptions);
>

-- 
Samisa Abeysinghe : http://www.bloglines.com/blog/samisa


---------------------------------------------------------------------
To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-user-help@ws.apache.org


Re: Creating Axis2 SOAP Header

Posted by Amila Suriarachchi <am...@gmail.com>.
I am not sure about your problem.
but add this code to specifically set the soap12 for service client.

clientOptions = new Options();
clientOptions.setSoapVersionURI(SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI
);
serviceClient.setOptions(clientOptions);

On 5/10/07, Michele Mazzucco <Mi...@ncl.ac.uk> wrote:
>
> Daniel,
>
> I think the way you create the SOAPHeaderBlock is not correct. Can
> you try this way please?
>
> SOAP12Factory factory = (SOAP12Factory)
> OMAbstractFactory.getSOAP12Factory();
> OMNamespace omNs = factory.createOMNamespace(
>                         "http://...",
>                         "..."
>                 );
>
> SOAPEnvelope env = factory.createSOAPEnvelope();
> SOAPHeader header = factory.createSOAPHeader();
> SOAPHeaderBlock block = factory.createSOAPHeaderBlock(
>         SOAPHeaderConstants.ELEM_QOSP_HEADER_BLOCK, omNs);
> OMElement type = factory.createOMElement(
>                 SOAPHeaderConstants.ELEM_MESSAGE_TYPE, omNs);
>
> type.setText(MessageType.UPLOAD.value());
> block.addChild(type);
> header.addChild(block);
>
> SOAPBody body = factory.createSOAPBody();
> OMElement method = factory.createOMElement(SOAPUtils.UPLOAD_SERVICE,
> omNs);
>
> OMElement name = factory.createOMElement(
>         SOAPUtils.UPLOAD_SERVICE_FILE_NAME, omNs);
> name.setText(this.fileName);
>
> method.addChild(name);
> body.addChild(method);
> env.addChild(header);
> env.addChild(body);
>
>
> Michele
>
>
>
>
> On 9 May 2007, at 22:26, Daniel Herbison wrote:
>
> >
> > I'm trying to add the SOAP header, described in comment in code
> > below, to a
> > RPC call to a service.  First of all I really do not know if the
> > code to
> > create the header is correct, i think it is in the ball park(?)
> > But I get a
> > run time error of:
> >
> > Exception in thread "main" java.lang.ClassCastException:
> > org.apache.axiom.om.impl.OMNamespaceImpl
> >         at
> > org.apache.axiom.soap.impl.dom.SOAPHeaderBlockImpl.<init>
> > (SOAPHeaderBlockImpl.java:54)
> >         at
> > org.apache.axiom.soap.impl.dom.soap12.SOAP12HeaderBlockImpl.<init>
> > (SOAP12HeaderBlockImpl.java:45)
> >         at rpcAxSys.main(Unknown Source)
> >
> > the line causing the run time error is marked below, why is this
> > doing this?
> > Also, is the header creation correct?
> >
> > code------------------
> > RPCServiceClient serviceClient = new RPCServiceClient();
> > Options options = serviceClient.getOptions();
> > EndpointReference targetEPR = new
> > EndpointReference("https://xyz/Authorize/Service.asmx");
> > options.setTo(targetEPR);
> >
> > /* header build
> >  <soap:Header>
> >   <BasicCredentials xmlns="beta">
> >    <serviceId>string1</serviceId>
> >    <serviceKey>string2</serviceKey>
> >   </BasicCredentials>
> >  </soap:Header>
> >  */
> > OMFactory fac = OMAbstractFactory.getOMFactory();
> > OMNamespace omNs = fac.createOMNamespace("beta", "xmlns");
> >
> > SOAPFactory soapFactory = new SOAP12Factory();
> > SOAPHeaderBlock soapHeaderBlock = new
> > SOAP12HeaderBlockImpl("Security",omNs,soapFactory);
> > soapHeaderBlock.setMustUnderstand(true);
> >
> > OMElement basicCredentials = fac.createOMElement
> > ("BasicCredentials", omNs);
> >
> > OMElement serviceId = fac.createOMElement("serviceId", omNs);
> > OMText serviceIdText = fac.createOMText(serviceId, agentID);
> > serviceId.addChild(serviceIdText);
> >
> > OMElement serviceKey = fac.createOMElement("serviceKey", omNs);
> > OMText serviceKeyText = fac.createOMText(serviceKey, agentToken);
> > serviceKey.addChild(serviceKeyText);
> >
> > basicCredentials.addChild(serviceId);
> > basicCredentials.addChild(serviceKey);
> >
> > soapHeaderBlock.addChild(basicCredentials);
> >
> > serviceClient.addHeader(soapHeaderBlock);
> > // end header build
> >
> > QName opSetClaim = new QName("beta", "GetClaim" );
> >
> > Object[] opSetParams = new Object[] { agentID, agentToken,
> > requestor };
> > Class[] returnTypes = new Class[] { Object.class };
> >
> > Object[] response = serviceClient.invokeBlocking(opSetClaim,
> > opSetParams,
> > returnTypes);
> >
> > --
> > View this message in context: http://www.nabble.com/Creating-Axis2-
> > SOAP-Header-tf3718396.html#a10403132
> > Sent from the Axis - User mailing list archive at Nabble.com.
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
> > For additional commands, e-mail: axis-user-help@ws.apache.org
> >
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
> For additional commands, e-mail: axis-user-help@ws.apache.org
>
>


-- 
Amila Suriarachchi,
WSO2 Inc.

Re: Creating Axis2 SOAP Header

Posted by Michele Mazzucco <Mi...@ncl.ac.uk>.
Daniel,

I think the way you create the SOAPHeaderBlock is not correct. Can  
you try this way please?

SOAP12Factory factory = (SOAP12Factory)  
OMAbstractFactory.getSOAP12Factory();
OMNamespace omNs = factory.createOMNamespace(
			"http://...",
			"..."
		);
		
SOAPEnvelope env = factory.createSOAPEnvelope();
SOAPHeader header = factory.createSOAPHeader();
SOAPHeaderBlock block = factory.createSOAPHeaderBlock(
	SOAPHeaderConstants.ELEM_QOSP_HEADER_BLOCK, omNs);
OMElement type = factory.createOMElement(
		SOAPHeaderConstants.ELEM_MESSAGE_TYPE, omNs);

type.setText(MessageType.UPLOAD.value());
block.addChild(type);
header.addChild(block);
		
SOAPBody body = factory.createSOAPBody();
OMElement method = factory.createOMElement(SOAPUtils.UPLOAD_SERVICE,  
omNs);
		
OMElement name = factory.createOMElement(
	SOAPUtils.UPLOAD_SERVICE_FILE_NAME, omNs);
name.setText(this.fileName);

method.addChild(name);
body.addChild(method);
env.addChild(header);
env.addChild(body);


Michele




On 9 May 2007, at 22:26, Daniel Herbison wrote:

>
> I'm trying to add the SOAP header, described in comment in code  
> below, to a
> RPC call to a service.  First of all I really do not know if the  
> code to
> create the header is correct, i think it is in the ball park(?)   
> But I get a
> run time error of:
>
> Exception in thread "main" java.lang.ClassCastException:
> org.apache.axiom.om.impl.OMNamespaceImpl
>         at
> org.apache.axiom.soap.impl.dom.SOAPHeaderBlockImpl.<init> 
> (SOAPHeaderBlockImpl.java:54)
>         at
> org.apache.axiom.soap.impl.dom.soap12.SOAP12HeaderBlockImpl.<init> 
> (SOAP12HeaderBlockImpl.java:45)
>         at rpcAxSys.main(Unknown Source)
>
> the line causing the run time error is marked below, why is this  
> doing this?
> Also, is the header creation correct?
>
> code------------------
> RPCServiceClient serviceClient = new RPCServiceClient();
> Options options = serviceClient.getOptions();
> EndpointReference targetEPR = new
> EndpointReference("https://xyz/Authorize/Service.asmx");
> options.setTo(targetEPR);
>
> /* header build
>  <soap:Header>
>   <BasicCredentials xmlns="beta">
>    <serviceId>string1</serviceId>
>    <serviceKey>string2</serviceKey>
>   </BasicCredentials>
>  </soap:Header>
>  */
> OMFactory fac = OMAbstractFactory.getOMFactory();
> OMNamespace omNs = fac.createOMNamespace("beta", "xmlns");
>
> SOAPFactory soapFactory = new SOAP12Factory();
> SOAPHeaderBlock soapHeaderBlock = new
> SOAP12HeaderBlockImpl("Security",omNs,soapFactory);
> soapHeaderBlock.setMustUnderstand(true);
>
> OMElement basicCredentials = fac.createOMElement 
> ("BasicCredentials", omNs);
>
> OMElement serviceId = fac.createOMElement("serviceId", omNs);
> OMText serviceIdText = fac.createOMText(serviceId, agentID);
> serviceId.addChild(serviceIdText);
>
> OMElement serviceKey = fac.createOMElement("serviceKey", omNs);
> OMText serviceKeyText = fac.createOMText(serviceKey, agentToken);
> serviceKey.addChild(serviceKeyText);
>
> basicCredentials.addChild(serviceId);
> basicCredentials.addChild(serviceKey);
>
> soapHeaderBlock.addChild(basicCredentials);
>
> serviceClient.addHeader(soapHeaderBlock);
> // end header build
>
> QName opSetClaim = new QName("beta", "GetClaim" );
>
> Object[] opSetParams = new Object[] { agentID, agentToken,  
> requestor };
> Class[] returnTypes = new Class[] { Object.class };
>
> Object[] response = serviceClient.invokeBlocking(opSetClaim,  
> opSetParams,
> returnTypes);
>
> -- 
> View this message in context: http://www.nabble.com/Creating-Axis2- 
> SOAP-Header-tf3718396.html#a10403132
> Sent from the Axis - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
> For additional commands, e-mail: axis-user-help@ws.apache.org
>


---------------------------------------------------------------------
To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-user-help@ws.apache.org