org.fourthline.cling.model.message.header.UpnpHeader Java Examples

The following examples show how to use org.fourthline.cling.model.message.header.UpnpHeader. 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: IncomingNotificationRequest.java    From DroidDLNA with GNU General Public License v3.0 6 votes vote down vote up
/**
 * @return The UDN value after parsing various USN header values, or <code>null</code>.
 */
public UDN getUDN() {
    // This processes the headers as specified in UDA 1.0, tables in section 1.1.12

    UpnpHeader<UDN> udnHeader = getHeaders().getFirstHeader(UpnpHeader.Type.USN, USNRootDeviceHeader.class);
    if (udnHeader != null) return udnHeader.getValue();

    udnHeader = getHeaders().getFirstHeader(UpnpHeader.Type.USN, UDNHeader.class);
    if (udnHeader != null) return udnHeader.getValue();

    UpnpHeader<NamedDeviceType> deviceTypeHeader = getHeaders().getFirstHeader(UpnpHeader.Type.USN, DeviceUSNHeader.class);
    if (deviceTypeHeader != null) return deviceTypeHeader.getValue().getUdn();

    UpnpHeader<NamedServiceType> serviceTypeHeader = getHeaders().getFirstHeader(UpnpHeader.Type.USN, ServiceUSNHeader.class);
    if (serviceTypeHeader != null) return serviceTypeHeader.getValue().getUdn();

    return null;
}
 
Example #2
Source File: OutgoingSearchResponse.java    From TVRemoteIME with GNU General Public License v2.0 6 votes vote down vote up
public OutgoingSearchResponse(IncomingDatagramMessage request,
                              Location location,
                              LocalDevice device) {

    super(new UpnpResponse(UpnpResponse.Status.OK), request.getSourceAddress(), request.getSourcePort());

    getHeaders().add(UpnpHeader.Type.MAX_AGE, new MaxAgeHeader(device.getIdentity().getMaxAgeSeconds()));
    getHeaders().add(UpnpHeader.Type.LOCATION, new LocationHeader(location.getURL()));
    getHeaders().add(UpnpHeader.Type.SERVER, new ServerHeader());
    getHeaders().add(UpnpHeader.Type.EXT, new EXTHeader());

    if (location.getNetworkAddress().getHardwareAddress() != null) {
        getHeaders().add(
                UpnpHeader.Type.EXT_IFACE_MAC,
                 new InterfaceMacHeader(location.getNetworkAddress().getHardwareAddress())
        );
    }
}
 
Example #3
Source File: DLNAHeaders.java    From TVRemoteIME with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void log() {
    if (log.isLoggable(Level.FINE)) {
        super.log();
        if (parsedDLNAHeaders != null && parsedDLNAHeaders.size() > 0) {
            log.fine("########################## PARSED DLNA HEADERS ##########################");
            for (Map.Entry<DLNAHeader.Type, List<UpnpHeader>> entry : parsedDLNAHeaders.entrySet()) {
                log.log(Level.FINE, "=== TYPE: {0}", entry.getKey());
                for (UpnpHeader upnpHeader : entry.getValue()) {
                    log.log(Level.FINE, "HEADER: {0}", upnpHeader);
                }
            }
        }
        log.fine("####################################################################");
    }
}
 
Example #4
Source File: StreamClientImpl.java    From TVRemoteIME with GNU General Public License v2.0 6 votes vote down vote up
protected void applyRequestHeaders() {
    // Headers
    UpnpHeaders headers = getRequestMessage().getHeaders();
    if (log.isLoggable(Level.FINE))
        log.fine("Writing headers on HttpContentExchange: " + headers.size());
    // TODO Always add the Host header
    // TODO: ? setRequestHeader(UpnpHeader.Type.HOST.getHttpName(), );
    // Add the default user agent if not already set on the message
    if (!headers.containsKey(UpnpHeader.Type.USER_AGENT)) {
        setRequestHeader(
            UpnpHeader.Type.USER_AGENT.getHttpName(),
            getConfiguration().getUserAgentValue(
                getRequestMessage().getUdaMajorVersion(),
                getRequestMessage().getUdaMinorVersion())
        );
    }
    for (Map.Entry<String, List<String>> entry : headers.entrySet()) {
        for (String v : entry.getValue()) {
            String headerName = entry.getKey();
            if (log.isLoggable(Level.FINE))
                log.fine("Setting header '" + headerName + "': " + v);
            addRequestHeader(headerName, v);
        }
    }
}
 
Example #5
Source File: StreamClientImpl.java    From DroidDLNA with GNU General Public License v3.0 6 votes vote down vote up
protected void applyRequestHeaders() {
    // Headers
    UpnpHeaders headers = getRequestMessage().getHeaders();
    if (log.isLoggable(Level.FINE))
        log.fine("Writing headers on HttpContentExchange: " + headers.size());
    // TODO Always add the Host header
    // TODO: ? setRequestHeader(UpnpHeader.Type.HOST.getHttpName(), );
    // Add the default user agent if not already set on the message
    if (!headers.containsKey(UpnpHeader.Type.USER_AGENT)) {
        setRequestHeader(
            UpnpHeader.Type.USER_AGENT.getHttpName(),
            getConfiguration().getUserAgentValue(
                getRequestMessage().getUdaMajorVersion(),
                getRequestMessage().getUdaMinorVersion())
        );
    }
    for (Map.Entry<String, List<String>> entry : headers.entrySet()) {
        for (String v : entry.getValue()) {
            String headerName = entry.getKey();
            if (log.isLoggable(Level.FINE))
                log.fine("Setting header '" + headerName + "': " + v);
            addRequestHeader(headerName, v);
        }
    }
}
 
Example #6
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 #7
Source File: OutgoingNotificationRequest.java    From DroidDLNA with GNU General Public License v3.0 6 votes vote down vote up
protected OutgoingNotificationRequest(Location location, LocalDevice device, NotificationSubtype type) {
    super(
            new UpnpRequest(UpnpRequest.Method.NOTIFY),
            ModelUtil.getInetAddressByName(Constants.IPV4_UPNP_MULTICAST_GROUP),
            Constants.UPNP_MULTICAST_PORT
    );

    this.type = type;

    getHeaders().add(UpnpHeader.Type.MAX_AGE, new MaxAgeHeader(device.getIdentity().getMaxAgeSeconds()));
    getHeaders().add(UpnpHeader.Type.LOCATION, new LocationHeader(location.getURL()));

    getHeaders().add(UpnpHeader.Type.SERVER, new ServerHeader());
    getHeaders().add(UpnpHeader.Type.HOST, new HostHeader());
    getHeaders().add(UpnpHeader.Type.NTS, new NTSHeader(type));
}
 
Example #8
Source File: IncomingSearchResponse.java    From TVRemoteIME with GNU General Public License v2.0 6 votes vote down vote up
public UDN getRootDeviceUDN() {
    // This processes the headers as specified in UDA 1.0, tables in section 1.1.12

    UpnpHeader<UDN> udnHeader = getHeaders().getFirstHeader(UpnpHeader.Type.USN, USNRootDeviceHeader.class);
    if (udnHeader != null) return udnHeader.getValue();

    udnHeader = getHeaders().getFirstHeader(UpnpHeader.Type.USN, UDNHeader.class);
    if (udnHeader != null) return udnHeader.getValue();

    UpnpHeader<NamedDeviceType> deviceTypeHeader = getHeaders().getFirstHeader(UpnpHeader.Type.USN, DeviceUSNHeader.class);
    if (deviceTypeHeader != null) return deviceTypeHeader.getValue().getUdn();

    UpnpHeader<NamedServiceType> serviceTypeHeader = getHeaders().getFirstHeader(UpnpHeader.Type.USN, ServiceUSNHeader.class);
    if (serviceTypeHeader != null) return serviceTypeHeader.getValue().getUdn();

    return null;
}
 
Example #9
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 #10
Source File: ClingRouterFactory.java    From portmapper with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected List<IRouter> findRoutersInternal() throws RouterException {
    final UpnpServiceConfiguration config = new DefaultUpnpServiceConfiguration();
    final ClingRegistryListener clingRegistryListener = new ClingRegistryListener();
    final UpnpService upnpService = new UpnpServiceImpl(config, clingRegistryListener);
    shutdownServiceOnExit(upnpService);

    final UpnpHeader<?> searchType = new UDADeviceTypeHeader(ClingRegistryListener.IGD_DEVICE_TYPE);
    log.info("Start searching {} for device type {}", DISCOVERY_TIMEOUT, searchType);
    upnpService.getControlPoint().search(searchType, (int) DISCOVERY_TIMEOUT.toSeconds());
    return clingRegistryListener
            .waitForServiceFound(DISCOVERY_TIMEOUT) //
            .map(service -> (RemoteService) service)
            .map(service -> createRouter(service, upnpService)) //
            .collect(toList());
}
 
Example #11
Source File: StreamClientImpl.java    From DroidDLNA with GNU General Public License v3.0 6 votes vote down vote up
protected HttpParams getRequestParams(StreamRequestMessage requestMessage) {
    HttpParams localParams = new BasicHttpParams();

    localParams.setParameter(
        CoreProtocolPNames.PROTOCOL_VERSION,
        requestMessage.getOperation().getHttpMinorVersion() == 0 ? HttpVersion.HTTP_1_0 : HttpVersion.HTTP_1_1
    );

    // DefaultHttpClient adds HOST header automatically in its default processor

    // Add the default user agent if not already set on the message
    if (!requestMessage.getHeaders().containsKey(UpnpHeader.Type.USER_AGENT)) {
        HttpProtocolParams.setUserAgent(
            localParams,
            getConfiguration().getUserAgentValue(requestMessage.getUdaMajorVersion(), requestMessage.getUdaMinorVersion())
        );
    }

    return new DefaultedHttpParams(localParams, globalParams);
}
 
Example #12
Source File: OutgoingEventRequestMessage.java    From TVRemoteIME with GNU General Public License v2.0 6 votes vote down vote up
public OutgoingEventRequestMessage(GENASubscription subscription,
                                   URL callbackURL,
                                   UnsignedIntegerFourBytes sequence,
                                   Collection<StateVariableValue> values) {

    super(new UpnpRequest(UpnpRequest.Method.NOTIFY, callbackURL));

    getHeaders().add(UpnpHeader.Type.CONTENT_TYPE, new ContentTypeHeader());
    getHeaders().add(UpnpHeader.Type.NT, new NTEventHeader());
    getHeaders().add(UpnpHeader.Type.NTS, new NTSHeader(NotificationSubtype.PROPCHANGE));
    getHeaders().add(UpnpHeader.Type.SID, new SubscriptionIdHeader(subscription.getSubscriptionId()));

    // Important! Pass by value so that we can safely increment it afterwards and before this is send!
    getHeaders().add(UpnpHeader.Type.SEQ, new EventSequenceHeader(sequence.getValue()));

    this.stateVariableValues = values;
}
 
Example #13
Source File: StreamClientImpl.java    From TVRemoteIME with GNU General Public License v2.0 6 votes vote down vote up
protected HttpParams getRequestParams(StreamRequestMessage requestMessage) {
    HttpParams localParams = new BasicHttpParams();

    localParams.setParameter(
        CoreProtocolPNames.PROTOCOL_VERSION,
        requestMessage.getOperation().getHttpMinorVersion() == 0 ? HttpVersion.HTTP_1_0 : HttpVersion.HTTP_1_1
    );

    // DefaultHttpClient adds HOST header automatically in its default processor

    // Add the default user agent if not already set on the message
    if (!requestMessage.getHeaders().containsKey(UpnpHeader.Type.USER_AGENT)) {
        HttpProtocolParams.setUserAgent(
            localParams,
            getConfiguration().getUserAgentValue(requestMessage.getUdaMajorVersion(), requestMessage.getUdaMinorVersion())
        );
    }

    return new DefaultedHttpParams(localParams, globalParams);
}
 
Example #14
Source File: OutgoingSearchResponse.java    From DroidDLNA with GNU General Public License v3.0 6 votes vote down vote up
public OutgoingSearchResponse(IncomingDatagramMessage request,
                              Location location,
                              LocalDevice device) {

    super(new UpnpResponse(UpnpResponse.Status.OK), request.getSourceAddress(), request.getSourcePort());

    getHeaders().add(UpnpHeader.Type.MAX_AGE, new MaxAgeHeader(device.getIdentity().getMaxAgeSeconds()));
    getHeaders().add(UpnpHeader.Type.LOCATION, new LocationHeader(location.getURL()));
    getHeaders().add(UpnpHeader.Type.SERVER, new ServerHeader());
    getHeaders().add(UpnpHeader.Type.EXT, new EXTHeader());

    if (location.getNetworkAddress().getHardwareAddress() != null) {
        getHeaders().add(
                UpnpHeader.Type.EXT_IFACE_MAC,
                 new InterfaceMacHeader(location.getNetworkAddress().getHardwareAddress())
        );
    }
}
 
Example #15
Source File: OutgoingRenewalRequestMessage.java    From DroidDLNA with GNU General Public License v3.0 6 votes vote down vote up
public OutgoingRenewalRequestMessage(RemoteGENASubscription subscription,
                                     UpnpHeaders extraHeaders) {

    super(UpnpRequest.Method.SUBSCRIBE, subscription.getEventSubscriptionURL());

    getHeaders().add(
            UpnpHeader.Type.SID,
            new SubscriptionIdHeader(subscription.getSubscriptionId())
    );

    getHeaders().add(
            UpnpHeader.Type.TIMEOUT,
            new TimeoutHeader(subscription.getRequestedDurationSeconds())
    );

    if (extraHeaders != null)
        getHeaders().putAll(extraHeaders);
}
 
Example #16
Source File: ProtocolFactoryImpl.java    From DroidDLNA with GNU General Public License v3.0 6 votes vote down vote up
protected boolean isSupportedServiceAdvertisement(IncomingDatagramMessage message) {
    ServiceType[] exclusiveServiceTypes = getUpnpService().getConfiguration().getExclusiveServiceTypes();
    if (exclusiveServiceTypes == null) return false; // Discovery is disabled
    if (exclusiveServiceTypes.length == 0) return true; // Any advertisement is fine

    String usnHeader = message.getHeaders().getFirstHeader(UpnpHeader.Type.USN.getHttpName());
    if (usnHeader == null) return false; // Not a service advertisement, drop it

    try {
        NamedServiceType nst = NamedServiceType.valueOf(usnHeader);
        for (ServiceType exclusiveServiceType : exclusiveServiceTypes) {
            if (nst.getServiceType().implementsVersion(exclusiveServiceType))
                return true;
        }
    } catch (InvalidValueException ex) {
        log.finest("Not a named service type header value: " + usnHeader);
    }
    log.fine("Service advertisement not supported, dropping it: " + usnHeader);
    return false;
}
 
Example #17
Source File: OutgoingNotificationRequestRootDevice.java    From DroidDLNA with GNU General Public License v3.0 5 votes vote down vote up
public OutgoingNotificationRequestRootDevice(Location location, LocalDevice device, NotificationSubtype type) {
    super(location, device, type);

    getHeaders().add(UpnpHeader.Type.NT, new RootDeviceHeader());
    getHeaders().add(UpnpHeader.Type.USN, new USNRootDeviceHeader(device.getIdentity().getUdn()));

    if (location.getNetworkAddress().getHardwareAddress() != null) {
        getHeaders().add(
                UpnpHeader.Type.EXT_IFACE_MAC,
                 new InterfaceMacHeader(location.getNetworkAddress().getHardwareAddress())
        );
    }
}
 
Example #18
Source File: IncomingSearchResponse.java    From TVRemoteIME with GNU General Public License v2.0 5 votes vote down vote up
public byte[] getInterfaceMacHeader() {
    InterfaceMacHeader header = getHeaders().getFirstHeader(UpnpHeader.Type.EXT_IFACE_MAC, InterfaceMacHeader.class);
    if (header != null) {
        return header.getValue();
    }
    return null;
}
 
Example #19
Source File: IncomingNotificationRequest.java    From DroidDLNA with GNU General Public License v3.0 5 votes vote down vote up
public URL getLocationURL() {
    LocationHeader header = getHeaders().getFirstHeader(UpnpHeader.Type.LOCATION, LocationHeader.class);
    if (header != null) {
        return header.getValue();
    }
    return null;
}
 
Example #20
Source File: UpnpHeaders.java    From TVRemoteIME with GNU General Public License v2.0 5 votes vote down vote up
public <H extends UpnpHeader> H getFirstHeader(UpnpHeader.Type type, Class<H> subtype) {
    UpnpHeader[] headers = getAsArray(type);
    if (headers.length == 0) return null;

    for (UpnpHeader header : headers) {
        if (subtype.isAssignableFrom(header.getClass())) {
            return (H) header;
        }
    }
    return null;
}
 
Example #21
Source File: IncomingEventRequestMessage.java    From TVRemoteIME with GNU General Public License v2.0 5 votes vote down vote up
/**
 * @return <code>true</code> if this message has an NT header, and NTS header
 *         with value {@link org.fourthline.cling.model.types.NotificationSubtype#PROPCHANGE}.
 */
public boolean hasValidNotificationHeaders() {
    NTEventHeader ntHeader = getHeaders().getFirstHeader(UpnpHeader.Type.NT, NTEventHeader.class);
    NTSHeader ntsHeader = getHeaders().getFirstHeader(UpnpHeader.Type.NTS, NTSHeader.class);
    return ntHeader != null && ntHeader.getValue() != null
            && ntsHeader != null && ntsHeader.getValue().equals(NotificationSubtype.PROPCHANGE);

}
 
Example #22
Source File: IncomingSearchResponse.java    From TVRemoteIME with GNU General Public License v2.0 5 votes vote down vote up
public Integer getMaxAge() {
    MaxAgeHeader header = getHeaders().getFirstHeader(UpnpHeader.Type.MAX_AGE, MaxAgeHeader.class);
    if (header != null) {
        return header.getValue();
    }
    return null;
}
 
Example #23
Source File: OutgoingSearchResponseRootDevice.java    From TVRemoteIME with GNU General Public License v2.0 5 votes vote down vote up
public OutgoingSearchResponseRootDevice(IncomingDatagramMessage request,
                                        Location location,
                                        LocalDevice device) {
    super(request, location, device);

    getHeaders().add(UpnpHeader.Type.ST, new RootDeviceHeader());
    getHeaders().add(UpnpHeader.Type.USN, new USNRootDeviceHeader(device.getIdentity().getUdn()));
}
 
Example #24
Source File: IncomingNotificationRequest.java    From TVRemoteIME with GNU General Public License v2.0 5 votes vote down vote up
public URL getLocationURL() {
    LocationHeader header = getHeaders().getFirstHeader(UpnpHeader.Type.LOCATION, LocationHeader.class);
    if (header != null) {
        return header.getValue();
    }
    return null;
}
 
Example #25
Source File: IncomingEventRequestMessage.java    From DroidDLNA with GNU General Public License v3.0 5 votes vote down vote up
/**
 * @return <code>true</code> if this message has an NT header, and NTS header
 *         with value {@link org.fourthline.cling.model.types.NotificationSubtype#PROPCHANGE}.
 */
public boolean hasValidNotificationHeaders() {
    NTEventHeader ntHeader = getHeaders().getFirstHeader(UpnpHeader.Type.NT, NTEventHeader.class);
    NTSHeader ntsHeader = getHeaders().getFirstHeader(UpnpHeader.Type.NTS, NTSHeader.class);
    return ntHeader != null && ntHeader.getValue() != null
            && ntsHeader != null && ntsHeader.getValue().equals(NotificationSubtype.PROPCHANGE);

}
 
Example #26
Source File: IncomingNotificationRequest.java    From TVRemoteIME with GNU General Public License v2.0 5 votes vote down vote up
public Integer getMaxAge() {
    MaxAgeHeader header = getHeaders().getFirstHeader(UpnpHeader.Type.MAX_AGE, MaxAgeHeader.class);
    if (header != null) {
        return header.getValue();
    }
    return null;
}
 
Example #27
Source File: OutgoingSearchResponseDeviceType.java    From TVRemoteIME with GNU General Public License v2.0 5 votes vote down vote up
public OutgoingSearchResponseDeviceType(IncomingDatagramMessage request,
                                        Location location,
                                        LocalDevice device) {
    super(request, location, device);

    getHeaders().add(UpnpHeader.Type.ST, new DeviceTypeHeader(device.getType()));
    getHeaders().add(UpnpHeader.Type.USN, new DeviceUSNHeader(device.getIdentity().getUdn(), device.getType()));
}
 
Example #28
Source File: IncomingEventRequestMessage.java    From DroidDLNA with GNU General Public License v3.0 5 votes vote down vote up
/**
 * @return <code>true</code> if this message as an NT and NTS header.
 */
public boolean hasNotificationHeaders() {
    UpnpHeader ntHeader = getHeaders().getFirstHeader(UpnpHeader.Type.NT);
    UpnpHeader ntsHeader = getHeaders().getFirstHeader(UpnpHeader.Type.NTS);
    return ntHeader != null && ntHeader.getValue() != null
            && ntsHeader != null && ntsHeader.getValue() != null;
}
 
Example #29
Source File: MockUpnpService.java    From DroidDLNA with GNU General Public License v3.0 5 votes vote down vote up
@Override
public SendingSearch createSendingSearch(UpnpHeader searchTarget, int mxSeconds) {
    return new SendingSearch(getUpnpService(), searchTarget, mxSeconds) {
        @Override
        public int getBulkIntervalMilliseconds() {
            return 0; // Don't wait
        }
    };
}
 
Example #30
Source File: OutgoingActionResponseMessage.java    From DroidDLNA with GNU General Public License v3.0 5 votes vote down vote up
protected void addHeaders() {
    getHeaders().add(
            UpnpHeader.Type.CONTENT_TYPE,
            new ContentTypeHeader(ContentTypeHeader.DEFAULT_CONTENT_TYPE_UTF8)
    );
    getHeaders().add(
            UpnpHeader.Type.SERVER,
            new ServerHeader()
    );
    getHeaders().add(
            UpnpHeader.Type.EXT,
            new EXTHeader()
    );
}