
ch.ethz.inf.vs.californium.examples.resources.LargeResource Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of cf-server Show documentation
Show all versions of cf-server Show documentation
Californium (Cf) example server
The newest version!
/*******************************************************************************
* Copyright (c) 2014, Institute for Pervasive Computing, ETH Zurich.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the Institute nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* This file is part of the Californium (Cf) CoAP framework.
******************************************************************************/
package ch.ethz.inf.vs.californium.examples.resources;
import ch.ethz.inf.vs.californium.server.resources.CoapExchange;
import ch.ethz.inf.vs.californium.server.resources.ResourceBase;
/**
* This class implements a resource that returns a larger amount of
* data on GET requests in order to test blockwise transfers.
*/
public class LargeResource extends ResourceBase {
private String payload = getPayload();
public LargeResource() {
this("large");
}
public LargeResource(String name) {
super(name);
getAttributes().setTitle("This is a large resource for testing block-wise transfer");
getAttributes().addResourceType("BlockWiseTransferTester");
}
@Override
public void handleGET(CoapExchange exchange) {
exchange.respond(payload);
}
@Override
public void handlePOST(CoapExchange exchange) {
exchange.respond(payload);
}
@Override
public void handlePUT(CoapExchange exchange) {
exchange.respond(payload);
}
private String getPayload() {
StringBuilder builder = new StringBuilder();
builder.append("/-------------------------------------------------------------\\\n");
builder.append("| RESOURCE BLOCK NO. 1 OF 8 |\n");
builder.append("| [each line contains 64 bytes] |\n");
builder.append("\\-------------------------------------------------------------/\n");
builder.append("/-------------------------------------------------------------\\\n");
builder.append("| RESOURCE BLOCK NO. 2 OF 8 |\n");
builder.append("| [each line contains 64 bytes] |\n");
builder.append("\\-------------------------------------------------------------/\n");
builder.append("/-------------------------------------------------------------\\\n");
builder.append("| RESOURCE BLOCK NO. 3 OF 8 |\n");
builder.append("| [each line contains 64 bytes] |\n");
builder.append("\\-------------------------------------------------------------/\n");
builder.append("/-------------------------------------------------------------\\\n");
builder.append("| RESOURCE BLOCK NO. 4 OF 8 |\n");
builder.append("| [each line contains 64 bytes] |\n");
builder.append("\\-------------------------------------------------------------/\n");
builder.append("/-------------------------------------------------------------\\\n");
builder.append("| RESOURCE BLOCK NO. 5 OF 8 |\n");
builder.append("| [each line contains 64 bytes] |\n");
builder.append("\\-------------------------------------------------------------/\n");
builder.append("/-------------------------------------------------------------\\\n");
builder.append("| RESOURCE BLOCK NO. 6 OF 8 |\n");
builder.append("| [each line contains 64 bytes] |\n");
builder.append("\\-------------------------------------------------------------/\n");
builder.append("/-------------------------------------------------------------\\\n");
builder.append("| RESOURCE BLOCK NO. 7 OF 8 |\n");
builder.append("| [each line contains 64 bytes] |\n");
builder.append("\\-------------------------------------------------------------/\n");
builder.append("/-------------------------------------------------------------\\\n");
builder.append("| RESOURCE BLOCK NO. 8 OF 8 |\n");
builder.append("| [each line contains 64 bytes] |\n");
builder.append("\\-------------------------------------------------------------/\n");
return builder.toString();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy