Java Code Examples for org.fourthline.cling.model.types.ErrorCode#ACTION_FAILED

The following examples show how to use org.fourthline.cling.model.types.ErrorCode#ACTION_FAILED . 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 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 2
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 3
Source File: SendingAction.java    From TVRemoteIME with GNU General Public License v2.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 4
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 5
Source File: QueryStateVariableExecutor.java    From TVRemoteIME with GNU General Public License v2.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 6
Source File: AbstractContentDirectoryService.java    From TVRemoteIME with GNU General Public License v2.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 7
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 8
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 9
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 10
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 11
Source File: MethodActionExecutor.java    From TVRemoteIME with GNU General Public License v2.0 4 votes vote down vote up
@Override
protected void execute(ActionInvocation<LocalService> actionInvocation, Object serviceImpl) throws Exception {

    // Find the "real" parameters of the method we want to call, and create arguments
    Object[] inputArgumentValues = createInputArgumentValues(actionInvocation, method);

    // Simple case: no output arguments
    if (!actionInvocation.getAction().hasOutputArguments()) {
        log.fine("Calling local service method with no output arguments: " + method);
        Reflections.invoke(method, serviceImpl, inputArgumentValues);
        return;
    }

    boolean isVoid = method.getReturnType().equals(Void.TYPE);

    log.fine("Calling local service method with output arguments: " + method);
    Object result;
    boolean isArrayResultProcessed = true;
    if (isVoid) {

        log.fine("Action method is void, calling declared accessors(s) on service instance to retrieve ouput argument(s)");
        Reflections.invoke(method, serviceImpl, inputArgumentValues);
        result = readOutputArgumentValues(actionInvocation.getAction(), serviceImpl);

    } else if (isUseOutputArgumentAccessors(actionInvocation)) {

        log.fine("Action method is not void, calling declared accessor(s) on returned instance to retrieve ouput argument(s)");
        Object returnedInstance = Reflections.invoke(method, serviceImpl, inputArgumentValues);
        result = readOutputArgumentValues(actionInvocation.getAction(), returnedInstance);

    } else {

        log.fine("Action method is not void, using returned value as (single) output argument");
        result = Reflections.invoke(method, serviceImpl, inputArgumentValues);
        isArrayResultProcessed = false; // We never want to process e.g. byte[] as individual variable values
    }

    ActionArgument<LocalService>[] outputArgs = actionInvocation.getAction().getOutputArguments();

    if (isArrayResultProcessed && result instanceof Object[]) {
        Object[] results = (Object[]) result;
        log.fine("Accessors returned Object[], setting output argument values: " + results.length);
        for (int i = 0; i < outputArgs.length; i++) {
            setOutputArgumentValue(actionInvocation, outputArgs[i], results[i]);
        }
    } else if (outputArgs.length == 1) {
        setOutputArgumentValue(actionInvocation, outputArgs[0], result);
    } else {
        throw new ActionException(
                ErrorCode.ACTION_FAILED,
                "Method return does not match required number of output arguments: " + outputArgs.length
        );
    }

}
 
Example 12
Source File: ActionCancelledException.java    From TVRemoteIME with GNU General Public License v2.0 4 votes vote down vote up
public ActionCancelledException(InterruptedException cause) {
    super(ErrorCode.ACTION_FAILED, "Action execution interrupted", cause);
}
 
Example 13
Source File: MethodActionExecutor.java    From DroidDLNA with GNU General Public License v3.0 4 votes vote down vote up
@Override
protected void execute(ActionInvocation<LocalService> actionInvocation, Object serviceImpl) throws Exception {

    // Find the "real" parameters of the method we want to call, and create arguments
    Object[] inputArgumentValues = createInputArgumentValues(actionInvocation, method);

    // Simple case: no output arguments
    if (!actionInvocation.getAction().hasOutputArguments()) {
        log.fine("Calling local service method with no output arguments: " + method);
        Reflections.invoke(method, serviceImpl, inputArgumentValues);
        return;
    }

    boolean isVoid = method.getReturnType().equals(Void.TYPE);

    log.fine("Calling local service method with output arguments: " + method);
    Object result;
    boolean isArrayResultProcessed = true;
    if (isVoid) {

        log.fine("Action method is void, calling declared accessors(s) on service instance to retrieve ouput argument(s)");
        Reflections.invoke(method, serviceImpl, inputArgumentValues);
        result = readOutputArgumentValues(actionInvocation.getAction(), serviceImpl);

    } else if (isUseOutputArgumentAccessors(actionInvocation)) {

        log.fine("Action method is not void, calling declared accessor(s) on returned instance to retrieve ouput argument(s)");
        Object returnedInstance = Reflections.invoke(method, serviceImpl, inputArgumentValues);
        result = readOutputArgumentValues(actionInvocation.getAction(), returnedInstance);

    } else {

        log.fine("Action method is not void, using returned value as (single) output argument");
        result = Reflections.invoke(method, serviceImpl, inputArgumentValues);
        isArrayResultProcessed = false; // We never want to process e.g. byte[] as individual variable values
    }

    ActionArgument<LocalService>[] outputArgs = actionInvocation.getAction().getOutputArguments();

    if (isArrayResultProcessed && result instanceof Object[]) {
        Object[] results = (Object[]) result;
        log.fine("Accessors returned Object[], setting output argument values: " + results.length);
        for (int i = 0; i < outputArgs.length; i++) {
            setOutputArgumentValue(actionInvocation, outputArgs[i], results[i]);
        }
    } else if (outputArgs.length == 1) {
        setOutputArgumentValue(actionInvocation, outputArgs[0], result);
    } else {
        throw new ActionException(
                ErrorCode.ACTION_FAILED,
                "Method return does not match required number of output arguments: " + outputArgs.length
        );
    }

}
 
Example 14
Source File: ActionCancelledException.java    From DroidDLNA with GNU General Public License v3.0 4 votes vote down vote up
public ActionCancelledException(InterruptedException cause) {
    super(ErrorCode.ACTION_FAILED, "Action execution interrupted", cause);
}