Request extends Message { public final Request setObserve() { if (!CoAP.isObservable(code)) { throw new IllegalStateException("observe option can only be set on a GET or FETCH request"); } getOptions().setObserve(0); return this; } Request(Code code);  Request(Code code, Type type); Code getCode(); @Override int getRawCode(); String getScheme(); void setScheme(String scheme); boolean isMulticast(); @Override boolean isIntendedPayload(); @Override Request setPayload(String payload); @Override Request setPayload(byte[] payload); Request setProxyUri(String proxyUri); boolean hasProxyURI(); Request setProxyScheme(String proxyScheme); Request setURI(final String uri); Request setURI(final URI uri); Request setOptions(final URI uri); void setUriIsApplied(); boolean hasURI(); String getURI(); @Deprecated InetAddress getDestination(); @Deprecated Message setDestination(InetAddress destination); @Deprecated int getDestinationPort(); @Deprecated Message setDestinationPort(int destinationPort); @Deprecated Principal getSenderIdentity(); @Deprecated void prepareDestinationContext(); @Override Request setDestinationContext(EndpointContext peerContext); Request send(); Request send(Endpoint endpoint); final Request setObserve(); final boolean isObserve(); final Request setObserveCancel(); final boolean isObserveCancel(); synchronized Response getResponse(); void setResponse(Response response); Response waitForResponse(); Response waitForResponse(long timeout); @Override void setTimedOut(boolean timedOut); @Override void setCanceled(boolean canceled); @Override void setRejected(boolean rejected); @Override void setSendError(Throwable sendError); Throwable getOnResponseError(); void setOnResponseError(Throwable cause); Map<String, String> getUserContext(); Request setUserContext(Map<String, String> userContext); @Override String toString(); static Request newGet(); static Request newFetch(); static Request newPost(); static Request newPut(); static Request newPatch(); static Request newIPatch(); static Request newDelete();  }
@Test public void setObserveFailsForNonGetRequest() { Code[] illegalCodes = new Code[]{ Code.PATCH, Code.DELETE, Code.POST, Code.PUT }; for (Code code : illegalCodes) { try { Request req = new Request(code); req.setObserve(); fail("should not be able to set observe option on " + code + " request"); } catch (IllegalStateException e) { } } }