org.fourthline.cling.model.types.ErrorCode Java Examples

The following examples show how to use org.fourthline.cling.model.types.ErrorCode. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PullSOAPActionProcessorImpl.java    From TVRemoteIME with GNU General Public License v2.0 6 votes vote down vote up
protected ActionArgumentValue[] readArgumentValues(XmlPullParser xpp, ActionArgument[] args) throws Exception {
    // We're in the <ActionName>Response tag
    Map<String, String> matches = getMatchingNodes(xpp, args);

    ActionArgumentValue[] values = new ActionArgumentValue[args.length];

    for (int i = 0; i < args.length; i++) {

        ActionArgument arg = args[i];
        String value = findActionArgumentValue(matches, arg);
        if (value == null) {
            throw new ActionException(
                ErrorCode.ARGUMENT_VALUE_INVALID,
                "Could not find argument '" + arg.getName() + "' node");
        }

        log.fine("Reading action argument: " + arg.getName());
        values[i] = createValue(arg, value);
    }
    return values;
}
 
Example #2
Source File: QueryStateVariableExecutor.java    From DroidDLNA with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected void execute(ActionInvocation<LocalService> actionInvocation, Object serviceImpl) throws Exception {

    // Querying a state variable doesn't mean an actual "action" method on this instance gets invoked
    if (actionInvocation.getAction() instanceof QueryStateVariableAction) {
        if (!actionInvocation.getAction().getService().isSupportsQueryStateVariables()) {
            actionInvocation.setFailure(
                    new ActionException(ErrorCode.INVALID_ACTION, "This service does not support querying state variables")
            );
        } else {
            executeQueryStateVariable(actionInvocation, serviceImpl);
        }
    } else {
        throw new IllegalStateException(
                "This class can only execute QueryStateVariableAction's, not: " + actionInvocation.getAction()
        );
    }
}
 
Example #3
Source File: GetProtocolInfo.java    From DroidDLNA with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void success(ActionInvocation invocation) {
	try {
		ActionArgumentValue sink = invocation.getOutput("Sink");
		ActionArgumentValue source = invocation.getOutput("Source");

		received(invocation,
				sink != null ? new ProtocolInfos(sink.toString()) : null,
				source != null ? new ProtocolInfos(source.toString())
						: null);

	} catch (Exception ex) {
		invocation.setFailure(new ActionException(ErrorCode.ACTION_FAILED,
				"Can't parse ProtocolInfo response: " + ex, ex));
		failure(invocation, null);
	}
}
 
Example #4
Source File: GetCurrentConnectionInfo.java    From DroidDLNA with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void success(ActionInvocation invocation) {

    try {
        ConnectionInfo info = new ConnectionInfo(
                (Integer)invocation.getInput("ConnectionID").getValue(),
                (Integer)invocation.getOutput("RcsID").getValue(),
                (Integer)invocation.getOutput("AVTransportID").getValue(),
                new ProtocolInfo(invocation.getOutput("ProtocolInfo").toString()),
                new ServiceReference(invocation.getOutput("PeerConnectionManager").toString()),
                (Integer)invocation.getOutput("PeerConnectionID").getValue(),
                ConnectionInfo.Direction.valueOf(invocation.getOutput("Direction").toString()),
                ConnectionInfo.Status.valueOf(invocation.getOutput("Status").toString())
        );

        received(invocation, info);

    } catch (Exception ex) {
        invocation.setFailure(
                new ActionException(ErrorCode.ACTION_FAILED, "Can't parse ConnectionInfo response: " + ex, ex)
        );
        failure(invocation, null);
    }
}
 
Example #5
Source File: GetStatusInfo.java    From TVRemoteIME with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void success(ActionInvocation invocation) {

    try {
        Connection.Status status =
                Connection.Status.valueOf(invocation.getOutput("NewConnectionStatus").getValue().toString());

        Connection.Error lastError =
                Connection.Error.valueOf(invocation.getOutput("NewLastConnectionError").getValue().toString());

        success(new Connection.StatusInfo(status, (UnsignedIntegerFourBytes) invocation.getOutput("NewUptime").getValue(), lastError));

    } catch (Exception ex) {
        invocation.setFailure(
                new ActionException(
                        ErrorCode.ARGUMENT_VALUE_INVALID,
                        "Invalid status or last error string: " + ex,
                        ex
                )
        );
        failure(invocation, null);
    }
}
 
Example #6
Source File: IncomingActionRequestMessage.java    From DroidDLNA with GNU General Public License v3.0 6 votes vote down vote up
public IncomingActionRequestMessage(StreamRequestMessage source,
                                    LocalService service) throws ActionException {
    super(source);

    SoapActionHeader soapActionHeader = getHeaders().getFirstHeader(UpnpHeader.Type.SOAPACTION, SoapActionHeader.class);
    if (soapActionHeader == null) {
        throw new ActionException(ErrorCode.INVALID_ACTION, "Missing SOAP action header");
    }

    SoapActionType actionType = soapActionHeader.getValue();

    this.action = service.getAction(actionType.getActionName());
    if (this.action == null) {
        throw new ActionException(ErrorCode.INVALID_ACTION, "Service doesn't implement action: " + actionType.getActionName());
    }

    if (!QueryStateVariableAction.ACTION_NAME.equals(actionType.getActionName())) {
        if (!service.getServiceType().implementsVersion(actionType.getServiceType())) {
            throw new ActionException(ErrorCode.INVALID_ACTION, "Service doesn't support the requested service version");
        }
    }

    this.actionNamespace = actionType.getTypeString();
}
 
Example #7
Source File: GetCurrentConnectionInfo.java    From TVRemoteIME with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void success(ActionInvocation invocation) {

    try {
        ConnectionInfo info = new ConnectionInfo(
                (Integer)invocation.getInput("ConnectionID").getValue(),
                (Integer)invocation.getOutput("RcsID").getValue(),
                (Integer)invocation.getOutput("AVTransportID").getValue(),
                new ProtocolInfo(invocation.getOutput("ProtocolInfo").toString()),
                new ServiceReference(invocation.getOutput("PeerConnectionManager").toString()),
                (Integer)invocation.getOutput("PeerConnectionID").getValue(),
                ConnectionInfo.Direction.valueOf(invocation.getOutput("Direction").toString()),
                ConnectionInfo.Status.valueOf(invocation.getOutput("Status").toString())
        );

        received(invocation, info);

    } catch (Exception ex) {
        invocation.setFailure(
                new ActionException(ErrorCode.ACTION_FAILED, "Can't parse ConnectionInfo response: " + ex, ex)
        );
        failure(invocation, null);
    }
}
 
Example #8
Source File: GetProtocolInfo.java    From TVRemoteIME with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void success(ActionInvocation invocation) {
	try {
		ActionArgumentValue sink = invocation.getOutput("Sink");
		ActionArgumentValue source = invocation.getOutput("Source");

		received(invocation,
				sink != null ? new ProtocolInfos(sink.toString()) : null,
				source != null ? new ProtocolInfos(source.toString())
						: null);

	} catch (Exception ex) {
		invocation.setFailure(new ActionException(ErrorCode.ACTION_FAILED,
				"Can't parse ProtocolInfo response: " + ex, ex));
		failure(invocation, null);
	}
}
 
Example #9
Source File: GetStatusInfo.java    From DroidDLNA with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void success(ActionInvocation invocation) {

    try {
        Connection.Status status =
                Connection.Status.valueOf(invocation.getOutput("NewConnectionStatus").getValue().toString());

        Connection.Error lastError =
                Connection.Error.valueOf(invocation.getOutput("NewLastConnectionError").getValue().toString());

        success(new Connection.StatusInfo(status, (UnsignedIntegerFourBytes) invocation.getOutput("NewUptime").getValue(), lastError));

    } catch (Exception ex) {
        invocation.setFailure(
                new ActionException(
                        ErrorCode.ARGUMENT_VALUE_INVALID,
                        "Invalid status or last error string: " + ex,
                        ex
                )
        );
        failure(invocation, null);
    }
}
 
Example #10
Source File: PullSOAPActionProcessorImpl.java    From DroidDLNA with GNU General Public License v3.0 6 votes vote down vote up
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"
        )
    );
}
 
Example #11
Source File: PullSOAPActionProcessorImpl.java    From DroidDLNA with GNU General Public License v3.0 6 votes vote down vote up
protected ActionArgumentValue[] readArgumentValues(XmlPullParser xpp, ActionArgument[] args) throws Exception {
    // We're in the <ActionName>Response tag
    Map<String, String> matches = getMatchingNodes(xpp, args);

    ActionArgumentValue[] values = new ActionArgumentValue[args.length];

    for (int i = 0; i < args.length; i++) {

        ActionArgument arg = args[i];
        String value = findActionArgumentValue(matches, arg);
        if (value == null) {
            throw new ActionException(
                ErrorCode.ARGUMENT_VALUE_INVALID,
                "Could not find argument '" + arg.getName() + "' node");
        }

        log.fine("Reading action argument: " + arg.getName());
        values[i] = createValue(arg, value);
    }
    return values;
}
 
Example #12
Source File: PullSOAPActionProcessorImpl.java    From TVRemoteIME with GNU General Public License v2.0 6 votes vote down vote up
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"
        )
    );
}
 
Example #13
Source File: SOAPActionProcessorImpl.java    From DroidDLNA with GNU General Public License v3.0 6 votes vote down vote up
/**
 * The UPnP spec says that action arguments must be in the order as declared
 * by the service. This method however is lenient, the action argument nodes
 * in the XML can be in any order, as long as they are all there everything
 * is OK.
 */
protected ActionArgumentValue[] readArgumentValues(NodeList nodeList, ActionArgument[] args)
        throws ActionException {

    List<Node> nodes = getMatchingNodes(nodeList, args);

    ActionArgumentValue[] values = new ActionArgumentValue[args.length];

    for (int i = 0; i < args.length; i++) {
    	
        ActionArgument arg = args[i];
        Node node = findActionArgumentNode(nodes, arg);
        if(node == null) {
            throw new ActionException(
                    ErrorCode.ARGUMENT_VALUE_INVALID,
                    "Could not find argument '" + arg.getName() + "' node");
        }
        log.fine("Reading action argument: " + arg.getName());
        String value = XMLUtil.getTextContent(node);
        values[i] = createValue(arg, value);
    }
    return values;
}
 
Example #14
Source File: SOAPActionProcessorImpl.java    From TVRemoteIME with GNU General Public License v2.0 6 votes vote down vote up
/**
 * The UPnP spec says that action arguments must be in the order as declared
 * by the service. This method however is lenient, the action argument nodes
 * in the XML can be in any order, as long as they are all there everything
 * is OK.
 */
protected ActionArgumentValue[] readArgumentValues(NodeList nodeList, ActionArgument[] args)
        throws ActionException {

    List<Node> nodes = getMatchingNodes(nodeList, args);

    ActionArgumentValue[] values = new ActionArgumentValue[args.length];

    for (int i = 0; i < args.length; i++) {
    	
        ActionArgument arg = args[i];
        Node node = findActionArgumentNode(nodes, arg);
        if(node == null) {
            throw new ActionException(
                    ErrorCode.ARGUMENT_VALUE_INVALID,
                    "Could not find argument '" + arg.getName() + "' node");
        }
        log.fine("Reading action argument: " + arg.getName());
        String value = XMLUtil.getTextContent(node);
        values[i] = createValue(arg, value);
    }
    return values;
}
 
Example #15
Source File: QueryStateVariableExecutor.java    From TVRemoteIME with GNU General Public License v2.0 6 votes vote down vote up
@Override
protected void execute(ActionInvocation<LocalService> actionInvocation, Object serviceImpl) throws Exception {

    // Querying a state variable doesn't mean an actual "action" method on this instance gets invoked
    if (actionInvocation.getAction() instanceof QueryStateVariableAction) {
        if (!actionInvocation.getAction().getService().isSupportsQueryStateVariables()) {
            actionInvocation.setFailure(
                    new ActionException(ErrorCode.INVALID_ACTION, "This service does not support querying state variables")
            );
        } else {
            executeQueryStateVariable(actionInvocation, serviceImpl);
        }
    } else {
        throw new IllegalStateException(
                "This class can only execute QueryStateVariableAction's, not: " + actionInvocation.getAction()
        );
    }
}
 
Example #16
Source File: IncomingActionRequestMessage.java    From TVRemoteIME with GNU General Public License v2.0 6 votes vote down vote up
public IncomingActionRequestMessage(StreamRequestMessage source,
                                    LocalService service) throws ActionException {
    super(source);

    SoapActionHeader soapActionHeader = getHeaders().getFirstHeader(UpnpHeader.Type.SOAPACTION, SoapActionHeader.class);
    if (soapActionHeader == null) {
        throw new ActionException(ErrorCode.INVALID_ACTION, "Missing SOAP action header");
    }

    SoapActionType actionType = soapActionHeader.getValue();

    this.action = service.getAction(actionType.getActionName());
    if (this.action == null) {
        throw new ActionException(ErrorCode.INVALID_ACTION, "Service doesn't implement action: " + actionType.getActionName());
    }

    if (!QueryStateVariableAction.ACTION_NAME.equals(actionType.getActionName())) {
        if (!service.getServiceType().implementsVersion(actionType.getServiceType())) {
            throw new ActionException(ErrorCode.INVALID_ACTION, "Service doesn't support the requested service version");
        }
    }

    this.actionNamespace = actionType.getTypeString();
}
 
Example #17
Source File: AbstractPeeringConnectionManagerService.java    From DroidDLNA with GNU General Public License v3.0 5 votes vote down vote up
@UpnpAction(out = {
        @UpnpOutputArgument(name = "ConnectionID", stateVariable = "A_ARG_TYPE_ConnectionID", getterName = "getConnectionID"),
        @UpnpOutputArgument(name = "AVTransportID", stateVariable = "A_ARG_TYPE_AVTransportID", getterName = "getAvTransportID"),
        @UpnpOutputArgument(name = "RcsID", stateVariable = "A_ARG_TYPE_RcsID", getterName = "getRcsID")
})
synchronized public ConnectionInfo prepareForConnection(
        @UpnpInputArgument(name = "RemoteProtocolInfo", stateVariable = "A_ARG_TYPE_ProtocolInfo") ProtocolInfo remoteProtocolInfo,
        @UpnpInputArgument(name = "PeerConnectionManager", stateVariable = "A_ARG_TYPE_ConnectionManager") ServiceReference peerConnectionManager,
        @UpnpInputArgument(name = "PeerConnectionID", stateVariable = "A_ARG_TYPE_ConnectionID") int peerConnectionId,
        @UpnpInputArgument(name = "Direction", stateVariable = "A_ARG_TYPE_Direction") String direction)
        throws ActionException {

    int connectionId = getNewConnectionId();

    ConnectionInfo.Direction dir;
    try {
        dir = ConnectionInfo.Direction.valueOf(direction);
    } catch (Exception ex) {
        throw new ConnectionManagerException(ErrorCode.ARGUMENT_VALUE_INVALID, "Unsupported direction: " + direction);
    }

    log.fine("Preparing for connection with local new ID " + connectionId + " and peer connection ID: " + peerConnectionId);

    ConnectionInfo newConnectionInfo = createConnection(
            connectionId,
            peerConnectionId,
            peerConnectionManager,
            dir,
            remoteProtocolInfo
    );

    storeConnection(newConnectionInfo);

    return newConnectionInfo;
}
 
Example #18
Source File: SendingAction.java    From TVRemoteIME with GNU General Public License v2.0 5 votes vote down vote up
protected void handleResponseFailure(IncomingActionResponseMessage responseMsg) throws ActionException {

        try {
            log.fine("Received response with Internal Server Error, reading SOAP failure message");
            getUpnpService().getConfiguration().getSoapActionProcessor().readBody(responseMsg, actionInvocation);
        } catch (UnsupportedDataException ex) {
            log.fine("Error reading SOAP body: " + ex);
            log.log(Level.FINE, "Exception root cause: ", Exceptions.unwrap(ex));
            throw new ActionException(
                ErrorCode.ACTION_FAILED,
                "Error reading SOAP response failure message. " + ex.getMessage(),
                false
            );
        }
    }
 
Example #19
Source File: AbstractContentDirectoryService.java    From DroidDLNA with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Override this method to implement searching of your content.
 * <p>
 * The default implementation returns an empty result.
 * </p>
 */
public BrowseResult search(String containerId, String searchCriteria, String filter,
                           long firstResult, long maxResults, SortCriterion[] orderBy) throws ContentDirectoryException {

    try {
        return new BrowseResult(new DIDLParser().generate(new DIDLContent()), 0, 0);
    } catch (Exception ex) {
        throw new ContentDirectoryException(ErrorCode.ACTION_FAILED, ex.toString());
    }
}
 
Example #20
Source File: PullSOAPActionProcessorImpl.java    From DroidDLNA with GNU General Public License v3.0 5 votes vote down vote up
protected Map<String, String> getMatchingNodes(XmlPullParser xpp, ActionArgument[] args) throws Exception {

        // This is a case-insensitive search!
        List<String> names = new ArrayList<String>();
        for (ActionArgument argument : args) {
            names.add(argument.getName().toUpperCase());
            for (String alias : Arrays.asList(argument.getAliases())) {
                names.add(alias.toUpperCase());
            }
        }

        Map<String, String> matches = new HashMap<String, String>();

        String enclosingTag = xpp.getName();

        int event;
        do {
            event = xpp.next();
            if(event == XmlPullParser.START_TAG && names.contains(xpp.getName().toUpperCase())) {
                matches.put(xpp.getName(), xpp.nextText());
            }

        }
        while (event != XmlPullParser.END_DOCUMENT && (event != XmlPullParser.END_TAG || !xpp.getName().equals(enclosingTag)));

        if (matches.size() < args.length) {
            throw new ActionException(
                ErrorCode.ARGUMENT_VALUE_INVALID,
                "Invalid number of input or output arguments in XML message, expected "
                    + args.length + " but found " + matches.size()
            );
        }
        return matches;
    }
 
Example #21
Source File: PullSOAPActionProcessorImpl.java    From DroidDLNA with GNU General Public License v3.0 5 votes vote down vote up
protected ActionException readFaultElement(XmlPullParser xpp) throws Exception {
    // We're in the "Fault" tag

    String errorCode = null;
    String errorDescription = null;

    XmlPullParserUtils.searchTag(xpp, "UPnPError");

    int event;
    do {
        event = xpp.next();
        if (event == XmlPullParser.START_TAG) {
            String tag = xpp.getName();
            if (tag.equals("errorCode")) {
                errorCode = xpp.nextText();
            } else if (tag.equals("errorDescription")) {
                errorDescription = xpp.nextText();
            }
        }
    }
    while (event != XmlPullParser.END_DOCUMENT && (event != XmlPullParser.END_TAG || !xpp.getName().equals("UPnPError")));

    if (errorCode != null) {
        try {
            int numericCode = Integer.valueOf(errorCode);
            ErrorCode standardErrorCode = ErrorCode.getByCode(numericCode);
            if (standardErrorCode != null) {
                log.fine("Reading fault element: " + standardErrorCode.getCode() + " - " + errorDescription);
                return new ActionException(standardErrorCode, errorDescription, false);
            } else {
                log.fine("Reading fault element: " + numericCode + " - " + errorDescription);
                return new ActionException(numericCode, errorDescription);
            }
        } catch (NumberFormatException ex) {
            throw new RuntimeException("Error code was not a number");
        }
    }

    throw new RuntimeException("Received fault element but no error code");
}
 
Example #22
Source File: SOAPActionProcessorImpl.java    From DroidDLNA with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Finds all element nodes in the list that match any argument name or argument
 * alias, throws {@link ActionException} if not all arguments were found.
 */
protected List<Node> getMatchingNodes(NodeList nodeList, ActionArgument[] args) throws ActionException {

    List<String> names = new ArrayList();
    for (ActionArgument argument : args) {
        names.add(argument.getName());
        names.addAll(Arrays.asList(argument.getAliases()));
    }

    List<Node> matches = new ArrayList();
    for (int i = 0; i < nodeList.getLength(); i++) {
        Node child = nodeList.item(i);

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

        if (names.contains(getUnprefixedNodeName(child)))
            matches.add(child);
    }

    if (matches.size() < args.length) {
        throw new ActionException(
                ErrorCode.ARGUMENT_VALUE_INVALID,
                "Invalid number of input or output arguments in XML message, expected " + args.length + " but found " + matches.size()
        );
    }
    return matches;
}
 
Example #23
Source File: SOAPActionProcessorImpl.java    From DroidDLNA with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Creates an instance of {@link ActionArgumentValue} and wraps an
 * {@link InvalidValueException} as an {@link ActionException} with the
 * appropriate {@link ErrorCode}.
 */
protected ActionArgumentValue createValue(ActionArgument arg, String value) throws ActionException {
    try {
        return new ActionArgumentValue(arg, value);
    } catch (InvalidValueException ex) {
        throw new ActionException(
                ErrorCode.ARGUMENT_VALUE_INVALID,
                "Wrong type or invalid value for '" + arg.getName() + "': " + ex.getMessage(),
                ex
        );
    }
}
 
Example #24
Source File: Search.java    From DroidDLNA with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void success(ActionInvocation actionInvocation) {
    log.fine("Successful search action, reading output argument values");

    SearchResult result = new SearchResult(
            actionInvocation.getOutput("Result").getValue().toString(),
            (UnsignedIntegerFourBytes) actionInvocation.getOutput("NumberReturned").getValue(),
            (UnsignedIntegerFourBytes) actionInvocation.getOutput("TotalMatches").getValue(),
            (UnsignedIntegerFourBytes) actionInvocation.getOutput("UpdateID").getValue());

    boolean proceed = receivedRaw(actionInvocation, result);

    if (proceed && result.getCountLong() > 0 && result.getResult().length() > 0) {
        try {
            DIDLParser didlParser = new DIDLParser();
            DIDLContent didl = didlParser.parse(result.getResult());
            received(actionInvocation, didl);
            updateStatus(Status.OK);
        } catch (Exception ex) {
            actionInvocation.setFailure(
                    new ActionException(ErrorCode.ACTION_FAILED, "Can't parse DIDL XML response: " + ex, ex)
            );
            failure(actionInvocation, null);
        }
    } else {
        received(actionInvocation, new DIDLContent());
        updateStatus(Status.NO_CONTENT);
    }
}
 
Example #25
Source File: QueryStateVariableExecutor.java    From DroidDLNA with GNU General Public License v3.0 5 votes vote down vote up
protected void executeQueryStateVariable(ActionInvocation<LocalService> actionInvocation, Object serviceImpl) throws Exception {

        LocalService service = actionInvocation.getAction().getService();

        String stateVariableName = actionInvocation.getInput("varName").toString();
        StateVariable stateVariable = service.getStateVariable(stateVariableName);

        if (stateVariable == null) {
            throw new ActionException(
                    ErrorCode.ARGUMENT_VALUE_INVALID, "No state variable found: " + stateVariableName
            );
        }

        StateVariableAccessor accessor;
        if ((accessor = service.getAccessor(stateVariable.getName())) == null) {
            throw new ActionException(
                    ErrorCode.ARGUMENT_VALUE_INVALID, "No accessor for state variable, can't read state: " + stateVariableName
            );
        }

        try {
            setOutputArgumentValue(
                    actionInvocation,
                    actionInvocation.getAction().getOutputArgument("return"),
                    accessor.read(stateVariable, serviceImpl).toString()
            );
        } catch (Exception ex) {
            throw new ActionException(ErrorCode.ACTION_FAILED, ex.getMessage());
        }
    }
 
Example #26
Source File: GetVolume.java    From DroidDLNA with GNU General Public License v3.0 5 votes vote down vote up
public void success(ActionInvocation invocation) {
    boolean ok = true;
    int currentVolume = 0;
    try {
        currentVolume = Integer.valueOf(invocation.getOutput("CurrentVolume").getValue().toString()); // UnsignedIntegerTwoBytes...
    } catch (Exception ex) {
        invocation.setFailure(
                new ActionException(ErrorCode.ACTION_FAILED, "Can't parse ProtocolInfo response: " + ex, ex)
        );
        failure(invocation, null);
        ok = false;
    }
    if (ok) received(invocation, currentVolume);
}
 
Example #27
Source File: SOAPActionProcessorImpl.java    From TVRemoteIME with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Finds all element nodes in the list that match any argument name or argument
 * alias, throws {@link ActionException} if not all arguments were found.
 */
protected List<Node> getMatchingNodes(NodeList nodeList, ActionArgument[] args) throws ActionException {

    List<String> names = new ArrayList();
    for (ActionArgument argument : args) {
        names.add(argument.getName());
        names.addAll(Arrays.asList(argument.getAliases()));
    }

    List<Node> matches = new ArrayList();
    for (int i = 0; i < nodeList.getLength(); i++) {
        Node child = nodeList.item(i);

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

        if (names.contains(getUnprefixedNodeName(child)))
            matches.add(child);
    }

    if (matches.size() < args.length) {
        throw new ActionException(
                ErrorCode.ARGUMENT_VALUE_INVALID,
                "Invalid number of input or output arguments in XML message, expected " + args.length + " but found " + matches.size()
        );
    }
    return matches;
}
 
Example #28
Source File: SendingAction.java    From DroidDLNA with GNU General Public License v3.0 5 votes vote down vote up
protected void handleResponseFailure(IncomingActionResponseMessage responseMsg) throws ActionException {

        try {
            log.fine("Received response with Internal Server Error, reading SOAP failure message");
            getUpnpService().getConfiguration().getSoapActionProcessor().readBody(responseMsg, actionInvocation);
        } catch (UnsupportedDataException ex) {
            log.fine("Error reading SOAP body: " + ex);
            log.log(Level.FINE, "Exception root cause: ", Exceptions.unwrap(ex));
            throw new ActionException(
                ErrorCode.ACTION_FAILED,
                "Error reading SOAP response failure message. " + ex.getMessage(),
                false
            );
        }
    }
 
Example #29
Source File: SendingAction.java    From DroidDLNA with GNU General Public License v3.0 5 votes vote down vote up
protected void handleResponse(IncomingActionResponseMessage responseMsg) throws ActionException {

        try {
            log.fine("Received response for outgoing call, reading SOAP response body: " + responseMsg);
            getUpnpService().getConfiguration().getSoapActionProcessor().readBody(responseMsg, actionInvocation);
        } catch (UnsupportedDataException ex) {
            log.fine("Error reading SOAP body: " + ex);
            log.log(Level.FINE, "Exception root cause: ", Exceptions.unwrap(ex));
            throw new ActionException(
                ErrorCode.ACTION_FAILED,
                "Error reading SOAP response message. " + ex.getMessage(),
                false
            );
        }
    }
 
Example #30
Source File: SOAPActionProcessorImpl.java    From TVRemoteIME with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Creates an instance of {@link ActionArgumentValue} and wraps an
 * {@link InvalidValueException} as an {@link ActionException} with the
 * appropriate {@link ErrorCode}.
 */
protected ActionArgumentValue createValue(ActionArgument arg, String value) throws ActionException {
    try {
        return new ActionArgumentValue(arg, value);
    } catch (InvalidValueException ex) {
        throw new ActionException(
                ErrorCode.ARGUMENT_VALUE_INVALID,
                "Wrong type or invalid value for '" + arg.getName() + "': " + ex.getMessage(),
                ex
        );
    }
}