use of org.eclipse.leshan.server.bootstrap.DefaultBootstrapSession in project thingsboard by thingsboard.
the class LwM2mDefaultBootstrapSessionManager method nextRequest.
protected BootstrapDownlinkRequest<? extends LwM2mResponse> nextRequest(BootstrapSession bsSession) {
DefaultBootstrapSession session = (DefaultBootstrapSession) bsSession;
List<BootstrapDownlinkRequest<? extends LwM2mResponse>> requestsToSend = session.getRequests();
if (!requestsToSend.isEmpty()) {
// get next requests
return requestsToSend.remove(0);
} else {
if (session.hasMoreTasks()) {
BootstrapTaskProvider.Tasks nextTasks = tasksProvider.getTasks(session, session.getResponses());
if (nextTasks == null) {
session.setMoreTasks(false);
return new BootstrapFinishRequest();
}
initTasks(session, nextTasks);
return nextRequest(bsSession);
} else {
return new BootstrapFinishRequest();
}
}
}
use of org.eclipse.leshan.server.bootstrap.DefaultBootstrapSession in project thingsboard by thingsboard.
the class LwM2mDefaultBootstrapSessionManager method initTasks.
protected void initTasks(BootstrapSession bssession, BootstrapTaskProvider.Tasks tasks) {
DefaultBootstrapSession session = (DefaultBootstrapSession) bssession;
// set models
if (tasks.supportedObjects != null)
session.setModel(modelProvider.getObjectModel(session, tasks.supportedObjects));
// set Requests to Send
log.info("tasks.requestsToSend = [{}]", tasks.requestsToSend);
session.setRequests(tasks.requestsToSend);
// prepare list where we will store Responses
session.setResponses(new ArrayList<LwM2mResponse>(tasks.requestsToSend.size()));
// is last Tasks ?
session.setMoreTasks(!tasks.last);
}
use of org.eclipse.leshan.server.bootstrap.DefaultBootstrapSession in project thingsboard by thingsboard.
the class LwM2mDefaultBootstrapSessionManager method onResponseError.
@Override
public BootstrapPolicy onResponseError(BootstrapSession bsSession, BootstrapDownlinkRequest<? extends LwM2mResponse> request, LwM2mResponse response) {
if (!(request instanceof BootstrapFinishRequest)) {
// store response
DefaultBootstrapSession session = (DefaultBootstrapSession) bsSession;
session.getResponses().add(response);
this.sendLogs(bsSession.getEndpoint(), String.format("%s: %s %s receives error response %s ", LOG_LWM2M_INFO, request.getClass().getSimpleName(), request.getPath().toString(), response.toString()));
// on response error for NOT bootstrap finish request we continue any sending next request
return BootstrapPolicy.continueWith(nextRequest(bsSession));
} else {
// on response error for bootstrap finish request we stop the session
this.sendLogs(bsSession.getEndpoint(), String.format("%s: error response for request bootstrap finish. Stop the session: %s", LOG_LWM2M_ERROR, bsSession.toString()));
return BootstrapPolicy.failed();
}
}
use of org.eclipse.leshan.server.bootstrap.DefaultBootstrapSession in project thingsboard by thingsboard.
the class LwM2mDefaultBootstrapSessionManager method begin.
@Override
public BootstrapSession begin(BootstrapRequest request, Identity clientIdentity) {
boolean authorized = true;
Iterator<SecurityInfo> securityInfos = null;
try {
if (bsSecurityStore != null && securityChecker != null) {
if (clientIdentity.isPSK()) {
SecurityInfo securityInfo = bsSecurityStore.getByIdentity(clientIdentity.getPskIdentity());
securityInfos = Collections.singletonList(securityInfo).iterator();
} else if (!clientIdentity.isX509()) {
securityInfos = bsSecurityStore.getAllByEndpoint(request.getEndpointName());
}
authorized = this.checkSecurityInfo(request.getEndpointName(), clientIdentity, securityInfos);
}
} catch (LwM2MAuthException e) {
authorized = false;
}
DefaultBootstrapSession session = new DefaultBootstrapSession(request, clientIdentity, authorized);
if (authorized) {
this.sendLogs(request.getEndpointName(), String.format("%s: Bootstrap session started...", LOG_LWM2M_INFO, request.getEndpointName()));
}
return session;
}
use of org.eclipse.leshan.server.bootstrap.DefaultBootstrapSession in project thingsboard by thingsboard.
the class LwM2mDefaultBootstrapSessionManager method onResponseSuccess.
@Override
public BootstrapPolicy onResponseSuccess(BootstrapSession bsSession, BootstrapDownlinkRequest<? extends LwM2mResponse> request, LwM2mResponse response) {
if (!(request instanceof BootstrapFinishRequest)) {
// store response
DefaultBootstrapSession session = (DefaultBootstrapSession) bsSession;
session.getResponses().add(response);
String msg = String.format("%s: receives success response for: %s %s %s", LOG_LWM2M_INFO, request.getClass().getSimpleName(), request.getPath().toString(), response.toString());
this.sendLogs(bsSession.getEndpoint(), msg);
// on success for NOT bootstrap finish request we send next request
return BootstrapPolicy.continueWith(nextRequest(bsSession));
} else {
// on success for bootstrap finish request we stop the session
this.sendLogs(bsSession.getEndpoint(), String.format("%s: receives success response for bootstrap finish.", LOG_LWM2M_INFO));
return BootstrapPolicy.finished();
}
}
Aggregations