Java源码示例:org.fourthline.cling.model.types.ErrorCode

示例1
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();
}
 
示例2
@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()
        );
    }
}
 
示例3
@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);
	}
}
 
示例4
@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);
    }
}
 
示例5
@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);
    }
}
 
示例6
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"
        )
    );
}
 
示例7
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;
}
 
示例8
/**
 * 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;
}
 
示例9
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();
}
 
示例10
@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()
        );
    }
}
 
示例11
@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);
	}
}
 
示例12
@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);
    }
}
 
示例13
@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);
    }
}
 
示例14
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"
        )
    );
}
 
示例15
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;
}
 
示例16
/**
 * 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;
}
 
示例17
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
            );
        }
    }
 
示例18
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
            );
        }
    }
 
示例19
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());
        }
    }
 
示例20
/**
 * Sets the output argument value on the {@link org.fourthline.cling.model.action.ActionInvocation}, considers string conversion.
 */
protected void setOutputArgumentValue(ActionInvocation<LocalService> actionInvocation, ActionArgument<LocalService> argument, Object result)
        throws ActionException {

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

    if (result != null) {
        try {
            if (service.isStringConvertibleType(result)) {
                log.fine("Result of invocation matches convertible type, setting toString() single output argument value");
                actionInvocation.setOutput(new ActionArgumentValue(argument, result.toString()));
            } else {
                log.fine("Result of invocation is Object, setting single output argument value");
                actionInvocation.setOutput(new ActionArgumentValue(argument, result));
            }
        } catch (InvalidValueException ex) {
            throw new ActionException(
                    ErrorCode.ARGUMENT_VALUE_INVALID,
                    "Wrong type or invalid value for '" + argument.getName() + "': " + ex.getMessage(),
                    ex
            );
        }
    } else {

        log.fine("Result of invocation is null, not setting any output argument value(s)");
    }

}
 
示例21
@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;
}
 
示例22
protected Channel getChannel(String channelName) throws RenderingControlException {
    try {
        return Channel.valueOf(channelName);
    } catch (IllegalArgumentException ex) {
        throw new RenderingControlException(ErrorCode.ARGUMENT_VALUE_INVALID, "Unsupported audio channel: " + channelName);
    }
}
 
示例23
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);
}
 
示例24
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);
    }
}
 
示例25
@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);
    }
}
 
示例26
/**
 * 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());
    }
}
 
示例27
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;
    }
 
示例28
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");
}
 
示例29
/**
 * 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;
}
 
示例30
/**
 * 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
        );
    }
}