/**
  * 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!");
 }
  public void quickLogon(String namespace, String uid, String pwd) {

    try {
      StringBuffer credentialXML = new StringBuffer();

      credentialXML.append("<credential>");
      credentialXML.append("<namespace>").append(namespace).append("</namespace>");
      credentialXML.append("<username>").append(uid).append("</username>");
      credentialXML.append("<password>").append(pwd).append("</password>");
      credentialXML.append("</credential>");

      String encodedCredentials = credentialXML.toString();
      XmlEncodedXML xmlCredentials = new XmlEncodedXML();
      xmlCredentials.set_value(encodedCredentials);

      this.cmService.logon(xmlCredentials, null);

      SOAPHeaderElement temp =
          ((Stub) this.cmService)
              .getResponseHeader("http://developer.cognos.com/schemas/bibus/3/", "biBusHeader");
      cmBiBusHeader =
          (BiBusHeader)
              temp.getValueAsType(
                  new QName("http://developer.cognos.com/schemas/bibus/3/", "biBusHeader"));
      ((Stub) this.cmService)
          .setHeader("http://developer.cognos.com/schemas/bibus/3/", "biBusHeader", cmBiBusHeader);
      ((Stub) this.dispatcher)
          .setHeader("http://developer.cognos.com/schemas/bibus/3/", "biBusHeader", cmBiBusHeader);
      banonymous = false;
    } catch (Exception e) {
      System.out.println("Warning: Named authentication failed. Will try as anonymous.");
      banonymous = true;
    }
  }
  /**
   * 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());
  }
 /**
  * Returns a SOAP header from the given SOAP client, if it exists.
  *
  * @param soapClient the SOAP client to check for the given header
  * @param headerName the name of the header being looked for
  * @return the header element, if it exists
  */
 @Override
 public Object getHeader(Stub soapClient, String headerName) {
   SOAPHeaderElement[] soapHeaders = soapClient.getHeaders();
   for (SOAPHeaderElement soapHeader : soapHeaders) {
     if (soapHeader.getName().equals(headerName)) {
       return soapHeader;
     }
   }
   return null;
 }
 /**
  * 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());
 }