Exemple #1
0
  protected SOAPElement findChild(NameImpl name) {
    Iterator eachChild = getChildElementNodes();
    while (eachChild.hasNext()) {
      SOAPElement child = (SOAPElement) eachChild.next();
      if (child.getElementName().equals(name)) {
        return child;
      }
    }

    return null;
  }
Exemple #2
0
  public SOAPElement addChildElement(SOAPElement element) throws SOAPException {

    // check if Element falls in SOAP 1.1 or 1.2 namespace.
    String elementURI = element.getElementName().getURI();
    String localName = element.getLocalName();

    if ((SOAPConstants.URI_NS_SOAP_ENVELOPE).equals(elementURI)
        || (SOAPConstants.URI_NS_SOAP_1_2_ENVELOPE).equals(elementURI)) {

      if ("Envelope".equalsIgnoreCase(localName)
          || "Header".equalsIgnoreCase(localName)
          || "Body".equalsIgnoreCase(localName)) {
        log.severe("SAAJ0103.impl.cannot.add.fragements");
        throw new SOAPExceptionImpl(
            "Cannot add fragments which contain elements " + "which are in the SOAP namespace");
      }

      if ("Fault".equalsIgnoreCase(localName) && !"Body".equalsIgnoreCase(this.getLocalName())) {
        log.severe("SAAJ0154.impl.adding.fault.to.nonbody");
        throw new SOAPExceptionImpl("Cannot add a SOAPFault as a child of " + this.getLocalName());
      }

      if ("Detail".equalsIgnoreCase(localName) && !"Fault".equalsIgnoreCase(this.getLocalName())) {
        log.severe("SAAJ0155.impl.adding.detail.nonfault");
        throw new SOAPExceptionImpl("Cannot add a Detail as a child of " + this.getLocalName());
      }

      if ("Fault".equalsIgnoreCase(localName)) {
        // if body is not empty throw an exception
        if (!elementURI.equals(this.getElementName().getURI())) {
          log.severe("SAAJ0158.impl.version.mismatch.fault");
          throw new SOAPExceptionImpl(
              "SOAP Version mismatch encountered when trying to add SOAPFault to SOAPBody");
        }
        Iterator it = this.getChildElements();
        if (it.hasNext()) {
          log.severe("SAAJ0156.impl.adding.fault.error");
          throw new SOAPExceptionImpl("Cannot add SOAPFault as a child of a non-Empty SOAPBody");
        }
      }
    }

    // preserve the encodingStyle attr as it may get lost in the import
    String encodingStyle = element.getEncodingStyle();

    ElementImpl importedElement = (ElementImpl) importElement(element);
    addNode(importedElement);

    if (encodingStyle != null) importedElement.setEncodingStyle(encodingStyle);

    return convertToSoapElement(importedElement);
  }
Exemple #3
0
 public void setParentElement(SOAPElement element) throws SOAPException {
   if (element == null) {
     log.severe("SAAJ0106.impl.no.null.to.parent.elem");
     throw new SOAPException("Cannot pass NULL to setParentElement");
   }
   element.addChildElement(this);
   findEncodingStyleAttributeName();
 }
 @Override
 public void process(final SOAPEnvelope envelope, final Authentification provider) {
   final SOAPElement getEventResponse = envelope.getBody().getElement("AuthentificationResponse");
   final MapData data = (MapData) getEventResponse.getFirstData();
   if (!data.getValue("success").getBooleanValue()) {
     AuthentificationManager.INSTANCE.setSessionParams(null);
     return;
   }
   try {
     AuthentificationManager.INSTANCE.setSessionParams(envelope.getHeaderFields());
   } catch (Exception e) {
     AuthentificationAnswer.m_logger.warn(
         (Object)
             "Probl\u00e8me \u00e0 la d\u00e9s\u00e9rialisation des donn\u00e9es d'authentification",
         (Throwable) e);
   }
 }
Exemple #5
0
  protected String getSOAPNamespace() {
    String soapNamespace = null;

    SOAPElement antecedent = this;
    while (antecedent != null) {
      Name antecedentName = antecedent.getElementName();
      String antecedentNamespace = antecedentName.getURI();

      if (NameImpl.SOAP11_NAMESPACE.equals(antecedentNamespace)
          || NameImpl.SOAP12_NAMESPACE.equals(antecedentNamespace)) {

        soapNamespace = antecedentNamespace;
        break;
      }

      antecedent = antecedent.getParentElement();
    }

    return soapNamespace;
  }
Exemple #6
0
  protected SOAPElement circumventBug5034339(SOAPElement element) {

    Name elementName = element.getElementName();
    if (!isNamespaceQualified(elementName)) {
      String prefix = elementName.getPrefix();
      String defaultNamespace = getNamespaceURI(prefix);
      if (defaultNamespace != null) {
        Name newElementName =
            NameImpl.create(elementName.getLocalName(), elementName.getPrefix(), defaultNamespace);
        SOAPElement newElement = createElement(newElementName);
        replaceChild(newElement, element);
        return newElement;
      }
    }
    return element;
  }
  public boolean handleMessage(SOAPMessageContext smc) {
    Boolean outbound = (Boolean) smc.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
    if (outbound) {
      // outbound message

      // *** #8 ***
      // get token from response context
      String propertyValue = (String) smc.get(RESPONSE_PROPERTY);
      System.out.printf("%s received '%s'%n", CLASS_NAME, propertyValue);

      // put token in response SOAP header
      try {
        // get SOAP envelope
        SOAPMessage msg = smc.getMessage();
        SOAPPart sp = msg.getSOAPPart();
        SOAPEnvelope se = sp.getEnvelope();

        // add header
        SOAPHeader sh = se.getHeader();
        if (sh == null) sh = se.addHeader();

        // add header element (name, namespace prefix, namespace)
        Name name = se.createName(RESPONSE_HEADER, "e", RESPONSE_NS);
        SOAPHeaderElement element = sh.addHeaderElement(name);

        // *** #9 ***
        // add header element value
        String newValue = propertyValue + "," + TOKEN;
        element.addTextNode(newValue);

        System.out.printf("%s put token '%s' on response message header%n", CLASS_NAME, TOKEN);

      } catch (SOAPException e) {
        System.out.printf("Failed to add SOAP header because of %s%n", e);
      }

    } else {
      // inbound message

      // get token from request SOAP header
      try {
        // get SOAP envelope header
        SOAPMessage msg = smc.getMessage();
        SOAPPart sp = msg.getSOAPPart();
        SOAPEnvelope se = sp.getEnvelope();
        SOAPHeader sh = se.getHeader();

        // check header
        if (sh == null) {
          System.out.println("Header not found.");
          return true;
        }

        // get Ticket header element
        Name nameTicket = se.createName(REQUEST_TICKET_HEADER, "e", REQUEST_NS);
        Iterator it = sh.getChildElements(nameTicket);
        // check header element
        if (!it.hasNext()) {
          System.out.printf("Header element %s not found.%n", REQUEST_TICKET_HEADER);
          return true;
        }
        SOAPElement elementTicket = (SOAPElement) it.next();

        // *** #4 ***
        // get header element value
        String headerTicketValue = elementTicket.getValue();
        System.out.printf("%s got '%s'%n", CLASS_NAME, headerTicketValue);

        // *** #5 ***
        // put Ticket token in request context
        System.out.printf("%s put token '%s' on request context%n", CLASS_NAME, headerTicketValue);
        smc.put(REQUEST_TICKET_PROPERTY, headerTicketValue);
        // set property scope to application so that server class can access property
        smc.setScope(REQUEST_TICKET_PROPERTY, Scope.APPLICATION);

        // get Author header element
        Name nameAuthor = se.createName(REQUEST_AUTHOR_HEADER, "e", REQUEST_NS);
        Iterator itAuthor = sh.getChildElements(nameAuthor);
        // check header element
        if (!itAuthor.hasNext()) {
          System.out.printf("Header element %s not found.%n", REQUEST_AUTHOR_HEADER);
          return true;
        }
        SOAPElement elementAuthor = (SOAPElement) itAuthor.next();

        // *** #4 ***
        // get Author header element value
        String headerAuthorValue = elementAuthor.getValue();
        System.out.printf("%s got '%s'%n", CLASS_NAME, headerAuthorValue);

        // *** #5 ***
        // put Author token in request context
        System.out.printf("%s put token '%s' on request context%n", CLASS_NAME, headerAuthorValue);
        smc.put(REQUEST_AUTHOR_PROPERTY, headerAuthorValue);
        // set property scope to application so that server class can access property
        smc.setScope(REQUEST_AUTHOR_PROPERTY, Scope.APPLICATION);

        // MAC
        // get MAC header element
        Name nameMac = se.createName(REQUEST_MAC_HEADER, "e", REQUEST_NS);
        Iterator itMac = sh.getChildElements(nameAuthor);
        // check header element
        if (!itMac.hasNext()) {
          System.out.printf("Header element %s not found.%n", REQUEST_MAC_HEADER);
          return true;
        }
        SOAPElement elementMac = (SOAPElement) itMac.next();

        // *** #4 ***
        // get MAC header element value
        String headerMacValue = elementMac.getTextContent();

        System.out.printf("%s got '%s'%n", CLASS_NAME, headerMacValue);

        // *** #5 ***
        // put MAC token in request context
        System.out.printf("%s put token '%s' on request context%n", CLASS_NAME, headerMacValue);
        smc.put(REQUEST_MAC_PROPERTY, headerMacValue);
        // set property scope to application so that server class can access property
        smc.setScope(REQUEST_MAC_PROPERTY, Scope.APPLICATION);

        String bodyValue = se.getBody().getTextContent();
        // *** #5 ***
        // put Body token in request context
        System.out.printf("%s put token '%s' on request context%n", CLASS_NAME, bodyValue);
        smc.put(REQUEST_BODY_PROPERTY, bodyValue);
        // set property scope to application so that server class can access property
        smc.setScope(REQUEST_BODY_PROPERTY, Scope.APPLICATION);

        msg.writeTo(System.out);

      } catch (SOAPException e) {
        System.out.printf("Failed to get SOAP header because of %s%n", e);
      } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }
    }

    return true;
  }