/** * Returns the Location-Path and Location-Query options as relative URI string. * @return the Location-* as string */ public String getLocationString() { StringBuilder builder = new StringBuilder(); builder.append("/"); builder.append(getLocationPathString()); if (getLocationQueryCount()>0) { builder.append("?"); builder.append(getLocationQueryString()); } return builder.toString(); }
/** * Returns the Location-Path and Location-Query options as relative URI string. * @return the Location-* as string */ public String getLocationString() { StringBuilder builder = new StringBuilder(); builder.append("/"); builder.append(getLocationPathString()); if (getLocationQueryCount()>0) { builder.append("?"); builder.append(getLocationQueryString()); } return builder.toString(); }
/** * Checks for Location-Path option. * * @param response * the response * @return true, if successful */ protected boolean hasLocation(Response response) { // boolean success = // response.hasOption(OptionNumberRegistry.LOCATION_PATH); boolean success = response.getOptions().getLocationPathCount() > 0; if (!success) { System.out.println("FAIL: Response without Location"); } else { System.out.printf("PASS: Location (%s)\n", response .getOptions().getLocationPathString()); } return success; }
@Test public void testLocationOptions() { OptionSet options = new OptionSet(); options.setLocationPath("/foo/bar"); Assert.assertEquals("Uri-Path", "foo/bar", options.getLocationPathString()); options.setLocationPath("foo/bar"); Assert.assertEquals("Uri-Path", "foo/bar", options.getLocationPathString()); options.setLocationPath("//foo/bar"); Assert.assertEquals("Uri-Path", "/foo/bar", options.getLocationPathString()); options.setLocationPath("/foo//bar"); Assert.assertEquals("Uri-Path", "foo//bar", options.getLocationPathString()); options.clearLocationPath(); options.addLocationPath("foo"); options.addLocationPath("bar"); Assert.assertEquals("Uri-Path", "foo/bar", options.getLocationPathString()); options.clearLocationPath(); options.addLocationPath("foo"); options.addLocationPath(""); options.addLocationPath("bar"); Assert.assertEquals("Uri-Path", "foo//bar", options.getLocationPathString()); }
String contentLocation = options.getLocationPathString(); if (null != contentLocation && (! contentLocation.isEmpty())) { onem2mResponse.setPrimitive(ResponsePrimitive.CONTENT_LOCATION,
@Override public void visit(CreateRequest request) { if (coapResponse.isError()) { // handle error response: lwM2mresponse = new CreateResponse(toLwM2mResponseCode(coapResponse.getCode()), null, coapResponse.getPayloadString(), coapResponse); } else if (coapResponse.getCode() == org.eclipse.californium.core.coap.CoAP.ResponseCode.CREATED) { // handle success response: lwM2mresponse = new CreateResponse(ResponseCode.CREATED, coapResponse.getOptions().getLocationPathString(), null, coapResponse); } else { // handle unexpected response: handleUnexpectedResponseCode(registration.getEndpoint(), request, coapResponse); } }
@Override public void visit(final CreateRequest request) { switch (coapResponse.getCode()) { case CREATED: lwM2mresponse = new CreateResponse(fromCoapCode(coapResponse.getCode().value), coapResponse.getOptions() .getLocationPathString()); break; case BAD_REQUEST: case UNAUTHORIZED: case NOT_FOUND: case METHOD_NOT_ALLOWED: lwM2mresponse = new CreateResponse(fromCoapCode(coapResponse.getCode().value)); break; default: handleUnexpectedResponseCode(client.getEndpoint(), coapRequest, coapResponse); } }
@Test public void testUTF8Encoding() { Response response = new Response(ResponseCode.CONTENT); response.setType(Type.NON); response.setMID(expectedMid); response.setToken(new byte[] {}); response.getOptions().addLocationPath("ᚠᛇᚻ᛫ᛒᛦᚦ᛫ᚠᚱᚩᚠᚢᚱ᛫ᚠᛁᚱᚪ᛫ᚷᛖᚻᚹᛦᛚᚳᚢᛗ").addLocationPath("γλώσσα") .addLocationPath("пустынных").addLocationQuery("ვეპხის=யாமறிந்த").addLocationQuery("⠊⠀⠉⠁⠝=⠑⠁⠞⠀⠛⠇⠁⠎⠎"); response.setPayload("⠊⠀⠉⠁⠝⠀⠑⠁⠞⠀⠛⠇⠁⠎⠎⠀⠁⠝⠙⠀⠊⠞⠀⠙⠕⠑⠎⠝⠞⠀⠓⠥⠗⠞⠀⠍⠑"); RawData rawData = serializer.serializeResponse(response); Response result = (Response) parser.parseMessage(rawData); assertEquals("ᚠᛇᚻ᛫ᛒᛦᚦ᛫ᚠᚱᚩᚠᚢᚱ᛫ᚠᛁᚱᚪ᛫ᚷᛖᚻᚹᛦᛚᚳᚢᛗ/γλώσσα/пустынных", response.getOptions().getLocationPathString()); assertEquals("ვეპხის=யாமறிந்த&⠊⠀⠉⠁⠝=⠑⠁⠞⠀⠛⠇⠁⠎⠎", response.getOptions().getLocationQueryString()); assertEquals("⠊⠀⠉⠁⠝⠀⠑⠁⠞⠀⠛⠇⠁⠎⠎⠀⠁⠝⠙⠀⠊⠞⠀⠙⠕⠑⠎⠝⠞⠀⠓⠥⠗⠞⠀⠍⠑", result.getPayloadString()); assertEquals(response.getMID(), result.getMID()); } }