Skip to content

Commit 19be0f3

Browse files
author
eitan
committed
include dropwizaed changes in comsat
1 parent e3edf6b commit 19be0f3

File tree

5 files changed

+1002
-0
lines changed

5 files changed

+1002
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package io.dropwizard.jersey.setup;
2+
3+
import com.sun.jersey.spi.container.servlet.ServletContainer;
4+
import javax.servlet.Servlet;
5+
6+
public class JerseyContainerHolder {
7+
private Servlet container;
8+
9+
public JerseyContainerHolder(ServletContainer container) {
10+
this.container = container;
11+
}
12+
13+
public Servlet getContainer() {
14+
return container;
15+
}
16+
17+
public void setContainer(Servlet container) {
18+
this.container = container;
19+
}
20+
}
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
package io.dropwizard.jersey.setup;
2+
3+
import com.google.common.base.Function;
4+
import com.sun.jersey.api.core.ResourceConfig;
5+
import com.sun.jersey.core.spi.scanning.PackageNamesScanner;
6+
import javax.servlet.Servlet;
7+
import io.dropwizard.jersey.DropwizardResourceConfig;
8+
9+
import javax.annotation.Nullable;
10+
11+
import static com.google.common.base.Preconditions.checkNotNull;
12+
13+
public class JerseyEnvironment {
14+
private final JerseyContainerHolder holder;
15+
private final DropwizardResourceConfig config;
16+
17+
public JerseyEnvironment(JerseyContainerHolder holder,
18+
DropwizardResourceConfig config) {
19+
this.holder = holder;
20+
this.config = config;
21+
}
22+
23+
public void disable() {
24+
holder.setContainer(null);
25+
}
26+
27+
public void replace(Function<ResourceConfig, Servlet> replace) {
28+
holder.setContainer(replace.apply(config));
29+
}
30+
31+
/**
32+
* Adds the given object as a Jersey singleton component.
33+
*
34+
* @param component a Jersey singleton component
35+
*/
36+
public void register(Object component) {
37+
config.getSingletons().add(checkNotNull(component));
38+
}
39+
40+
/**
41+
* Adds the given class as a Jersey component. <p/><b>N.B.:</b> This class must either have a
42+
* no-args constructor or use Jersey's built-in dependency injection.
43+
*
44+
* @param componentClass a Jersey component class
45+
*/
46+
public void register(Class<?> componentClass) {
47+
config.getClasses().add(checkNotNull(componentClass));
48+
}
49+
50+
/**
51+
* Adds array of package names which will be used to scan for components. Packages will be
52+
* scanned recursively, including all nested packages.
53+
*
54+
* @param packages array of package names
55+
*/
56+
public void packages(String... packages) {
57+
config.init(new PackageNamesScanner(checkNotNull(packages)));
58+
}
59+
60+
/**
61+
* Enables the Jersey feature with the given name.
62+
*
63+
* @param featureName the name of the feature to be enabled
64+
* @see com.sun.jersey.api.core.ResourceConfig
65+
*/
66+
public void enable(String featureName) {
67+
config.getFeatures().put(checkNotNull(featureName), Boolean.TRUE);
68+
}
69+
70+
/**
71+
* Disables the Jersey feature with the given name.
72+
*
73+
* @param featureName the name of the feature to be disabled
74+
* @see com.sun.jersey.api.core.ResourceConfig
75+
*/
76+
public void disable(String featureName) {
77+
config.getFeatures().put(checkNotNull(featureName), Boolean.FALSE);
78+
}
79+
80+
/**
81+
* Sets the given Jersey property.
82+
*
83+
* @param name the name of the Jersey property
84+
* @param value the value of the Jersey property
85+
* @see com.sun.jersey.api.core.ResourceConfig
86+
*/
87+
public void property(String name, @Nullable Object value) {
88+
config.getProperties().put(checkNotNull(name), value);
89+
}
90+
91+
/**
92+
* Gets the given Jersey property.
93+
*
94+
* @param name the name of the Jersey property
95+
* @see com.sun.jersey.api.core.ResourceConfig
96+
*/
97+
@SuppressWarnings("unchecked")
98+
public <T> T getProperty(String name) {
99+
return (T) config.getProperties().get(name);
100+
}
101+
102+
public String getUrlPattern() {
103+
return config.getUrlPattern();
104+
}
105+
106+
public void setUrlPattern(String urlPattern) {
107+
config.setUrlPattern(urlPattern);
108+
}
109+
110+
public ResourceConfig getResourceConfig() {
111+
return config;
112+
}
113+
}

0 commit comments

Comments
 (0)