Search in sources :

Example 6 with ClassLoaderFiles

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());
}
Also used : ClassLoaderFiles(org.springframework.boot.devtools.restart.classloader.ClassLoaderFiles) URLClassLoader(java.net.URLClassLoader) ClassLoaderFile(org.springframework.boot.devtools.restart.classloader.ClassLoaderFile) Test(org.junit.Test)

Example 7 with ClassLoaderFiles

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);
}
Also used : ClassLoaderFiles(org.springframework.boot.devtools.restart.classloader.ClassLoaderFiles) RestartClassLoader(org.springframework.boot.devtools.restart.classloader.RestartClassLoader) RestartClassLoader(org.springframework.boot.devtools.restart.classloader.RestartClassLoader) URL(java.net.URL)

Example 8 with ClassLoaderFiles

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);
    }
}
Also used : ClassLoaderFiles(org.springframework.boot.devtools.restart.classloader.ClassLoaderFiles) IOException(java.io.IOException) ObjectInputStream(java.io.ObjectInputStream)

Example 9 with ClassLoaderFiles

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);
}
Also used : ServletServerHttpRequest(org.springframework.http.server.ServletServerHttpRequest) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) ClassLoaderFiles(org.springframework.boot.devtools.restart.classloader.ClassLoaderFiles) ServletServerHttpResponse(org.springframework.http.server.ServletServerHttpResponse) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) ClassLoaderFile(org.springframework.boot.devtools.restart.classloader.ClassLoaderFile) Test(org.junit.Test)

Example 10 with ClassLoaderFiles

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);
}
Also used : GenericApplicationContext(org.springframework.context.support.GenericApplicationContext) ClassLoaderFiles(org.springframework.boot.devtools.restart.classloader.ClassLoaderFiles) Before(org.junit.Before)

Aggregations

ClassLoaderFiles (org.springframework.boot.devtools.restart.classloader.ClassLoaderFiles)10 ClassLoaderFile (org.springframework.boot.devtools.restart.classloader.ClassLoaderFile)6 Test (org.junit.Test)5 URL (java.net.URL)4 URLClassLoader (java.net.URLClassLoader)4 File (java.io.File)2 IOException (java.io.IOException)2 FileOutputStream (java.io.FileOutputStream)1 ObjectInputStream (java.io.ObjectInputStream)1 LinkedHashSet (java.util.LinkedHashSet)1 Before (org.junit.Before)1 SourceFolder (org.springframework.boot.devtools.restart.classloader.ClassLoaderFiles.SourceFolder)1 RestartClassLoader (org.springframework.boot.devtools.restart.classloader.RestartClassLoader)1 GenericApplicationContext (org.springframework.context.support.GenericApplicationContext)1 ServletServerHttpRequest (org.springframework.http.server.ServletServerHttpRequest)1 ServletServerHttpResponse (org.springframework.http.server.ServletServerHttpResponse)1 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)1 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)1