1 | /* |
---|
2 | * Copyright (C) 2014 DASISH |
---|
3 | * |
---|
4 | * This program is free software; you can redistribute it and/or |
---|
5 | * modify it under the terms of the GNU General Public License |
---|
6 | * as published by the Free Software Foundation; either version 2 |
---|
7 | * of the License, or (at your option) any later version. |
---|
8 | * |
---|
9 | * This program is distributed in the hope that it will be useful, |
---|
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
12 | * GNU General Public License for more details. |
---|
13 | * |
---|
14 | * You should have received a copy of the GNU General Public License |
---|
15 | * along with this program; if not, write to the Free Software |
---|
16 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
---|
17 | */ |
---|
18 | package eu.dasish.annotation.backend.rest; |
---|
19 | |
---|
20 | import java.io.IOException; |
---|
21 | import java.net.URI; |
---|
22 | //import java.util.Collections; |
---|
23 | import javax.ws.rs.ProcessingException; |
---|
24 | import javax.ws.rs.core.UriBuilder; |
---|
25 | import org.glassfish.grizzly.http.server.HttpServer; |
---|
26 | import org.glassfish.jersey.client.ClientConfig; |
---|
27 | import org.glassfish.jersey.grizzly2.httpserver.GrizzlyHttpServerFactory; |
---|
28 | //import org.glassfish.jersey.grizzly2.servlet.GrizzlyWebContainerFactory; |
---|
29 | //import org.glassfish.jersey.servlet.ServletContainer; |
---|
30 | import org.glassfish.jersey.test.DeploymentContext; |
---|
31 | import org.glassfish.jersey.test.spi.TestContainer; |
---|
32 | import org.glassfish.jersey.test.spi.TestContainerException; |
---|
33 | import org.glassfish.jersey.test.spi.TestContainerFactory; |
---|
34 | //import org.glassfish.jersey.jdkhttp.JdkHttpServerFactory; |
---|
35 | /** |
---|
36 | * |
---|
37 | * @author olhsha |
---|
38 | */ |
---|
39 | public class DasishTestContainerFactory implements TestContainerFactory { |
---|
40 | |
---|
41 | @Override |
---|
42 | public TestContainer create(final URI baseUri, final DeploymentContext dc) throws IllegalArgumentException { |
---|
43 | return new TestContainer() { |
---|
44 | |
---|
45 | |
---|
46 | public HttpServer getServer() { |
---|
47 | return _server; |
---|
48 | } |
---|
49 | private URI _baseUri=UriBuilder.fromUri(baseUri).path(dc.getContextPath()).build(); |
---|
50 | private HttpServer _server; |
---|
51 | |
---|
52 | @Override |
---|
53 | public ClientConfig getClientConfig() { |
---|
54 | return null; |
---|
55 | } |
---|
56 | |
---|
57 | @Override |
---|
58 | public URI getBaseUri() { |
---|
59 | return _baseUri; |
---|
60 | } |
---|
61 | |
---|
62 | @Override |
---|
63 | public void start() { |
---|
64 | try { |
---|
65 | // ServletContainer sc = new ServletContainer(dc.getResourceConfig()); |
---|
66 | //_server = JdkHttpServerFactory.createHttpServer(baseUri, dc.getResourceConfig()); |
---|
67 | //_server = GrizzlyWebContainerFactory.create(baseUri, sc, Collections.singletonMap("jersey.config.server.provider.packages", "eu.dasish.annotation.backend.rest"), null); |
---|
68 | //_server.getServerConfiguration(). |
---|
69 | // _server = GrizzlyWebContainerFactory.create(baseUri, sc, Collections.singletonMap("jersey.config.server.provider.packages", "eu.dasish.annotation.backend.rest"), null); |
---|
70 | //_server = GrizzlyWebContainerFactory.create(baseUri, Collections.singletonMap("jersey.config.server.provider.packages", "eu.dasish.annotation.backend.rest")); |
---|
71 | _server = GrizzlyHttpServerFactory.createHttpServer(baseUri, dc.getResourceConfig()); |
---|
72 | _server.start(); |
---|
73 | } catch (ProcessingException e) { |
---|
74 | throw new TestContainerException(e); |
---|
75 | } catch (IOException e) { |
---|
76 | throw new TestContainerException(e); |
---|
77 | } |
---|
78 | } |
---|
79 | |
---|
80 | @Override |
---|
81 | public void stop() { |
---|
82 | _server.shutdownNow(); |
---|
83 | } |
---|
84 | }; |
---|
85 | } |
---|
86 | } |
---|