Skip to content

Commit

Permalink
Update PingController configuration so works in all apps.
Browse files Browse the repository at this point in the history
  • Loading branch information
msqr committed Dec 21, 2023
1 parent 9a5e875 commit 3c30b08
Show file tree
Hide file tree
Showing 9 changed files with 83 additions and 102 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
import java.util.concurrent.TimeoutException;
import org.springframework.http.MediaType;
import org.springframework.scheduling.concurrent.CustomizableThreadFactory;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
Expand All @@ -54,14 +53,23 @@
* @author matt
* @version 3.1
*/
@Controller
@RequestMapping("/ping")
public class PingController {

private static final ExecutorService EXECUTOR = Executors
.newCachedThreadPool(new CustomizableThreadFactory("Ping-"));

private List<PingTest> tests = null;
private final List<PingTest> tests;

/**
* Constructor.
*
* @param tests
* the tests
*/
public PingController(List<PingTest> tests) {
super();
this.tests = tests;
}

private PingResults executeTests() {
final Instant now = Instant.now();
Expand Down Expand Up @@ -186,12 +194,13 @@ public boolean isAllGood() {

}

/**
* Get the ping tests.
*
* @return the tests
*/
public List<PingTest> getTests() {
return tests;
}

public void setTests(List<PingTest> tests) {
this.tests = tests;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import static net.solarnetwork.central.oscp.web.OscpWebUtils.RESPONSE_SENT;
import java.util.List;
import java.util.concurrent.TimeUnit;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
Expand All @@ -45,26 +44,20 @@
* Web layer configuration.
*
* @author matt
* @version 1.0
* @version 1.1
*/
@Configuration
@Import({ WebServiceErrorAttributes.class })
public class WebConfig implements WebMvcConfigurer {

@Autowired(required = false)
private List<PingTest> pingTests;

@Bean
public PingController pingController() {
PingController controller = new PingController();
controller.setTests(pingTests);
return controller;
}

@Controller
@RequestMapping("/ping")
static class SolarOscpFpPingController extends PingController {
// nothing new

public SolarOscpFpPingController(List<PingTest> tests) {
super(tests);
}

}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import static net.solarnetwork.central.oscp.web.OscpWebUtils.RESPONSE_SENT;
import java.util.List;
import java.util.concurrent.TimeUnit;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
Expand All @@ -45,26 +44,20 @@
* Web layer configuration.
*
* @author matt
* @version 1.0
* @version 1.1
*/
@Configuration
@Import({ WebServiceErrorAttributes.class, WebServiceGlobalControllerSupport.class })
public class WebConfig implements WebMvcConfigurer {

@Autowired(required = false)
private List<PingTest> pingTests;

@Bean
public PingController pingController() {
PingController controller = new PingController();
controller.setTests(pingTests);
return controller;
}

@Controller
@RequestMapping("/ping")
static class SolarOscpSimCpPingController extends PingController {
// nothing new

public SolarOscpSimCpPingController(List<PingTest> tests) {
super(tests);
}

}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@

import java.util.List;
import java.util.concurrent.TimeUnit;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.stereotype.Controller;
Expand All @@ -41,26 +39,20 @@
* Web layer configuration.
*
* @author matt
* @version 1.0
* @version 1.1
*/
@Configuration
@Import({ WebServiceErrorAttributes.class })
public class WebConfig implements WebMvcConfigurer {

@Autowired(required = false)
private List<PingTest> pingTests;

@Bean
public PingController pingController() {
SolarDnp3PingController controller = new SolarDnp3PingController();
controller.setTests(pingTests);
return controller;
}

@Controller
@RequestMapping("/ping")
static class SolarDnp3PingController extends PingController {
// nothing new

public SolarDnp3PingController(List<PingTest> tests) {
super(tests);
}

}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.http.CacheControl;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.config.annotation.ContentNegotiationConfigurer;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
Expand All @@ -55,26 +55,21 @@
* Web layer configuration.
*
* @author matt
* @version 1.0
* @version 1.1
*/
@Configuration
@Import({ WebServiceErrorAttributes.class, WebServiceControllerSupport.class,
WebServiceGlobalControllerSupport.class })
public class WebConfig implements WebMvcConfigurer {

@Autowired(required = false)
private List<PingTest> pingTests;

@Bean
public PingController pingController() {
SolarInPingController controller = new SolarInPingController();
controller.setTests(pingTests);
return controller;
}

@Controller
@RequestMapping("/solarin/ping")
static class SolarInPingController extends PingController {
// nothing new

public SolarInPingController(List<PingTest> tests) {
super(tests);
}

}

@SuppressWarnings("deprecation")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@
package net.solarnetwork.central.jobs.config;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import net.solarnetwork.central.web.PingController;
import net.solarnetwork.central.web.support.WebServiceControllerSupport;
Expand All @@ -38,21 +38,21 @@
* Web layer configuration.
*
* @author matt
* @version 1.0
* @version 1.1
*/
@Configuration
@Import({ WebServiceErrorAttributes.class, WebServiceControllerSupport.class,
WebServiceGlobalControllerSupport.class })
public class WebConfig implements WebMvcConfigurer {

@Autowired(required = false)
private List<PingTest> pingTests;
@Controller
@RequestMapping("/ping")
static class SolarJobsPingController extends PingController {

public SolarJobsPingController(List<PingTest> tests) {
super(tests);
}

@Bean
public PingController pingController() {
PingController controller = new PingController();
controller.setTests(pingTests);
return controller;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.http.CacheControl;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.config.annotation.ContentNegotiationConfigurer;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
Expand All @@ -55,26 +55,21 @@
* Web layer configuration.
*
* @author matt
* @version 1.0
* @version 1.1
*/
@Configuration
@Import({ WebServiceErrorAttributes.class, WebServiceControllerSupport.class,
WebServiceGlobalControllerSupport.class })
public class WebConfig implements WebMvcConfigurer {

@Autowired(required = false)
private List<PingTest> pingTests;

@Bean
public PingController pingController() {
SolarOcppPingController controller = new SolarOcppPingController();
controller.setTests(pingTests);
return controller;
}

@Controller
@RequestMapping("/solarocpp/ping")
static class SolarOcppPingController extends PingController {
// nothing new

public SolarOcppPingController(List<PingTest> tests) {
super(tests);
}

}

@SuppressWarnings("deprecation")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,10 @@
import org.springframework.format.datetime.standard.TemporalAccessorParser;
import org.springframework.format.datetime.standard.TemporalAccessorPrinter;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.stereotype.Controller;
import org.springframework.util.AntPathMatcher;
import org.springframework.util.PathMatcher;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
Expand All @@ -72,7 +74,7 @@
* Web layer configuration.
*
* @author matt
* @version 1.0
* @version 1.1
*/
@Configuration
@Import({ WebServiceErrorAttributes.class, WebServiceControllerSupport.class,
Expand All @@ -82,9 +84,6 @@ public class WebConfig implements WebMvcConfigurer {
/** A qualifier for the source ID path matcher. */
public static final String SOURCE_ID_PATH_MATCHER = "source-id";

@Autowired(required = false)
private List<PingTest> pingTests;

@Autowired(required = false)
@Qualifier(QUERY_CACHE)
private ContentCachingService contentCachingService;
Expand All @@ -98,11 +97,14 @@ public PathMatcher sourceIdPathMatcher() {
return matcher;
}

@Bean
public PingController pingController() {
PingController controller = new PingController();
controller.setTests(pingTests);
return controller;
@Controller
@RequestMapping("/ping")
static class SolarQueryPingController extends PingController {

public SolarQueryPingController(List<PingTest> tests) {
super(tests);
}

}

@Override
Expand Down
Loading

0 comments on commit 3c30b08

Please sign in to comment.