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: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > > > -- 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: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
