Search in sources :

Example 1 with CloseSessionResponse

use of org.eclipse.milo.opcua.stack.core.types.structured.CloseSessionResponse in project milo by eclipse.

the class SessionManager method closeSession.

private CloseSessionResponse closeSession(ServiceRequest service) throws UaException {
    CloseSessionRequest request = (CloseSessionRequest) service.getRequest();
    long secureChannelId = service.getSecureChannelId();
    NodeId authToken = service.getRequest().getRequestHeader().getAuthenticationToken();
    Session session = activeSessions.get(authToken);
    if (session != null) {
        if (session.getSecureChannelId() != secureChannelId) {
            throw new UaException(StatusCodes.Bad_SecureChannelIdInvalid);
        } else {
            activeSessions.remove(authToken);
            session.close(request.getDeleteSubscriptions());
            return new CloseSessionResponse(service.createResponseHeader());
        }
    } else {
        session = createdSessions.get(authToken);
        if (session == null) {
            throw new UaException(StatusCodes.Bad_SessionIdInvalid);
        } else if (session.getSecureChannelId() != secureChannelId) {
            throw new UaException(StatusCodes.Bad_SecureChannelIdInvalid);
        } else {
            createdSessions.remove(authToken);
            session.close(request.getDeleteSubscriptions());
            return new CloseSessionResponse(service.createResponseHeader());
        }
    }
}
Also used : UaException(org.eclipse.milo.opcua.stack.core.UaException) CloseSessionRequest(org.eclipse.milo.opcua.stack.core.types.structured.CloseSessionRequest) NodeId(org.eclipse.milo.opcua.stack.core.types.builtin.NodeId) CloseSessionResponse(org.eclipse.milo.opcua.stack.core.types.structured.CloseSessionResponse)

Example 2 with CloseSessionResponse

use of org.eclipse.milo.opcua.stack.core.types.structured.CloseSessionResponse in project milo by eclipse.

the class SessionManager method onCloseSession.

@Override
public void onCloseSession(ServiceRequest service) {
    try {
        CloseSessionResponse response = closeSession(service);
        service.setResponse(response);
    } catch (UaException e) {
        service.setServiceFault(e);
    }
}
Also used : UaException(org.eclipse.milo.opcua.stack.core.UaException) CloseSessionResponse(org.eclipse.milo.opcua.stack.core.types.structured.CloseSessionResponse)

Aggregations

UaException (org.eclipse.milo.opcua.stack.core.UaException)2 CloseSessionResponse (org.eclipse.milo.opcua.stack.core.types.structured.CloseSessionResponse)2 NodeId (org.eclipse.milo.opcua.stack.core.types.builtin.NodeId)1 CloseSessionRequest (org.eclipse.milo.opcua.stack.core.types.structured.CloseSessionRequest)1