1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package de.smartics.properties.admin.resources.controller;
17
18 import javax.naming.NamingException;
19 import javax.servlet.http.HttpServletRequest;
20 import javax.ws.rs.FormParam;
21 import javax.ws.rs.GET;
22 import javax.ws.rs.POST;
23 import javax.ws.rs.Path;
24 import javax.ws.rs.Produces;
25 import javax.ws.rs.core.Context;
26 import javax.ws.rs.core.MediaType;
27 import javax.ws.rs.core.UriInfo;
28
29 import org.apache.commons.lang3.StringUtils;
30
31 import de.smartics.properties.admin.domain.model.JndiConfiguration;
32 import de.smartics.properties.admin.domain.model.ManagedApplication;
33 import de.smartics.properties.admin.domain.model.Paths;
34
35
36
37
38 @Path("")
39 public class JndiResource
40 {
41
42
43
44
45
46
47
48
49
50 @Context
51 private HttpServletRequest request;
52
53
54
55
56 @Context
57 private UriInfo uriInfo;
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79 @GET
80 @Path(Paths.PATH_JNDI)
81 @Produces(MediaType.TEXT_HTML)
82 public JndiConfiguration getAsHtml()
83 {
84 final JndiConfiguration config = JndiConfiguration.getJndiConfiguration();
85 return config;
86 }
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109 @POST
110 @Path(Paths.PATH_JNDI)
111 @Produces(MediaType.TEXT_HTML)
112 public JndiConfiguration postAsHtml(
113 @FormParam(Paths.PARAM_JNDI_APP_GROUP_ID) final String groupId,
114 @FormParam(Paths.PARAM_JNDI_APP_ARTIFACT_ID) final String artifactId,
115 @FormParam(Paths.PARAM_JNDI_APP_VERSION) final String version,
116 @FormParam(Paths.PARAM_JNDI_APP_ARCHIVE_TYPE) final String archiveType,
117 @FormParam(Paths.PARAM_JNDI_APP_CLASSIFIER) final String classifier,
118 @FormParam(Paths.PARAM_JNDI_CACHE_MAPPED_NAME) final String cacheName,
119 @FormParam(Paths.PARAM_JNDI_DS_MAPPED_NAME) final String dsName,
120 @FormParam(Paths.PARAM_JNDI_DS_CREATE_TABLE) final String dsCreateTable,
121 @FormParam(Paths.PARAM_JNDI_DS_DROP_TABLE) final String dsDropTable,
122 @FormParam(Paths.PARAM_JNDI_SECURITY_KEY) final String securityKey,
123 @FormParam(Paths.PARAM_JNDI_SECURITY_ALGORITHM) final String securityAlgorithm,
124 @FormParam(Paths.PARAM_JNDI_SECURITY_PROVIDER) final String securityProvider,
125 @FormParam(Paths.PARAM_JNDI_SECURITY_TRANSFORMATION) final String securityTransformation)
126 throws NamingException
127 {
128 final JndiConfiguration config = JndiConfiguration.getJndiConfiguration();
129
130 if (!config.isInitialized())
131 {
132 config.initialize();
133 }
134
135 config.setGroupId(norm(groupId));
136 config.setArtifactId(norm(artifactId));
137 config.setVersion(norm(version));
138 config.setArchiveType(norm(archiveType));
139 config.setClassifier(norm(classifier));
140
141 config.setCacheName(norm(cacheName));
142
143 config.setDsName(norm(dsName));
144 config.setDsCreateTable(norm(dsCreateTable));
145 config.setDsDropTable(norm(dsDropTable));
146
147 config.setSecurityKey(norm(securityKey));
148 config.setSecurityAlgorithm(norm(securityAlgorithm));
149 config.setSecurityProvider(norm(securityProvider));
150 config.setSecurityTransformation(norm(securityTransformation));
151
152 config.update();
153
154 final ManagedApplication app = ManagedApplication.getApplication();
155 app.clean();
156
157 return config;
158 }
159
160
161
162 private static String norm(final String value)
163 {
164 return StringUtils.isBlank(value) ? null : value;
165 }
166
167
168
169 }