Java Code Examples for org.fourthline.cling.model.action.ActionInvocation#setFailure()

The following examples show how to use org.fourthline.cling.model.action.ActionInvocation#setFailure() . 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: 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 2
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 3
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 4
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 5
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 6
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 7
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 8
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 9
Source File: GetVolume.java    From TVRemoteIME with GNU General Public License v2.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 10
Source File: Browse.java    From TVRemoteIME with GNU General Public License v2.0 5 votes vote down vote up
public void success(ActionInvocation invocation) {
    log.fine("Successful browse action, reading output argument values");

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

    boolean proceed = receivedRaw(invocation, result);

    if (proceed && result.getCountLong() > 0 && result.getResult().length() > 0) {

        try {

            DIDLParser didlParser = new DIDLParser();
            DIDLContent didl = didlParser.parse(result.getResult());
            received(invocation, didl);
            updateStatus(Status.OK);

        } catch (Exception ex) {
            invocation.setFailure(
                    new ActionException(ErrorCode.ACTION_FAILED, "Can't parse DIDL XML response: " + ex, ex)
            );
            failure(invocation, null);
        }

    } else {
        received(invocation, new DIDLContent());
        updateStatus(Status.NO_CONTENT);
    }
}
 
Example 11
Source File: Search.java    From TVRemoteIME with GNU General Public License v2.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 12
Source File: SOAPActionProcessorImpl.java    From TVRemoteIME with GNU General Public License v2.0 5 votes vote down vote up
public void readBody(ActionResponseMessage responseMsg, ActionInvocation actionInvocation) throws UnsupportedDataException {

        log.fine("Reading body of " + responseMsg + " for: " + actionInvocation);
        if (log.isLoggable(Level.FINER)) {
            log.finer("===================================== SOAP BODY BEGIN ============================================");
            log.finer(responseMsg.getBodyString());
            log.finer("-===================================== SOAP BODY END ============================================");
        }

        String body = getMessageBody(responseMsg);
        try {

            DocumentBuilderFactory factory = createDocumentBuilderFactory();
            factory.setNamespaceAware(true);
            DocumentBuilder documentBuilder = factory.newDocumentBuilder();
            documentBuilder.setErrorHandler(this);

            Document d = documentBuilder.parse(new InputSource(new StringReader(body)));

            Element bodyElement = readBodyElement(d);

            ActionException failure = readBodyFailure(d, bodyElement);

            if (failure == null) {
                readBodyResponse(d, bodyElement, responseMsg, actionInvocation);
            } else {
                actionInvocation.setFailure(failure);
            }

        } catch (Exception ex) {
    		throw new UnsupportedDataException("Can't transform message payload: " + ex, ex, body);
        }
    }
 
Example 13
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 14
Source File: Browse.java    From DroidDLNA with GNU General Public License v3.0 5 votes vote down vote up
public void success(ActionInvocation invocation) {
    log.fine("Successful browse action, reading output argument values");

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

    boolean proceed = receivedRaw(invocation, result);

    if (proceed && result.getCountLong() > 0 && result.getResult().length() > 0) {

        try {

            DIDLParser didlParser = new DIDLParser();
            DIDLContent didl = didlParser.parse(result.getResult());
            received(invocation, didl);
            updateStatus(Status.OK);

        } catch (Exception ex) {
            invocation.setFailure(
                    new ActionException(ErrorCode.ACTION_FAILED, "Can't parse DIDL XML response: " + ex, ex)
            );
            failure(invocation, null);
        }

    } else {
        received(invocation, new DIDLContent());
        updateStatus(Status.NO_CONTENT);
    }
}
 
Example 15
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 16
Source File: SOAPActionProcessorImpl.java    From DroidDLNA with GNU General Public License v3.0 5 votes vote down vote up
public void readBody(ActionResponseMessage responseMsg, ActionInvocation actionInvocation) throws UnsupportedDataException {

        log.fine("Reading body of " + responseMsg + " for: " + actionInvocation);
        if (log.isLoggable(Level.FINER)) {
            log.finer("===================================== SOAP BODY BEGIN ============================================");
            log.finer(responseMsg.getBodyString());
            log.finer("-===================================== SOAP BODY END ============================================");
        }

        String body = getMessageBody(responseMsg);
        try {

            DocumentBuilderFactory factory = createDocumentBuilderFactory();
            factory.setNamespaceAware(true);
            DocumentBuilder documentBuilder = factory.newDocumentBuilder();
            documentBuilder.setErrorHandler(this);

            Document d = documentBuilder.parse(new InputSource(new StringReader(body)));

            Element bodyElement = readBodyElement(d);

            ActionException failure = readBodyFailure(d, bodyElement);

            if (failure == null) {
                readBodyResponse(d, bodyElement, responseMsg, actionInvocation);
            } else {
                actionInvocation.setFailure(failure);
            }

        } catch (Exception ex) {
    		throw new UnsupportedDataException("Can't transform message payload: " + ex, ex, body);
        }
    }