/** * Test T12 - unknown header, with MustUnderstand true * * @throws Exception */ public void testT12() throws Exception { Call call = new Call(DOC_ENDPOINT); call.setOperationStyle(Style.DOCUMENT); call.setSOAPVersion(SOAPConstants.SOAP12_CONSTANTS); SOAPEnvelope reqEnv = new SOAPEnvelope(SOAPConstants.SOAP12_CONSTANTS); SOAPHeaderElement header = new SOAPHeaderElement(TEST_NS, "Unknown"); header.setObjectValue("test header"); header.setMustUnderstand(true); reqEnv.addHeader(header); try { call.invoke(reqEnv); } catch (AxisFault fault) { assertEquals(Constants.FAULT_SOAP12_MUSTUNDERSTAND, fault.getFaultCode()); ArrayList headers = fault.getHeaders(); // If there is a NotUnderstood header, check it for (Iterator i = headers.iterator(); i.hasNext(); ) { SOAPHeaderElement h = (SOAPHeaderElement) i.next(); if (h.getQName().equals(Constants.QNAME_NOTUNDERSTOOD)) { // TODO : check qname attribute } } return; } fail("Didn't receive expected fault!"); }
/** * Several tests (T1, etc) use the same functionality, send an empty body with the "echoOk" header * using various roles, and check the return in the "responseOk" header. * * @throws Exception */ protected void testEchoOkHeaderWithEmptyBody(String role) throws Exception { test.wsdl.soap12.assertion.Soap12TestDocBindingStub binding; try { binding = (test.wsdl.soap12.assertion.Soap12TestDocBindingStub) new test.wsdl.soap12.assertion.WhiteMesaSoap12TestSvcLocator().getSoap12TestDocPort(); } catch (javax.xml.rpc.ServiceException jre) { if (jre.getLinkedCause() != null) jre.getLinkedCause().printStackTrace(); throw new junit.framework.AssertionFailedError("JAX-RPC ServiceException caught: " + jre); } assertNotNull("binding is null", binding); // Time out after a minute binding.setTimeout(60000); // Test operation SOAPHeaderElement header = new SOAPHeaderElement(TEST_NS, "echoOk"); if (role != null) header.setRole(role); header.setObjectValue("this is a test"); binding.setHeader(header); binding.emptyBody(); // Get the response header SOAPHeaderElement respHeader = binding.getHeader(TEST_NS, "responseOk"); assertNotNull("Missing response header", respHeader); assertEquals("this is a test", respHeader.getValue()); }
/** * Test T5 - echoOk header to unrecognized role (should be ignored) * * @throws Exception */ public void testT5() throws Exception { Call call = new Call(DOC_ENDPOINT); call.setOperationStyle(Style.DOCUMENT); call.setSOAPVersion(SOAPConstants.SOAP12_CONSTANTS); SOAPEnvelope reqEnv = new SOAPEnvelope(SOAPConstants.SOAP12_CONSTANTS); SOAPHeaderElement header = new SOAPHeaderElement(TEST_NS, "echoOk"); header.setRole(ROLE_B); header.setObjectValue("test header"); reqEnv.addHeader(header); SOAPEnvelope respEnv = call.invoke(reqEnv); assertTrue("Got unexpected header!", respEnv.getHeaders().isEmpty()); }
/** @see SoapClientHandler#setHeader(Object, String, String, Object) */ @Override public void setHeader(Stub soapClient, String namespace, String headerName, Object headerValue) { try { QName qName = new QName(namespace, headerName); SOAPHeaderElement soapHeaderElement = new SOAPHeaderElement(qName); soapHeaderElement.setObjectValue(headerValue); soapHeaderElement.setActor(null); soapClient.setHeader(soapHeaderElement); } catch (SOAPException e) { throw new ServiceException("Could not set header.", e); } }
/** * Test T6 - echoOk header targeted at endpoint via intermediary * * @throws Exception */ public void testT6() throws Exception { Call call = new Call(INTERMEDIARY_ENDPOINT); call.setOperationStyle(Style.DOCUMENT); call.setSOAPVersion(SOAPConstants.SOAP12_CONSTANTS); SOAPEnvelope reqEnv = new SOAPEnvelope(SOAPConstants.SOAP12_CONSTANTS); SOAPHeaderElement header = new SOAPHeaderElement(TEST_NS, "echoOk"); header.setRole(ROLE_C); header.setObjectValue("test header"); reqEnv.addHeader(header); SOAPEnvelope respEnv = call.invoke(reqEnv); SOAPHeaderElement respHeader = respEnv.getHeaderByName(TEST_NS, "responseOk"); assertNotNull(respHeader); assertEquals("test header", respHeader.getValue()); }