colesico.framework.rpc.clientapi.handler.BasicRequestHandler Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of colesico-rpc Show documentation
Show all versions of colesico-rpc Show documentation
Colesico framework Remote Procedure Call for Services
The newest version!
package colesico.framework.rpc.clientapi.handler;
import colesico.framework.profile.Profile;
import colesico.framework.profile.teleapi.ProfileSerializer;
import colesico.framework.rpc.teleapi.BasicEnvelope;
import colesico.framework.rpc.clientapi.RpcRequestHandler;
import colesico.framework.security.Principal;
import colesico.framework.security.teleapi.PrincipalSerializer;
import javax.inject.Provider;
import javax.inject.Singleton;
@Singleton
public class BasicRequestHandler implements RpcRequestHandler {
private final PrincipalSerializer principalSerializer;
private final ProfileSerializer profileSerializer;
private final Provider principalProv;
private final Provider profileProv;
public BasicRequestHandler(PrincipalSerializer principalSerializer, ProfileSerializer profileSerializer, Provider principalProv, Provider profileProv) {
this.principalSerializer = principalSerializer;
this.profileSerializer = profileSerializer;
this.principalProv = principalProv;
this.profileProv = profileProv;
}
@Override
public void onRequest(BasicEnvelope request) {
Principal principal = principalProv.get();
if (principal != null) {
request.setPrincipal(principalSerializer.serialize(principal));
} else {
request.setPrincipal(null);
}
Profile profile = profileProv.get();
if (profile != null) {
request.setProfile(profileSerializer.serialize(profile));
} else {
request.setProfile(null);
}
}
}