org.fourthline.cling.model.action.ActionInvocation Java Examples

The following examples show how to use org.fourthline.cling.model.action.ActionInvocation. 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 Project: TVRemoteIME   Author: kingthy   File: OutgoingActionRequestMessage.java    License: GNU General Public License v2.0 6 votes vote down vote up
public OutgoingActionRequestMessage(ActionInvocation actionInvocation, URL controlURL) {
    this(actionInvocation.getAction(), new UpnpRequest(UpnpRequest.Method.POST, controlURL));

    // For proxy remote invocations, pass through the user agent header
    if (actionInvocation instanceof RemoteActionInvocation) {
        RemoteActionInvocation remoteActionInvocation = (RemoteActionInvocation) actionInvocation;
        if (remoteActionInvocation.getRemoteClientInfo() != null
            && remoteActionInvocation.getRemoteClientInfo().getRequestUserAgent() != null) {
            getHeaders().add(
                UpnpHeader.Type.USER_AGENT,
                new UserAgentHeader(remoteActionInvocation.getRemoteClientInfo().getRequestUserAgent())
            );
        }
    } else if (actionInvocation.getClientInfo() != null) {
        getHeaders().putAll(actionInvocation.getClientInfo().getRequestHeaders());
    }
}
 
Example #2
Source Project: TVRemoteIME   Author: kingthy   File: PortMappingAdd.java    License: GNU General Public License v2.0 6 votes vote down vote up
protected PortMappingAdd(Service service, ControlPoint controlPoint, PortMapping portMapping) {
    super(new ActionInvocation(service.getAction("AddPortMapping")), controlPoint);

    this.portMapping = portMapping;

    getActionInvocation().setInput("NewExternalPort", portMapping.getExternalPort());
    getActionInvocation().setInput("NewProtocol", portMapping.getProtocol());
    getActionInvocation().setInput("NewInternalClient", portMapping.getInternalClient());
    getActionInvocation().setInput("NewInternalPort", portMapping.getInternalPort());
    getActionInvocation().setInput("NewLeaseDuration", portMapping.getLeaseDurationSeconds());
    getActionInvocation().setInput("NewEnabled", portMapping.isEnabled());
    if (portMapping.hasRemoteHost())
        getActionInvocation().setInput("NewRemoteHost", portMapping.getRemoteHost());
    if (portMapping.hasDescription())
        getActionInvocation().setInput("NewPortMappingDescription", portMapping.getDescription());

}
 
Example #3
Source Project: TVRemoteIME   Author: kingthy   File: GetStatusInfo.java    License: 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 Project: TVRemoteIME   Author: kingthy   File: Browse.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * @param maxResults Can be <code>null</code>, then {@link #getDefaultMaxResults()} is used.
 */
public Browse(Service service, String objectID, BrowseFlag flag,
                            String filter, long firstResult, Long maxResults, SortCriterion... orderBy) {

    super(new ActionInvocation(service.getAction("Browse")));

    log.fine("Creating browse action for object ID: " + objectID);

    getActionInvocation().setInput("ObjectID", objectID);
    getActionInvocation().setInput("BrowseFlag", flag.toString());
    getActionInvocation().setInput("Filter", filter);
    getActionInvocation().setInput("StartingIndex", new UnsignedIntegerFourBytes(firstResult));
    getActionInvocation().setInput("RequestedCount",
            new UnsignedIntegerFourBytes(maxResults == null ? getDefaultMaxResults() : maxResults)
    );
    getActionInvocation().setInput("SortCriteria", SortCriterion.toString(orderBy));
}
 
Example #5
Source Project: HPlayer   Author: hezhubo   File: UpnpControlSet.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 设置静音
 */
public void setDeviceMute(boolean mute) {
    ActionCallback setMute = new SetMute(renderingControlService, mute) {

        @Override
        public void failure(ActionInvocation arg0, UpnpResponse arg1, String arg2) {
            onFailureCallBack(SET_MUTE, arg2);
        }

        @Override
        public void success(ActionInvocation invocation) {
            onSuccessCallBack(SET_MUTE);
        }
    };
    mUpnpService.getControlPoint().execute(setMute);
}
 
Example #6
Source Project: DroidDLNA   Author: offbye   File: SOAPActionProcessorImpl.java    License: GNU General Public License v3.0 6 votes vote down vote up
protected Element readActionResponseElement(Element bodyElement, ActionInvocation actionInvocation) {
    NodeList bodyChildren = bodyElement.getChildNodes();

    for (int i = 0; i < bodyChildren.getLength(); i++) {
        Node bodyChild = bodyChildren.item(i);

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

        if (getUnprefixedNodeName(bodyChild).equals(actionInvocation.getAction().getName() + "Response")) {
            log.fine("Reading action response element: " + getUnprefixedNodeName(bodyChild));
            return (Element) bodyChild;
        }
    }
    log.fine("Could not read action response element");
    return null;
}
 
Example #7
Source Project: TVRemoteIME   Author: kingthy   File: RecoveringSOAPActionProcessorImpl.java    License: GNU General Public License v2.0 6 votes vote down vote up
public void readBody(ActionRequestMessage requestMessage, ActionInvocation actionInvocation) throws UnsupportedDataException {
    try {
        super.readBody(requestMessage, actionInvocation);
    } catch (UnsupportedDataException ex) {

        // Can't recover from this
        if (!requestMessage.isBodyNonEmptyString())
            throw ex;

        log.warning("Trying to recover from invalid SOAP XML request: " + ex);
        String body = getMessageBody(requestMessage);

        // TODO: UPNP VIOLATION: TwonkyMobile sends unencoded '&' in SetAVTransportURI action calls:
        // <CurrentURI>http://192.168.1.14:56923/content/12a470d854dbc6887e4103e3140783fd.wav?profile_id=0&convert=wav</CurrentURI>
        String fixedBody = XmlPullParserUtils.fixXMLEntities(body);

        try {
            // Try again, if this fails, we are done...
            requestMessage.setBody(fixedBody);
            super.readBody(requestMessage, actionInvocation);
        } catch (UnsupportedDataException ex2) {
            handleInvalidMessage(actionInvocation, ex, ex2);
        }
    }
}
 
Example #8
Source Project: TVRemoteIME   Author: kingthy   File: PullSOAPActionProcessorImpl.java    License: 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 #9
Source Project: TVRemoteIME   Author: kingthy   File: AddMessage.java    License: GNU General Public License v2.0 5 votes vote down vote up
public AddMessage(Service service, Message message) {
    super(new ActionInvocation(service.getAction("AddMessage")));

    getActionInvocation().setInput("MessageID", Integer.toString(message.getId()));
    getActionInvocation().setInput("MessageType", mimeType.toString());
    getActionInvocation().setInput("Message", message.toString());
}
 
Example #10
Source Project: TVRemoteIME   Author: kingthy   File: SOAPActionProcessorImpl.java    License: GNU General Public License v2.0 5 votes vote down vote up
protected void readBodyResponse(Document d,
                                Element bodyElement,
                                ActionResponseMessage message,
                                ActionInvocation actionInvocation) throws Exception {

    Element actionResponse = readActionResponseElement(bodyElement, actionInvocation);
    readActionOutputArguments(actionResponse, actionInvocation);
}
 
Example #11
Source Project: TVRemoteIME   Author: kingthy   File: SOAPActionProcessorImpl.java    License: GNU General Public License v2.0 5 votes vote down vote up
protected void writeActionInputArguments(Document d,
                                         Element actionRequestElement,
                                         ActionInvocation actionInvocation) {

    for (ActionArgument argument : actionInvocation.getAction().getInputArguments()) {
        log.fine("Writing action input argument: " + argument.getName());
        String value = actionInvocation.getInput(argument) != null ? actionInvocation.getInput(argument).toString() : "";
        XMLUtil.appendNewElement(d, actionRequestElement, argument.getName(), value);
    }
}
 
Example #12
Source Project: DroidDLNA   Author: offbye   File: PrepareForConnection.java    License: GNU General Public License v3.0 5 votes vote down vote up
public PrepareForConnection(Service service, ControlPoint controlPoint,
                            ProtocolInfo remoteProtocolInfo, ServiceReference peerConnectionManager,
                            int peerConnectionID, ConnectionInfo.Direction direction) {
    super(new ActionInvocation(service.getAction("PrepareForConnection")), controlPoint);

    getActionInvocation().setInput("RemoteProtocolInfo", remoteProtocolInfo.toString());
    getActionInvocation().setInput("PeerConnectionManager", peerConnectionManager.toString());
    getActionInvocation().setInput("PeerConnectionID", peerConnectionID);
    getActionInvocation().setInput("Direction", direction.toString());
}
 
Example #13
Source Project: DroidDLNA   Author: offbye   File: AddMessage.java    License: GNU General Public License v3.0 5 votes vote down vote up
public AddMessage(Service service, Message message) {
    super(new ActionInvocation(service.getAction("AddMessage")));

    getActionInvocation().setInput("MessageID", Integer.toString(message.getId()));
    getActionInvocation().setInput("MessageType", mimeType.toString());
    getActionInvocation().setInput("Message", message.toString());
}
 
Example #14
Source Project: DroidDLNA   Author: offbye   File: PullSOAPActionProcessorImpl.java    License: GNU General Public License v3.0 5 votes vote down vote up
public void readBody(ActionRequestMessage requestMessage, ActionInvocation actionInvocation) throws UnsupportedDataException {
    String body = getMessageBody(requestMessage);
    try {
        XmlPullParser xpp = XmlPullParserUtils.createParser(body);
        readBodyRequest(xpp, requestMessage, actionInvocation);
    } catch (Exception ex) {
        throw new UnsupportedDataException("Can't transform message payload: " + ex, ex, body);
    }
}
 
Example #15
Source Project: DroidDLNA   Author: offbye   File: StopCallback.java    License: GNU General Public License v3.0 5 votes vote down vote up
public void success(ActionInvocation paramActionInvocation) {
    super.success(paramActionInvocation);
    if (!isRePlay.booleanValue()) {
        this.handler.sendEmptyMessage(DMCControlMessage.SETURL);
    } else {
        this.handler.sendEmptyMessage(DMCControlMessage.GETTRANSPORTINFO);
    }
}
 
Example #16
Source Project: TVRemoteIME   Author: kingthy   File: SetAVTransportURI.java    License: GNU General Public License v2.0 5 votes vote down vote up
public SetAVTransportURI(UnsignedIntegerFourBytes instanceId, Service service, String uri, String metadata) {
    super(new ActionInvocation(service.getAction("SetAVTransportURI")));
    log.fine("Creating SetAVTransportURI action for URI: " + uri);
    getActionInvocation().setInput("InstanceID", instanceId);
    getActionInvocation().setInput("CurrentURI", uri);
    getActionInvocation().setInput("CurrentURIMetaData", metadata);
}
 
Example #17
Source Project: TVRemoteIME   Author: kingthy   File: SOAPActionProcessorImpl.java    License: GNU General Public License v2.0 5 votes vote down vote up
public void writeBody(ActionResponseMessage responseMessage, ActionInvocation actionInvocation) throws UnsupportedDataException {

        log.fine("Writing body of " + responseMessage + " for: " + actionInvocation);

        try {

            DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
            factory.setNamespaceAware(true);
            Document d = factory.newDocumentBuilder().newDocument();
            Element body = writeBodyElement(d);

            if (actionInvocation.getFailure() != null) {
                writeBodyFailure(d, body, responseMessage, actionInvocation);
            } else {
                writeBodyResponse(d, body, responseMessage, actionInvocation);
            }

            if (log.isLoggable(Level.FINER)) {
                log.finer("===================================== SOAP BODY BEGIN ============================================");
                log.finer(responseMessage.getBodyString());
                log.finer("-===================================== SOAP BODY END ============================================");
            }

        } catch (Exception ex) {
            throw new UnsupportedDataException("Can't transform message payload: " + ex, ex);
        }
    }
 
Example #18
Source Project: portmapper   Author: kaklakariada   File: GetPortMappingEntryAction.java    License: GNU General Public License v3.0 5 votes vote down vote up
@Override
public PortMapping convert(final ActionInvocation<RemoteService> response) {
    final Protocol protocol = Protocol.getProtocol(getStringValue(response, "NewProtocol"));
    final String remoteHost = getStringValue(response, "NewRemoteHost");
    final int externalPort = getIntValue(response, "NewExternalPort");
    final String internalClient = getStringValue(response, "NewInternalClient");
    final int internalPort = getIntValue(response, "NewInternalPort");
    final String description = getStringValue(response, "NewPortMappingDescription");
    final boolean enabled = getBooleanValue(response, "NewEnabled");
    final long leaseDuration = getLongValue(response, "NewLeaseDuration");
    return new PortMapping(protocol, remoteHost, externalPort, internalClient, internalPort, description, enabled,
            leaseDuration);
}
 
Example #19
Source Project: TVRemoteIME   Author: kingthy   File: SOAPActionProcessorImpl.java    License: GNU General Public License v2.0 5 votes vote down vote up
protected void writeBodyRequest(Document d,
                                Element bodyElement,
                                ActionRequestMessage message,
                                ActionInvocation actionInvocation) throws Exception {

    Element actionRequestElement = writeActionRequestElement(d, bodyElement, message, actionInvocation);
    writeActionInputArguments(d, actionRequestElement, actionInvocation);
    message.setBody(toString(d));

}
 
Example #20
Source Project: DroidDLNA   Author: offbye   File: GetVolumeCallback.java    License: GNU General Public License v3.0 5 votes vote down vote up
public void received(ActionInvocation paramActionInvocation, int paramInt) {
	Log.e("getcurrentvolume", "" + paramInt);
	Message localMessage = new Message();
	localMessage.what = DMCControlMessage.SETVOLUME;
	Bundle localBundle = new Bundle();
	localBundle.putLong("getVolume", paramInt);
	localBundle.putInt("isSetVolume", isSetVolumeFlag);
	localMessage.setData(localBundle);
	handler.sendMessage(localMessage);
}
 
Example #21
Source Project: DroidDLNA   Author: offbye   File: ActionCallback.java    License: GNU General Public License v3.0 5 votes vote down vote up
protected String createDefaultFailureMessage(ActionInvocation invocation, UpnpResponse operation) {
    String message = "Error: ";
    final ActionException exception = invocation.getFailure();
    if (exception != null) {
        message = message + exception.getMessage();
    }
    if (operation != null) {
        message = message + " (HTTP response was: " + operation.getResponseDetails() + ")";
    }
    return message;
}
 
Example #22
Source Project: DroidDLNA   Author: offbye   File: SOAPActionProcessorImpl.java    License: GNU General Public License v3.0 5 votes vote down vote up
public void writeBody(ActionResponseMessage responseMessage, ActionInvocation actionInvocation) throws UnsupportedDataException {

        log.fine("Writing body of " + responseMessage + " for: " + actionInvocation);

        try {

            DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
            factory.setNamespaceAware(true);
            Document d = factory.newDocumentBuilder().newDocument();
            Element body = writeBodyElement(d);

            if (actionInvocation.getFailure() != null) {
                writeBodyFailure(d, body, responseMessage, actionInvocation);
            } else {
                writeBodyResponse(d, body, responseMessage, actionInvocation);
            }

            if (log.isLoggable(Level.FINER)) {
                log.finer("===================================== SOAP BODY BEGIN ============================================");
                log.finer(responseMessage.getBodyString());
                log.finer("-===================================== SOAP BODY END ============================================");
            }

        } catch (Exception ex) {
            throw new UnsupportedDataException("Can't transform message payload: " + ex, ex);
        }
    }
 
Example #23
Source Project: DroidDLNA   Author: offbye   File: SOAPActionProcessorImpl.java    License: GNU General Public License v3.0 5 votes vote down vote up
protected void writeActionInputArguments(Document d,
                                         Element actionRequestElement,
                                         ActionInvocation actionInvocation) {

    for (ActionArgument argument : actionInvocation.getAction().getInputArguments()) {
        log.fine("Writing action input argument: " + argument.getName());
        String value = actionInvocation.getInput(argument) != null ? actionInvocation.getInput(argument).toString() : "";
        XMLUtil.appendNewElement(d, actionRequestElement, argument.getName(), value);
    }
}
 
Example #24
Source Project: DroidDLNA   Author: offbye   File: GetPositionInfoCallback.java    License: GNU General Public License v3.0 5 votes vote down vote up
public void received(ActionInvocation paramActionInvocation,
		PositionInfo paramPositionInfo) {
	Bundle localBundle = new Bundle();
	localBundle.putString("TrackDuration",
			paramPositionInfo.getTrackDuration());
	localBundle.putString("RelTime", paramPositionInfo.getRelTime());
	Intent localIntent = new Intent(Action.PLAY_UPDATE);
	localIntent.putExtras(localBundle);
	activity.sendBroadcast(localIntent);
}
 
Example #25
Source Project: DroidDLNA   Author: offbye   File: SOAPActionProcessorImpl.java    License: GNU General Public License v3.0 5 votes vote down vote up
public void readActionInputArguments(Element actionRequestElement,
                                     ActionInvocation actionInvocation) throws ActionException {
    actionInvocation.setInput(
            readArgumentValues(
                    actionRequestElement.getChildNodes(),
                    actionInvocation.getAction().getInputArguments()
            )
    );
}
 
Example #26
Source Project: TVRemoteIME   Author: kingthy   File: GetVolume.java    License: 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 #27
Source Project: TVRemoteIME   Author: kingthy   File: PortMappingDelete.java    License: GNU General Public License v2.0 5 votes vote down vote up
protected PortMappingDelete(Service service, ControlPoint controlPoint, PortMapping portMapping) {
    super(new ActionInvocation(service.getAction("DeletePortMapping")), controlPoint);

    this.portMapping = portMapping;

    getActionInvocation().setInput("NewExternalPort", portMapping.getExternalPort());
    getActionInvocation().setInput("NewProtocol", portMapping.getProtocol());
    if (portMapping.hasRemoteHost())
        getActionInvocation().setInput("NewRemoteHost", portMapping.getRemoteHost());

}
 
Example #28
Source Project: DroidDLNA   Author: offbye   File: GetVolumeCallback.java    License: GNU General Public License v3.0 5 votes vote down vote up
public void failure(ActionInvocation paramActionInvocation,
		UpnpResponse paramUpnpResponse, String paramString) {
	if (this.type == 1) {
		this.handler.sendEmptyMessage(DMCControlMessage.PLAYIMAGEFAILED);
	} else if (this.type == 2) {
		this.handler.sendEmptyMessage(DMCControlMessage.PLAYAUDIOFAILED);
	} else if (this.type == 3) {
		this.handler.sendEmptyMessage(DMCControlMessage.PLAYVIDEOFAILED);
	}
}
 
Example #29
Source Project: TVRemoteIME   Author: kingthy   File: Browse.java    License: GNU General Public License v2.0 5 votes vote down vote up
public boolean receivedRaw(ActionInvocation actionInvocation, BrowseResult browseResult) {
    /*
    if (log.isLoggable(Level.FINER)) {
        log.finer("-------------------------------------------------------------------------------------");
        log.finer("\n" + XML.pretty(browseResult.getDidl()));
        log.finer("-------------------------------------------------------------------------------------");
    }
    */
    return true;
}
 
Example #30
Source Project: TVRemoteIME   Author: kingthy   File: SOAPActionProcessorImpl.java    License: GNU General Public License v2.0 5 votes vote down vote up
protected void readActionOutputArguments(Element actionResponseElement,
                                         ActionInvocation actionInvocation) throws ActionException {

    actionInvocation.setOutput(
            readArgumentValues(
                    actionResponseElement.getChildNodes(),
                    actionInvocation.getAction().getOutputArguments()
            )
    );
}