use of org.springframework.boot.devtools.restart.classloader.ClassLoaderFiles in project spring-boot by spring-projects.
the class RestarterTests method addClassLoaderFiles.
@Test
public void addClassLoaderFiles() throws Exception {
ClassLoaderFiles classLoaderFiles = new ClassLoaderFiles();
classLoaderFiles.addFile("f", new ClassLoaderFile(Kind.ADDED, "abc".getBytes()));
Restarter restarter = Restarter.getInstance();
restarter.addClassLoaderFiles(classLoaderFiles);
restarter.restart();
ClassLoader classLoader = ((TestableRestarter) restarter).getRelaunchClassLoader();
assertThat(FileCopyUtils.copyToByteArray(classLoader.getResourceAsStream("f"))).isEqualTo("abc".getBytes());
}
use of org.springframework.boot.devtools.restart.classloader.ClassLoaderFiles in project spring-boot by spring-projects.
the class Restarter method doStart.
private Throwable doStart() throws Exception {
Assert.notNull(this.mainClassName, "Unable to find the main class to restart");
ClassLoader parent = this.applicationClassLoader;
URL[] urls = this.urls.toArray(new URL[this.urls.size()]);
ClassLoaderFiles updatedFiles = new ClassLoaderFiles(this.classLoaderFiles);
ClassLoader classLoader = new RestartClassLoader(parent, urls, updatedFiles, this.logger);
if (this.logger.isDebugEnabled()) {
this.logger.debug("Starting application " + this.mainClassName + " with URLs " + Arrays.asList(urls));
}
return relaunch(classLoader);
}
use of org.springframework.boot.devtools.restart.classloader.ClassLoaderFiles in project spring-boot by spring-projects.
the class HttpRestartServer method handle.
/**
* Handle a server request.
* @param request the request
* @param response the response
* @throws IOException in case of I/O errors
*/
public void handle(ServerHttpRequest request, ServerHttpResponse response) throws IOException {
try {
Assert.state(request.getHeaders().getContentLength() > 0, "No content");
ObjectInputStream objectInputStream = new ObjectInputStream(request.getBody());
ClassLoaderFiles files = (ClassLoaderFiles) objectInputStream.readObject();
objectInputStream.close();
this.server.updateAndRestart(files);
response.setStatusCode(HttpStatus.OK);
} catch (Exception ex) {
logger.warn("Unable to handler restart server HTTP request", ex);
response.setStatusCode(HttpStatus.INTERNAL_SERVER_ERROR);
}
}
use of org.springframework.boot.devtools.restart.classloader.ClassLoaderFiles in project spring-boot by spring-projects.
the class HttpRestartServerTests method sendClassLoaderFiles.
@Test
public void sendClassLoaderFiles() throws Exception {
MockHttpServletRequest request = new MockHttpServletRequest();
MockHttpServletResponse response = new MockHttpServletResponse();
ClassLoaderFiles files = new ClassLoaderFiles();
files.addFile("name", new ClassLoaderFile(Kind.ADDED, new byte[0]));
byte[] bytes = serialize(files);
request.setContent(bytes);
this.server.handle(new ServletServerHttpRequest(request), new ServletServerHttpResponse(response));
verify(this.delegate).updateAndRestart(this.filesCaptor.capture());
assertThat(this.filesCaptor.getValue().getFile("name")).isNotNull();
assertThat(response.getStatus()).isEqualTo(200);
}
use of org.springframework.boot.devtools.restart.classloader.ClassLoaderFiles in project spring-boot by spring-projects.
the class ClassLoaderFilesResourcePatternResolverTests method setup.
@Before
public void setup() {
this.files = new ClassLoaderFiles();
this.resolver = new ClassLoaderFilesResourcePatternResolver(new GenericApplicationContext(), this.files);
}
Aggregations