protected Element writeActionResponseElement(
      Document d,
      Element bodyElement,
      ActionResponseMessage message,
      ActionInvocation actionInvocation) {

    log.fine("Writing action response element: " + actionInvocation.getAction().getName());
    Element actionResponseElement =
        d.createElementNS(
            message.getActionNamespace(),
            "u:" + actionInvocation.getAction().getName() + "Response");
    bodyElement.appendChild(actionResponseElement);

    return actionResponseElement;
  }
 public void readActionInputArguments(
     Element actionRequestElement, ActionInvocation actionInvocation) throws ActionException {
   actionInvocation.setInput(
       readArgumentValues(
           actionRequestElement.getChildNodes(),
           actionInvocation.getAction().getInputArguments()));
 }
  protected Element readActionRequestElement(
      Element bodyElement, ActionRequestMessage message, ActionInvocation actionInvocation) {
    NodeList bodyChildren = bodyElement.getChildNodes();

    log.fine(
        "Looking for action request element matching namespace:" + message.getActionNamespace());

    for (int i = 0; i < bodyChildren.getLength(); i++) {
      Node bodyChild = bodyChildren.item(i);

      if (bodyChild.getNodeType() != Node.ELEMENT_NODE) continue;

      String unprefixedName = getUnprefixedNodeName(bodyChild);
      if (unprefixedName.equals(actionInvocation.getAction().getName())) {
        if (bodyChild.getNamespaceURI() == null
            || !bodyChild.getNamespaceURI().equals(message.getActionNamespace()))
          throw new UnsupportedDataException(
              "Illegal or missing namespace on action request element: " + bodyChild);
        log.fine("Reading action request element: " + unprefixedName);
        return (Element) bodyChild;
      }
    }
    throw new UnsupportedDataException(
        "Could not read action request element matching namespace: "
            + message.getActionNamespace());
  }
Beispiel #4
0
  @Test(dataProvider = "devices")
  public void invokeActions(LocalDevice device) {
    LocalService svc = device.getServices()[0];

    ActionInvocation setColor = new ActionInvocation(svc.getAction("SetColor"));
    setColor.setInput("In", MyServiceWithEnum.Color.Blue);
    svc.getExecutor(setColor.getAction()).execute(setColor);
    assertEquals(setColor.getFailure(), null);
    assertEquals(setColor.getOutput().length, 0);

    ActionInvocation getColor = new ActionInvocation(svc.getAction("GetColor"));
    svc.getExecutor(getColor.getAction()).execute(getColor);
    assertEquals(getColor.getFailure(), null);
    assertEquals(getColor.getOutput().length, 1);
    assertEquals(getColor.getOutput()[0].toString(), MyServiceWithEnum.Color.Blue.name());
  }
  protected void readActionOutputArguments(
      Element actionResponseElement, ActionInvocation actionInvocation) throws ActionException {

    actionInvocation.setOutput(
        readArgumentValues(
            actionResponseElement.getChildNodes(),
            actionInvocation.getAction().getOutputArguments()));
  }
  protected void writeActionOutputArguments(
      Document d, Element actionResponseElement, ActionInvocation actionInvocation) {

    for (ActionArgument argument : actionInvocation.getAction().getOutputArguments()) {
      log.fine("Writing action output argument: " + argument.getName());
      String value =
          actionInvocation.getOutput(argument) != null
              ? actionInvocation.getOutput(argument).toString()
              : "";
      XMLUtil.appendNewElement(d, actionResponseElement, argument.getName(), value);
    }
  }
  protected Element readActionResponseElement(
      Element bodyElement, ActionInvocation actionInvocation) {
    NodeList bodyChildren = bodyElement.getChildNodes();

    for (int i = 0; i < bodyChildren.getLength(); i++) {
      Node bodyChild = bodyChildren.item(i);

      if (bodyChild.getNodeType() != Node.ELEMENT_NODE) continue;

      if (getUnprefixedNodeName(bodyChild)
          .equals(actionInvocation.getAction().getName() + "Response")) {
        log.fine("Reading action response element: " + getUnprefixedNodeName(bodyChild));
        return (Element) bodyChild;
      }
    }
    log.fine("Could not read action response element");
    return null;
  }