Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#noissue] Converted websocket.xml to WebSocketConfig class #9879

Merged
merged 1 commit into from
Apr 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import com.navercorp.pinpoint.web.config.ScatterChartProperties;
import com.navercorp.pinpoint.web.config.WebClusterProperties;
import com.navercorp.pinpoint.web.config.WebMysqlDataSourceConfiguration;
import com.navercorp.pinpoint.web.config.WebSocketConfig;
import com.navercorp.pinpoint.web.frontend.FrontendConfigExportConfiguration;
import com.navercorp.pinpoint.web.install.InstallModule;
import com.navercorp.pinpoint.web.query.QueryServiceConfiguration;
Expand All @@ -28,7 +27,6 @@
"classpath:servlet-context-web.xml",

"classpath:applicationContext-web-dao-config.xml",
"classpath:applicationContext-web-websocket.xml"
})
@Import({
WebAppPropertySources.class,
Expand All @@ -37,14 +35,13 @@

WebServerConfig.class,
WebMvcConfig.class,
WebSocketConfig.class,
WebMysqlDataSourceConfiguration.class,
ClusterConfigurationFactory.class,
CacheConfiguration.class,

WebHbaseModule.class,

WebSocketConfig.class,

InstallModule.class,
WebhookModule.class,
FrontendConfigExportConfiguration.class,
Expand Down
89 changes: 89 additions & 0 deletions web/src/main/java/com/navercorp/pinpoint/web/WebSocketConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
/*
* Copyright 2023 NAVER Corp.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.navercorp.pinpoint.web;

import com.navercorp.pinpoint.thrift.io.DeserializerFactory;
import com.navercorp.pinpoint.thrift.io.HeaderTBaseDeserializer;
import com.navercorp.pinpoint.thrift.io.HeaderTBaseSerializer;
import com.navercorp.pinpoint.thrift.io.SerializerFactory;
import com.navercorp.pinpoint.web.cluster.ClusterManager;
import com.navercorp.pinpoint.web.config.ConfigProperties;
import com.navercorp.pinpoint.web.service.AgentInfoService;
import com.navercorp.pinpoint.web.service.AgentService;
import com.navercorp.pinpoint.web.service.AgentServiceImpl;
import com.navercorp.pinpoint.web.websocket.ActiveThreadCountHandler;
import com.navercorp.pinpoint.web.websocket.CustomHandshakeInterceptor;
import com.navercorp.pinpoint.web.websocket.PinpointWebSocketConfigurer;
import com.navercorp.pinpoint.web.websocket.PinpointWebSocketHandler;
import com.navercorp.pinpoint.web.websocket.PinpointWebSocketHandlerManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.socket.config.annotation.EnableWebSocket;
import org.springframework.web.socket.config.annotation.WebSocketConfigurer;
import org.springframework.web.socket.handler.WebSocketHandlerDecoratorFactory;

import java.util.List;

/**
* @author youngjin.kim2
*/
@Configuration
@EnableWebSocket
public class WebSocketConfig {

@Bean
WebSocketConfigurer webSocketConfigurer(
PinpointWebSocketHandlerManager handlerRepository,
ConfigProperties configProperties,
@Autowired(required = false) WebSocketHandlerDecoratorFactory webSocketHandlerDecoratorFactory,
@Autowired(required = false) CustomHandshakeInterceptor customHandshakeInterceptor
) {
return new PinpointWebSocketConfigurer(
handlerRepository,
configProperties,
webSocketHandlerDecoratorFactory,
customHandshakeInterceptor
);
}

@Bean
AgentService agentService(
AgentInfoService agentInfoService,
ClusterManager clusterManager,
@Qualifier("commandHeaderTBaseSerializerFactory") SerializerFactory<HeaderTBaseSerializer> commandSerializerFactory,
@Qualifier("commandHeaderTBaseDeserializerFactory") DeserializerFactory<HeaderTBaseDeserializer> commandDeserializerFactory
) {
return new AgentServiceImpl(
agentInfoService,
clusterManager,
commandSerializerFactory,
commandDeserializerFactory
);
}

@Bean
PinpointWebSocketHandler activeThreadHandler(AgentService agentService) {
return new ActiveThreadCountHandler("/agent/activeThread", agentService);
}

@Bean
PinpointWebSocketHandlerManager handlerRegister(List<PinpointWebSocketHandler> handlers) {
return new PinpointWebSocketHandlerManager(handlers);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -14,50 +14,53 @@
* limitations under the License.
*/

package com.navercorp.pinpoint.web.config;
package com.navercorp.pinpoint.web.websocket;


import com.navercorp.pinpoint.web.websocket.CustomHandshakeInterceptor;
import com.navercorp.pinpoint.web.websocket.DefaultWebSocketHandlerDecoratorFactory;
import com.navercorp.pinpoint.web.websocket.PinpointWebSocketHandler;
import com.navercorp.pinpoint.web.websocket.PinpointWebSocketHandlerManager;
import com.navercorp.pinpoint.web.websocket.WebSocketSessionContextPrepareHandshakeInterceptor;
import com.navercorp.pinpoint.web.config.ConfigProperties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.lang.NonNull;
import org.springframework.util.StringUtils;
import org.springframework.web.socket.WebSocketHandler;
import org.springframework.web.socket.config.annotation.EnableWebSocket;
import org.springframework.web.socket.config.annotation.WebSocketConfigurer;
import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistration;
import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry;
import org.springframework.web.socket.handler.WebSocketHandlerDecoratorFactory;
import org.springframework.web.socket.server.support.HttpSessionHandshakeInterceptor;

import java.util.Objects;

/**
* @author Taejin Koo
*/
@Configuration
@EnableWebSocket
public class WebSocketConfig implements WebSocketConfigurer {
public class PinpointWebSocketConfigurer implements WebSocketConfigurer {

private static final String[] DEFAULT_ALLOWED_ORIGIN = new String[0];

private static final String WEBSOCKET_SUFFIX = ".pinpointws";

@Autowired
private PinpointWebSocketHandlerManager handlerRepository;

@Autowired
private ConfigProperties configProperties;

@Autowired(required = false)
private WebSocketHandlerDecoratorFactory webSocketHandlerDecoratorFactory = new DefaultWebSocketHandlerDecoratorFactory();

@Autowired(required = false)
private CustomHandshakeInterceptor customHandshakeInterceptor = null;
private final PinpointWebSocketHandlerManager handlerRepository;
private final ConfigProperties configProperties;
private final WebSocketHandlerDecoratorFactory webSocketHandlerDecoratorFactory;
private final CustomHandshakeInterceptor customHandshakeInterceptor;

public PinpointWebSocketConfigurer(
PinpointWebSocketHandlerManager handlerRepository,
ConfigProperties configProperties,
@Autowired(required = false) WebSocketHandlerDecoratorFactory webSocketHandlerDecoratorFactory,
@Autowired(required = false) CustomHandshakeInterceptor customHandshakeInterceptor
) {
this.handlerRepository = Objects.requireNonNull(handlerRepository, "handlerRepository");
this.configProperties = Objects.requireNonNull(configProperties, "configProperties");
this.webSocketHandlerDecoratorFactory = Objects.requireNonNullElseGet(
webSocketHandlerDecoratorFactory,
() -> new DefaultWebSocketHandlerDecoratorFactory()
);
this.customHandshakeInterceptor = customHandshakeInterceptor;
}

@Override
public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
public void registerWebSocketHandlers(@NonNull WebSocketHandlerRegistry registry) {
final String[] allowedOriginArray = getAllowedOriginArray(configProperties.getWebSocketAllowedOrigins());

for (PinpointWebSocketHandler handler : handlerRepository.getWebSocketHandlerRepository()) {
Expand Down
26 changes: 0 additions & 26 deletions web/src/main/resources/applicationContext-web-websocket.xml

This file was deleted.