is it possible to have plugin listen to a port and accept http requests?

It was easy enough to find information how to make http requests from plugin, but I couldn't find information on setting up a http server.

When running Intellij I can see it is listening to one port (Ultimate is listening on 3 ports), so there is some built in web server. Is it possible to use that web server or add some filters to existing incoming requests?

All hints and references highly appreciated!

1

Take a look at the com.intellij.httpRequestHandler extension point. Easiest way of using it is to extend org.jetbrains.ide.RestService.

1
Avatar
Permanently deleted user

Thank you Jamie!

It was exactly what I needed.

I extended RestService

public class KeyboardTypeListener extends RestService {

@NotNull
@Override
protected String getServiceName() {
return "keymapSwitcher";
}

@Override
protected boolean isMethodSupported(@NotNull HttpMethod httpMethod) {
return httpMethod == HttpMethod.GET;
}

@Nullable
@Override
public String execute(@NotNull QueryStringDecoder queryStringDecoder, @NotNull FullHttpRequest fullHttpRequest, @NotNull ChannelHandlerContext channelHandlerContext) throws IOException {
sendOk(fullHttpRequest, channelHandlerContext);
return null;
}

@Override
protected boolean isHostTrusted(@NotNull FullHttpRequest request) throws InterruptedException, InvocationTargetException {
return true;
}
}

requested 127.0.0.1:63343/api.keymapSwitcher

and it worked

0

请先登录再写评论。