提问人:pawello12 提问时间:5/26/2023 最后编辑:pawello12 更新时间:5/26/2023 访问量:66
尝试从keycloak发送事件时连接被拒绝
Connection refused when trying to send an event from keycloak
问:
我正在尝试将事件从密钥斗篷发送到另一个微服务的端点,当我尝试返回连接被拒绝时。端点本身工作正常,因此密钥隐身中一定缺少某些内容。有谁知道为什么会这样?也许我应该添加一些配置?SimpleHttp.doPost()
@JBossLog
public class HttpSenderEventListenerProvider implements EventListenerProvider {
protected static final String TARGET_URI = "http://localhost:1010/my-service/event";
protected final KeycloakSession session;
private Set<EventType> excludedEvents;
private Set<OperationType> excludedAdminOperations;
public HttpSenderEventListenerProvider(KeycloakSession session, Set<EventType> excludedEvents, Set<OperationType> excludedAdminOpearations) {
this.session = session;
this.excludedEvents = excludedEvents;
this.excludedAdminOperations = excludedAdminOpearations;
}
@Override
public void onEvent(Event event) {
try {
testConnection(event);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
@Override
public void onEvent(AdminEvent event, boolean b) {
try {
testConnectionAdmin(event);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
@Override
public void close() {
// close this instance of the event listener
}
private void testConnection(Event event) throws IOException{
SimpleHttp request = SimpleHttp.doPost(TARGET_URI, session).json(event);
SimpleHttp.Response response = request.asResponse();
int status = response.getStatus();
}
private void testConnectionAdmin(AdminEvent event) throws IOException{
SimpleHttp request = SimpleHttp.doPost(TARGET_URI, session).json(event);
SimpleHttp.Response response = request.asResponse();
int status = response.getStatus();
}
}
public class EventListenerProviderFactoryImpl implements EventListenerProviderFactory {
private Set<EventType> excludedEvents;
private Set<OperationType> excludedAdminOperations;
@Override
public EventListenerProvider create(KeycloakSession session) {
return new HttpSenderEventListenerProvider(session, excludedEvents, excludedAdminOperations);
}
{...}
@Override
public String getId() {
return "sysout";
}
}
答: 暂无答案
评论