Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support of Option without value in Uri-Query. #45

Closed
sbernard31 opened this issue Apr 14, 2023 · 5 comments
Closed

Add support of Option without value in Uri-Query. #45

sbernard31 opened this issue Apr 14, 2023 · 5 comments

Comments

@sbernard31
Copy link
Collaborator

coapRequest.options().getUriQueryMap() seems to only support Option in the form of a "key=value" pair.
It should also support more simple form like "key" without value.

(See more detailed at : #27 (comment))

@szysas
Copy link
Collaborator

szysas commented Apr 19, 2023

Currently empty query value can be placed in such way: field1=value1&field2=&field3=, so equal sign is needed. Would that work with Leshan?

@sbernard31
Copy link
Collaborator Author

Nope that does not match the LWM2M specification 😬

See for Q option :
/rd?ep={Endpoint Client Name}&lt={Lifetime}&lwm2m={version}&b={binding}&Q&sms={MSISDN}

@sbernard31
Copy link
Collaborator Author

sbernard31 commented Apr 19, 2023

Currently I parse UriQuery by myself using :

// TODO remove this class when https://github.com/open-coap/java-coap/issues/45 will be fixed.
public class QueryUtil {
    public static Map<String, String> parseUriQuery(String uriQuery) {
        if (uriQuery == null || uriQuery.length() == 0) {
            return Collections.emptyMap();
        }
        Map<String, String> result = new LinkedHashMap<>();
        String[] params = uriQuery.substring(uriQuery.indexOf('?') + 1).split("&");

        for (String prm : params) {
            String[] p = prm.split("=", 2);
            if (p.length == 2) {
                result.put(p[0], p[1]);
            } else if (p.length == 1) {
                result.put(p[0], null);
            } else {
                throw new IllegalArgumentException();
            }
        }
        return result;
    }
}
for (Entry<String, String> entry : QueryUtil.parseUriQuery(coapRequest.options().getUriQuery())
                    .entrySet()) {
 ... .. 
}

@szysas
Copy link
Collaborator

szysas commented Apr 24, 2023

There is release v6.12.0 that contains implementation for this ticket, can we close it?

@sbernard31
Copy link
Collaborator Author

Tested with v6.12.0, my integrations tests pass now without my "HACK" ✔️

Thx for adding this 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants