Search in sources :

Example 1 with OtherOption

use of nl.teslanet.mule.connectors.coap.api.options.OtherOption in project mule-coap-connector by teslanet-nl.

the class MessageUtils method copyOptions.

/**
 * Copy options from {@link ResponseOptions} to {@link OptionSet}.
 * @param responseOptions to copy from
 * @param optionSet to copy to
 * @throws InternalInvalidOptionValueException
 * @throws InvalidETagException when an option containes invalid ETag value
 * @throws IOException when an option stream throws an error.
 */
public static void copyOptions(ResponseOptions responseOptions, OptionSet optionSet, TransformationService transformationService) throws InternalInvalidOptionValueException, IOException, InvalidETagException {
    if (responseOptions.getEtag() != null) {
        ETag etag = MessageUtils.toETag(responseOptions.getEtag(), transformationService);
        if (etag.isEmpty())
            throw new InternalInvalidOptionValueException("ETag", "empty etag is not valid");
        optionSet.addETag(etag.getValue());
    }
    if (responseOptions.getContentFormat() != null) {
        optionSet.setContentFormat(responseOptions.getContentFormat());
    }
    if (responseOptions.getMaxAge() != null) {
        optionSet.setMaxAge(responseOptions.getMaxAge());
    }
    if (responseOptions.getLocationPath() != null) {
        optionSet.setLocationPath(responseOptions.getLocationPath());
    }
    if (responseOptions.getLocationQuery() != null) {
        for (AbstractQueryParam param : responseOptions.getLocationQuery()) {
            optionSet.addLocationQuery(param.toString());
        }
    }
    if (responseOptions.getResponseSize() != null) {
        optionSet.setSize2(responseOptions.getResponseSize());
    }
    if (responseOptions.getAcceptableRequestSize() != null) {
        optionSet.setSize1(responseOptions.getAcceptableRequestSize());
    }
    for (OtherOption otherOption : responseOptions.getOtherResponseOptions()) {
        try {
            optionSet.addOption(new Option(otherOption.getNumber(), toBytes(otherOption.getValue(), transformationService)));
        } catch (InternalInvalidByteArrayValueException e) {
            throw new InternalInvalidOptionValueException("Other-Option", "Number { " + otherOption.getNumber() + " }", e);
        }
    }
}
Also used : OtherOption(nl.teslanet.mule.connectors.coap.api.options.OtherOption) ETag(nl.teslanet.mule.connectors.coap.api.options.ETag) InternalInvalidByteArrayValueException(nl.teslanet.mule.connectors.coap.internal.exceptions.InternalInvalidByteArrayValueException) AbstractQueryParam(nl.teslanet.mule.connectors.coap.api.query.AbstractQueryParam) BlockOption(org.eclipse.californium.core.coap.BlockOption) OtherOption(nl.teslanet.mule.connectors.coap.api.options.OtherOption) Option(org.eclipse.californium.core.coap.Option) InternalInvalidOptionValueException(nl.teslanet.mule.connectors.coap.internal.exceptions.InternalInvalidOptionValueException)

Aggregations

ETag (nl.teslanet.mule.connectors.coap.api.options.ETag)1 OtherOption (nl.teslanet.mule.connectors.coap.api.options.OtherOption)1 AbstractQueryParam (nl.teslanet.mule.connectors.coap.api.query.AbstractQueryParam)1 InternalInvalidByteArrayValueException (nl.teslanet.mule.connectors.coap.internal.exceptions.InternalInvalidByteArrayValueException)1 InternalInvalidOptionValueException (nl.teslanet.mule.connectors.coap.internal.exceptions.InternalInvalidOptionValueException)1 BlockOption (org.eclipse.californium.core.coap.BlockOption)1 Option (org.eclipse.californium.core.coap.Option)1