@Override public void onCancel() { view.setCancelEnabled(false); if (actionExecutionFuture != null) { Workbench.Log.ACTION_INVOCATION.info( "Interrupting action execution: " + action.getName() ); actionExecutionFuture.cancel(true); } }
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; }
@Override public String toString() { return "(" + getClass().getSimpleName() + ", Arguments: " + (getArguments() != null ? getArguments().length : "NO ARGS") + ") " + getName(); }
protected Element writeActionRequestElement(Document d, Element bodyElement, ActionRequestMessage message, ActionInvocation actionInvocation) { log.fine("Writing action request element: " + actionInvocation.getAction().getName()); Element actionRequestElement = d.createElementNS( message.getActionNamespace(), "u:" + actionInvocation.getAction().getName() ); bodyElement.appendChild(actionRequestElement); return actionRequestElement; }
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; }
@Override public void failure(ActionInvocation invocation, UpnpResponse operation, String defaultMsg) { if (invocation.getFailure() instanceof ActionCancelledException) { Workbench.Log.ACTION_INVOCATION.info( "Action execution of '" + invocation.getAction().getName() + "' was cancelled, cause: " + invocation.getFailure().getCause().getMessage() ); } else { Workbench.Log.ACTION_INVOCATION.severe(defaultMsg); } }
@Override public void success(final ActionInvocation invocation) { onSuccess(invocation.getOutput()); Workbench.Log.ACTION_INVOCATION.info( "Completed invocation: " + invocation.getAction().getName() ); }
private void generateActionList(Service serviceModel, Document descriptor, Element scpdElement) { Element actionListElement = appendNewElement(descriptor, scpdElement, ELEMENT.actionList); for (Action action : serviceModel.getActions()) { if (!action.getName().equals(QueryStateVariableAction.ACTION_NAME)) generateAction(action, descriptor, actionListElement); } }
public Service(ServiceType serviceType, ServiceId serviceId, Action<S>[] actions, StateVariable<S>[] stateVariables) throws ValidationException { this.serviceType = serviceType; this.serviceId = serviceId; if (actions != null) { for (Action action : actions) { this.actions.put(action.getName(), action); action.setService(this); } } if (stateVariables != null) { for (StateVariable stateVariable : stateVariables) { this.stateVariables.put(stateVariable.getName(), stateVariable); stateVariable.setService(this); } } }
protected void readBodyResponse(XmlPullParser xpp, ActionInvocation actionInvocation) throws Exception { // We're in the "Body" tag int event; do { event = xpp.next(); if (event == XmlPullParser.START_TAG) { if (xpp.getName().equals("Fault")) { ActionException e = readFaultElement(xpp); actionInvocation.setFailure(e); return; } else if (xpp.getName().equals(actionInvocation.getAction().getName() + "Response")) { readActionOutputArguments(xpp, actionInvocation); return; } } } while (event != XmlPullParser.END_DOCUMENT && (event != XmlPullParser.END_TAG || !xpp.getName().equals("Body"))); throw new ActionException( ErrorCode.ACTION_FAILED, String.format("Action SOAP response do not contain %s element", actionInvocation.getAction().getName() + "Response" ) ); }
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() ); }
protected void readBodyRequest(XmlPullParser xpp, ActionRequestMessage requestMessage, ActionInvocation actionInvocation) throws Exception { XmlPullParserUtils.searchTag(xpp, actionInvocation.getAction().getName()); readActionInputArguments(xpp, actionInvocation); }
setTitle("Invoking Action: " + action.getName()); setPreferredSize(new Dimension(450, (action.getArguments().length *40) + 120)); pack();
@Override public void onInvoke() { ActionInvocation actionInvocation = new ActionInvocation(action, view.getInputValues()); // Starts background thread Workbench.Log.ACTION_INVOCATION.info("Executing action: " + action.getName()); ActionCallback actionCallback = new ControlActionCallback(actionInvocation) { @Override protected void onSuccess(final ActionArgumentValue[] values) { SwingUtilities.invokeLater(new Runnable() { public void run() { view.setCancelEnabled(false); view.setOutputValues(values); } }); } @Override public void failure(ActionInvocation invocation, UpnpResponse operation, String defaultMsg) { SwingUtilities.invokeLater(new Runnable() { public void run() { view.setCancelEnabled(false); } }); super.failure(invocation, operation, defaultMsg); } }; actionExecutionFuture = controlPoint.execute(actionCallback); view.setCancelEnabled(true); }
public List<ValidationError> validate() { List<ValidationError> errors = new ArrayList<>(); if (getName() == null || getName().length() == 0) { errors.add(new ValidationError( getClass(), "Action without name of: " + getService() )); } else if (!ModelUtil.isValidUDAName(getName())) { log.warning("UPnP specification violation of: " + getService().getDevice()); log.warning("Invalid action name: " + this); if (retValueArgument != null) { log.warning("UPnP specification violation of: " + getService().getDevice()); log.warning("Only one argument of action '" + getName() + "' can be <retval/>"); if (a.getDirection() == ActionArgument.Direction.OUT) { log.warning("UPnP specification violation of: " + getService().getDevice()); log.warning("Argument '" + retValueArgument.getName() + "' of action '" + getName() + "' is <retval/> but not the first OUT argument");
public Action<S> deepCopy() { ActionArgument<S>[] actionArgumentsDupe = new ActionArgument[getArguments().length]; for (int i = 0; i < getArguments().length; i++) { ActionArgument arg = getArguments()[i]; actionArgumentsDupe[i] = arg.deepCopy(); } return new Action<>( getName(), actionArgumentsDupe ); }
private void generateAction(Action action, Document descriptor, Element actionListElement) { Element actionElement = appendNewElement(descriptor, actionListElement, ELEMENT.action); appendNewElementIfNotNull(descriptor, actionElement, ELEMENT.name, action.getName()); if (action.hasArguments()) { Element argumentListElement = appendNewElement(descriptor, actionElement, ELEMENT.argumentList); for (ActionArgument actionArgument : action.getArguments()) { generateActionArgument(actionArgument, descriptor, argumentListElement); } } }
protected IncomingActionResponseMessage invokeRemote(OutgoingActionRequestMessage requestMessage) throws RouterException { Device device = actionInvocation.getAction().getService().getDevice(); log.fine("Sending outgoing action call '" + actionInvocation.getAction().getName() + "' to remote service of: " + device); IncomingActionResponseMessage responseMessage = null; try {