本文整理汇总了Java中org.eclipse.californium.core.coap.Response.getPayload方法的典型用法代码示例。如果您正苦于以下问题:Java Response.getPayload方法的具体用法?Java Response.getPayload怎么用?Java Response.getPayload使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.californium.core.coap.Response
的用法示例。
在下文中一共展示了Response.getPayload方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testSuccessPlaintext
import org.eclipse.californium.core.coap.Response; //导入方法依赖的package包/类
@Test
public void testSuccessPlaintext() throws Exception {
Request request = Request.newPost();
request.setURI("coap://localhost:"+config.getCoapPort()+"/"+Constants.TOKEN_RESOURCE);
TokenRequest req = new TokenRequest();
req.setGrantType("client_credentials");
req.setAud(config.getResourceServers().get(0).getAud());
req.setClientID(config.getClients().get(0).getClient_id());
req.setClientSecret(config.getClients().get(0).getClient_secret());
req.setScopes(config.getResourceServers().get(0).getScopes());
request.getOptions().setContentFormat(MediaTypeRegistry.APPLICATION_JSON);
request.setPayload(req.toPayload(MediaTypeRegistry.APPLICATION_JSON));
Response response = request.send().waitForResponse();
TokenResponse tokenResponse = new TokenResponse(response.getPayload(), MediaTypeRegistry.APPLICATION_JSON);
TestUtils.validateToken(tokenResponse.getAccessToken().getBytes(), config.getResourceServers().get(0).getAud(), MediaTypeRegistry.APPLICATION_JSON);
}
示例2: testSuccessClientGeneratedECKeys
import org.eclipse.californium.core.coap.Response; //导入方法依赖的package包/类
@Test
public void testSuccessClientGeneratedECKeys() throws Exception {
JsonWebKey popKey = EcJwkGenerator.generateJwk(EllipticCurves.P256);
popKey.setKeyId("testkid");
TokenRequest req = new TokenRequest();
req.setGrantType("client_credentials");
req.setAud(config.getResourceServers().get(0).getAud());
req.setClientID(config.getClients().get(0).getClient_id());
req.setClientSecret(config.getClients().get(0).getClient_secret());
req.setScopes(config.getResourceServers().get(0).getScopes());
req.setKey(popKey);
Response response = DTLSUtils.dtlsPSKRequest("coaps://localhost:"+config.getCoapsPort()+"/"+Constants.TOKEN_RESOURCE, "POST", req.toPayload(MediaTypeRegistry.APPLICATION_JSON), MediaTypeRegistry.APPLICATION_JSON, config.getPskIdentity(), config.getPskKey().getBytes());
Assert.assertEquals(ResponseCode.CONTENT, response.getCode());
TokenResponse tokenResponse = new TokenResponse(response.getPayload(), MediaTypeRegistry.APPLICATION_JSON);
TestUtils.validateToken(tokenResponse.getAccessToken().getBytes(), config.getResourceServers().get(0).getAud(), MediaTypeRegistry.APPLICATION_JSON);
}
示例3: testSuccessClientGeneratedRSAKeys
import org.eclipse.californium.core.coap.Response; //导入方法依赖的package包/类
@Test
public void testSuccessClientGeneratedRSAKeys() throws Exception {
JsonWebKey popKey = RsaJwkGenerator.generateJwk(2048);
popKey.setKeyId("testkid");
TokenRequest req = new TokenRequest();
req.setGrantType("client_credentials");
req.setAud(config.getResourceServers().get(0).getAud());
req.setClientID(config.getClients().get(0).getClient_id());
req.setClientSecret(config.getClients().get(0).getClient_secret());
req.setScopes(config.getResourceServers().get(0).getScopes());
req.setKey(popKey);
Response response = DTLSUtils.dtlsPSKRequest("coaps://localhost:"+config.getCoapsPort()+"/"+Constants.TOKEN_RESOURCE, "POST", req.toPayload(MediaTypeRegistry.APPLICATION_JSON), MediaTypeRegistry.APPLICATION_JSON, config.getPskIdentity(), config.getPskKey().getBytes());
Assert.assertEquals(ResponseCode.CONTENT, response.getCode());
TokenResponse tokenResponse = new TokenResponse(response.getPayload(), MediaTypeRegistry.APPLICATION_JSON);
TestUtils.validateToken(tokenResponse.getAccessToken().getBytes(), config.getResourceServers().get(0).getAud(), MediaTypeRegistry.APPLICATION_JSON);
}
示例4: testScopes
import org.eclipse.californium.core.coap.Response; //导入方法依赖的package包/类
@Test
public void testScopes() throws Exception {
JsonWebKey jwk;
jwk = EcJwkGenerator.generateJwk(EllipticCurves.P256);
jwk.setKeyId("testkid");
TokenRequest req = new TokenRequest();
req.setGrantType("client_credentials");
req.setAud(config.getResourceServers().get(0).getAud());
req.setClientID(config.getClients().get(0).getClient_id());
req.setClientSecret(config.getClients().get(0).getClient_secret());
req.setScopes(config.getResourceServers().get(0).getScopes());
req.setKey(jwk);
Response response = DTLSUtils.dtlsPSKRequest("coaps://localhost:"+config.getCoapsPort()+"/"+Constants.TOKEN_RESOURCE, "POST", req.toPayload(MediaTypeRegistry.APPLICATION_JSON), MediaTypeRegistry.APPLICATION_JSON, config.getPskIdentity(), config.getPskKey().getBytes());
TokenResponse tokenResponse = new TokenResponse(response.getPayload(), MediaTypeRegistry.APPLICATION_JSON);
TestUtils.validateToken(tokenResponse.getAccessToken().getBytes(), config.getResourceServers().get(0).getAud(), MediaTypeRegistry.APPLICATION_JSON);
}
示例5: decodeCoapResponse
import org.eclipse.californium.core.coap.Response; //导入方法依赖的package包/类
private LwM2mNode decodeCoapResponse(LwM2mPath path, Response coapResponse, LwM2mRequest<?> request,
String endpoint) {
// Get content format
ContentFormat contentFormat = null;
if (coapResponse.getOptions().hasContentFormat()) {
contentFormat = ContentFormat.fromCode(coapResponse.getOptions().getContentFormat());
}
// Decode payload
try {
return decoder.decode(coapResponse.getPayload(), contentFormat, path, model);
} catch (CodecException e) {
if (LOG.isDebugEnabled()) {
byte[] payload = coapResponse.getPayload() == null ? new byte[0] : coapResponse.getPayload();
LOG.debug(
String.format("Unable to decode response payload of request [%s] from client [%s] [payload:%s]",
request, endpoint, Hex.encodeHexString(payload)));
}
throw new InvalidResponseException(e, "Unable to decode response payload of request [%s] from client [%s]",
request, endpoint);
}
}
示例6: callBadRequestEndpointCall
import org.eclipse.californium.core.coap.Response; //导入方法依赖的package包/类
private void callBadRequestEndpointCall(byte[] payload, String expectedError, int contentType) throws Exception {
Response response = DTLSUtils.dtlsPSKRequest("coaps://localhost:"+config.getCoapsPort()+"/"+Constants.TOKEN_RESOURCE, "POST", payload, contentType, config.getPskIdentity(), config.getPskKey().getBytes());
Assert.assertEquals(response.getCode(), ResponseCode.BAD_REQUEST);
// take request and turn it into a TokenRequest object
byte[] error = response.getPayload();
ErrorResponse errorResp = new ErrorResponse(error, MediaTypeRegistry.APPLICATION_JSON);
Assert.assertEquals(expectedError, errorResp.getError());
}
示例7: testSuccess
import org.eclipse.californium.core.coap.Response; //导入方法依赖的package包/类
@Test
public void testSuccess() throws Exception {
// first create a token
JsonWebKey jwk;
jwk = EcJwkGenerator.generateJwk(EllipticCurves.P256);
jwk.setKeyId("testkid");
TokenRequest createReq = new TokenRequest();
createReq.setGrantType("client_credentials");
createReq.setAud(config.getResourceServers().get(0).getAud());
createReq.setClientID(config.getClients().get(0).getClient_id());
createReq.setClientSecret(config.getClients().get(0).getClient_secret());
createReq.setScopes(config.getResourceServers().get(0).getScopes());
createReq.setKey(jwk);
Response createResponse = DTLSUtils.dtlsPSKRequest("coaps://localhost:"+config.getCoapsPort()+"/"+Constants.TOKEN_RESOURCE, "POST", createReq.toPayload(MediaTypeRegistry.APPLICATION_JSON), MediaTypeRegistry.APPLICATION_JSON, config.getPskIdentity(), config.getPskKey().getBytes());
Assert.assertEquals(ResponseCode.CONTENT, createResponse.getCode());
TokenResponse tokenResponse = new TokenResponse(createResponse.getPayload(), MediaTypeRegistry.APPLICATION_JSON);
// see of token is valid
IntrospectRequest introspectionReq = new IntrospectRequest();
introspectionReq.setToken(tokenResponse.getAccessToken());
introspectionReq.setClientID(config.getClients().get(0).getClient_id());
introspectionReq.setClientSecret(config.getClients().get(0).getClient_secret());
Response introspectionResponse = DTLSUtils.dtlsPSKRequest("coaps://localhost:"+config.getCoapsPort()+"/"+Constants.INSTROSPECTION_RESOURCE, "POST", introspectionReq.toPayload(MediaTypeRegistry.APPLICATION_JSON), MediaTypeRegistry.APPLICATION_JSON, config.getPskIdentity(), config.getPskKey().getBytes());
Assert.assertEquals(introspectionResponse.getCode(), ResponseCode.CONTENT);
IntrospectResponse introspectResponse = new IntrospectResponse(introspectionResponse.getPayload(), MediaTypeRegistry.APPLICATION_JSON);
Assert.assertTrue(introspectResponse.isActive());
}
示例8: invalidToken
import org.eclipse.californium.core.coap.Response; //导入方法依赖的package包/类
@Test
public void invalidToken() throws Exception {
IntrospectRequest req = new IntrospectRequest();
req.setToken("loremipsum");
req.setClientID(config.getClients().get(0).getClient_id());
req.setClientSecret(config.getClients().get(0).getClient_secret());
Response response = DTLSUtils.dtlsPSKRequest("coaps://localhost:"+config.getCoapsPort()+"/"+Constants.INSTROSPECTION_RESOURCE, "POST", req.toPayload(MediaTypeRegistry.APPLICATION_JSON), MediaTypeRegistry.APPLICATION_JSON, config.getPskIdentity(), config.getPskKey().getBytes());
Assert.assertEquals(response.getCode(), ResponseCode.CONTENT);
IntrospectResponse introspectResponse = new IntrospectResponse(response.getPayload(), MediaTypeRegistry.APPLICATION_JSON);
Assert.assertFalse(introspectResponse.isActive());
}
示例9: callBadRequestEndpointCall
import org.eclipse.californium.core.coap.Response; //导入方法依赖的package包/类
private void callBadRequestEndpointCall(byte[] payload, String expectedError, int contentFormat) throws Exception {
Response response = DTLSUtils.dtlsPSKRequest("coaps://localhost:"+config.getCoapsPort()+"/"+Constants.INSTROSPECTION_RESOURCE, "POST", payload, contentFormat, config.getPskIdentity(), config.getPskKey().getBytes());
Assert.assertEquals(response.getCode(), ResponseCode.BAD_REQUEST);
// take request and turn it into a TokenRequest object
byte[] error = response.getPayload();
ErrorResponse errorResp = new ErrorResponse(error, MediaTypeRegistry.APPLICATION_JSON);
Assert.assertEquals(expectedError, errorResp.getError());
}
示例10: createObserveResponse
import org.eclipse.californium.core.coap.Response; //导入方法依赖的package包/类
private ObserveResponse createObserveResponse(Observation observation, LwM2mModel model, Response coapResponse) {
// CHANGED response is supported for backward compatibility with old spec.
if (coapResponse.getCode() != CoAP.ResponseCode.CHANGED
&& coapResponse.getCode() != CoAP.ResponseCode.CONTENT) {
throw new InvalidResponseException("Unexpected response code [%s] for %s", coapResponse.getCode(),
observation);
}
// get content format
ContentFormat contentFormat = null;
if (coapResponse.getOptions().hasContentFormat()) {
contentFormat = ContentFormat.fromCode(coapResponse.getOptions().getContentFormat());
}
// decode response
try {
List<TimestampedLwM2mNode> timestampedNodes = decoder.decodeTimestampedData(coapResponse.getPayload(),
contentFormat, observation.getPath(), model);
// create lwm2m response
if (timestampedNodes.size() == 1 && !timestampedNodes.get(0).isTimestamped()) {
return new ObserveResponse(toLwM2mResponseCode(coapResponse.getCode()),
timestampedNodes.get(0).getNode(), null, observation, null, coapResponse);
} else {
return new ObserveResponse(toLwM2mResponseCode(coapResponse.getCode()), null, timestampedNodes,
observation, null, coapResponse);
}
} catch (CodecException e) {
if (LOG.isDebugEnabled()) {
byte[] payload = coapResponse.getPayload() == null ? new byte[0] : coapResponse.getPayload();
LOG.debug(String.format("Unable to decode notification payload [%s] of observation [%s] ",
Hex.encodeHexString(payload), observation), e);
}
throw new InvalidResponseException(e, "Unable to decode notification payload of observation [%s] ",
observation);
}
}
示例11: CoapMessage
import org.eclipse.californium.core.coap.Response; //导入方法依赖的package包/类
public CoapMessage(Response request, boolean incoming) {
this(incoming, request.getType(), request.getMID(), request.getTokenString(), request.getOptions(), request
.getPayload());
this.code = request.getCode().toString();
}
示例12: testSuccessPlaintext
import org.eclipse.californium.core.coap.Response; //导入方法依赖的package包/类
@Test
public void testSuccessPlaintext() throws Exception {
// first create a token
JsonWebKey jwk;
jwk = EcJwkGenerator.generateJwk(EllipticCurves.P256);
jwk.setKeyId("testkid");
TokenRequest createReq = new TokenRequest();
createReq.setGrantType("client_credentials");
createReq.setAud(config.getResourceServers().get(0).getAud());
createReq.setClientID(config.getClients().get(0).getClient_id());
createReq.setClientSecret(config.getClients().get(0).getClient_secret());
createReq.setScopes(config.getResourceServers().get(0).getScopes());
createReq.setKey(jwk);
Request request = Request.newPost();
request.setURI("coap://localhost:"+config.getCoapPort()+"/"+Constants.TOKEN_RESOURCE);
request.setPayload(createReq.toPayload(MediaTypeRegistry.APPLICATION_JSON));
request.getOptions().setContentFormat(MediaTypeRegistry.APPLICATION_JSON);
Response createResponse = request.send().waitForResponse();
Assert.assertEquals(ResponseCode.CONTENT, createResponse.getCode());
TokenResponse tokenResponse = new TokenResponse(createResponse.getPayload(), MediaTypeRegistry.APPLICATION_JSON);
// see of token is valid
IntrospectRequest introspectionReq = new IntrospectRequest();
introspectionReq.setToken(tokenResponse.getAccessToken());
introspectionReq.setClientID(config.getClients().get(0).getClient_id());
introspectionReq.setClientSecret(config.getClients().get(0).getClient_secret());
Request introspectionRequest = Request.newPost();
introspectionRequest.setURI("coap://localhost:"+config.getCoapPort()+"/"+Constants.INSTROSPECTION_RESOURCE);
introspectionRequest.setPayload(introspectionReq.toPayload(MediaTypeRegistry.APPLICATION_JSON));
introspectionRequest.getOptions().setContentFormat(MediaTypeRegistry.APPLICATION_JSON);
Response introspectionResponse = introspectionRequest.send().waitForResponse();
Assert.assertEquals(introspectionResponse.getCode(), ResponseCode.CONTENT);
IntrospectResponse introspectResponse = new IntrospectResponse(introspectionResponse.getPayload(), MediaTypeRegistry.APPLICATION_JSON);
Assert.assertTrue(introspectResponse.isActive());
}
示例13: asymmetricEcClient
import org.eclipse.californium.core.coap.Response; //导入方法依赖的package包/类
private static void asymmetricEcClient() throws JoseException {
JsonWebKey popKey = EcJwkGenerator.generateJwk(EllipticCurves.P256);
// generate a unique kid for the newly generated key
String kid = new BigInteger(130, random).toString(32);
popKey.setKeyId(kid);
TokenRequest req = new TokenRequest();
req.setGrantType("client_credentials");
req.setAud(config.getRsAud());
req.setClientID(config.getClientId());
req.setClientSecret(config.getClientSecret());
req.setScopes(config.getRsScopes());
// add key to the request so that public part can be sent to AS
req.setKey(popKey);
Response response;
try {
// send token request to AS and include the public key
response = DTLSUtils.dtlsPSKRequest("coaps://localhost:"+config.getAsCoapsPort()+"/"+Constants.TOKEN_RESOURCE, "POST", req.toPayload(MediaTypeRegistry.APPLICATION_JSON), MediaTypeRegistry.APPLICATION_JSON, config.getAsPskIdentity(), config.getAsPskKey().getBytes());
TokenResponse tokenResponse = new TokenResponse(response.getPayload(), response.getOptions().getContentFormat());
String accessToken = tokenResponse.getAccessToken();
EllipticCurveJsonWebKey rpk = tokenResponse.getRpk();
if(rpk != null) {
String keyType = rpk.getKeyType();
PublicKey publicKey = null;
if(keyType.equalsIgnoreCase("ec")) {
EllipticCurveJsonWebKey ecjwk = new EllipticCurveJsonWebKey((ECPublicKey) rpk.getKey());
publicKey = ecjwk.getPublicKey();
}
else if(keyType.equalsIgnoreCase("rsa")) {
RsaJsonWebKey rsajwk = new RsaJsonWebKey((RSAPublicKey) rpk.getKey());
publicKey = rsajwk.getPublicKey();
}
ArrayList<PublicKey> trustedPublicKeys = new ArrayList<PublicKey>();
trustedPublicKeys.add(publicKey);
// send key to resource servers authz-info resource over unencrypted DTLS
Request authzInfoRequest = Request.newPost();
authzInfoRequest.setURI("coap://localhost:"+config.getRsCoapPort()+"/"+Constants.AUTHZ_INFO_RESOURCE);
authzInfoRequest.getOptions().setContentFormat(Constants.MediaTypeRegistry_APPLICATION_JWT);
authzInfoRequest.setPayload(accessToken.getBytes());
Response authzInfoResponse = authzInfoRequest.send().waitForResponse();
if(authzInfoResponse.getCode() == ResponseCode.CREATED) {
// get the temperature
response = DTLSUtils.dtlsRPKRequest("coaps://localhost:"+config.getRsCoapsPort()+"/temperature", "POST", "".getBytes(), MediaTypeRegistry.APPLICATION_JSON, popKey, trustedPublicKeys);
TemperatureResponse temperatureResponse = new TemperatureResponse(response.getPayload(), response.getOptions().getContentFormat());
logger.info("Temp: " + temperatureResponse);
}
else {
logger.info("Access token not valid. Response code: " + response.getCode());
}
}
} catch (Exception e) {
logger.error(e);
}
}