1313 *
1414 * @see SimpleHttpsServer
1515 * @since 03.04.00
16- * @version 03.05.00
16+ * @version 03.05.03
1717 * @author Ktt Development
1818 */
19+ @ SuppressWarnings ("SpellCheckingInspection" )
1920final class SimpleHttpsServerImpl extends SimpleHttpsServer {
2021
2122 private final HttpsServer server = HttpsServer .create ();
@@ -74,29 +75,25 @@ public final HttpsConfigurator getHttpsConfigurator(){
7475
7576 // region copySimpleHttpServerImpl
7677
77- @ SuppressWarnings ("SpellCheckingInspection" )
7878 @ Override
7979 public synchronized final InetSocketAddress bind (final int port ) throws IOException {
8080 final InetSocketAddress addr = new InetSocketAddress (port );
8181 server .bind (addr , 0 );
8282 return addr ;
8383 }
8484
85- @ SuppressWarnings ("SpellCheckingInspection" )
8685 @ Override
8786 public synchronized final InetSocketAddress bind (final int port , final int backlog ) throws IOException {
8887 final InetSocketAddress addr = new InetSocketAddress (port );
8988 server .bind (addr , backlog );
9089 return addr ;
9190 }
9291
93- @ SuppressWarnings ("SpellCheckingInspection" )
9492 @ Override
9593 public synchronized final void bind (final InetSocketAddress addr ) throws IOException {
9694 server .bind (addr ,0 );
9795 }
9896
99- @ SuppressWarnings ("SpellCheckingInspection" )
10097 @ Override
10198 public synchronized final void bind (final InetSocketAddress addr , final int backlog ) throws IOException {
10299 server .bind (addr ,backlog );
@@ -143,51 +140,57 @@ public final HttpSession getHttpSession(final SimpleHttpExchange exchange){
143140
144141 //
145142
146- @ Override
147- public synchronized final HttpContext createContext (final String path ){
148- return createContext (path ,HttpExchange ::close ,null );
143+ @ Override
144+ public synchronized final HttpContext createContext (final String context ){
145+ return createContext (context ,HttpExchange ::close ,null );
149146 }
150147
151148 @ Override
152- public synchronized final HttpContext createContext (final String path , final HttpHandler handler ){
153- return createContext (path ,handler ,null );
149+ public synchronized final HttpContext createContext (final String context , final HttpHandler handler ){
150+ return createContext (context ,handler ,null );
154151 }
155152
156153 //
157154
158155 @ Override
159- public synchronized final HttpContext createContext (final String path , final Authenticator authenticator ){
160- return createContext (path ,HttpExchange ::close ,authenticator );
156+ public synchronized final HttpContext createContext (final String context , final Authenticator authenticator ){
157+ return createContext (context ,HttpExchange ::close ,authenticator );
161158 }
162159
163160 @ Override
164- public synchronized final HttpContext createContext (final String path , final HttpHandler handler , final Authenticator authenticator ){
165- if (!getContext (path ).equals ("/" ) && handler instanceof RootHandler )
161+ public synchronized final HttpContext createContext (final String context , final HttpHandler handler , final Authenticator authenticator ){
162+ if (!ContextUtil . getContext (context , true , false ).equals ("/" ) && handler instanceof RootHandler )
166163 throw new IllegalArgumentException ("RootHandler can only be used at the root '/' context" );
167164
168165 final HttpHandler wrapper = exchange -> {
169166 handle (exchange );
170167 handler .handle (exchange );
171168 };
172169
173- final HttpContext context = server .createContext (getContext (path ),wrapper );
174- contexts .put (context ,handler );
170+ final HttpContext hc = server .createContext (ContextUtil . getContext (context , true , false ),wrapper );
171+ contexts .put (hc ,handler );
175172
176173 if (authenticator != null )
177- context .setAuthenticator (authenticator );
174+ hc .setAuthenticator (authenticator );
178175
179- return context ;
176+ return hc ;
180177 }
181178
182179 //
183180
181+ @ SuppressWarnings ("CaughtExceptionImmediatelyRethrown" )
184182 @ Override
185- public synchronized final void removeContext (final String path ){
186- server .removeContext (getContext (path ));
187- for (final HttpContext context : contexts .keySet ()){
188- if (context .getPath ().equalsIgnoreCase (getContext (path ))){
189- contexts .remove (context );
190- break ;
183+ public synchronized final void removeContext (final String context ){
184+ try {
185+ server .removeContext (ContextUtil .getContext (context ,true ,false ));
186+ }catch (final IllegalArgumentException e ){
187+ throw e ;
188+ }finally {
189+ for (final HttpContext hc : contexts .keySet ()){
190+ if (hc .getPath ().equalsIgnoreCase (ContextUtil .getContext (context ,true ,false ))){
191+ contexts .remove (hc );
192+ break ;
193+ }
191194 }
192195 }
193196 }
@@ -201,9 +204,9 @@ public synchronized final void removeContext(final HttpContext context){
201204//
202205
203206 @ Override
204- public final HttpHandler getContextHandler (final String path ){
207+ public final HttpHandler getContextHandler (final String context ){
205208 for (final Map .Entry <HttpContext , HttpHandler > entry : contexts .entrySet ())
206- if (entry .getKey ().getPath ().equals (getContext (path )))
209+ if (entry .getKey ().getPath ().equals (ContextUtil . getContext (context , true , false )))
207210 return entry .getValue ();
208211 return null ;
209212 }
@@ -229,9 +232,9 @@ public synchronized final String getRandomContext(){
229232 public synchronized final String getRandomContext (final String context ){
230233 String targetContext ;
231234
232- final String head = context .isEmpty () ? "" : getContext (context );
235+ final String head = context .isEmpty () ? "" : ContextUtil . getContext (context , true , false );
233236
234- do targetContext = head + getContext (UUID .randomUUID ().toString ());
237+ do targetContext = head + ContextUtil . getContext (UUID .randomUUID ().toString (), true , false );
235238 while (getContextHandler (targetContext ) != null );
236239
237240 return targetContext ;
@@ -275,12 +278,4 @@ public String toString(){
275278 '}' ;
276279 }
277280
278- // start slash; no end slash
279- private static String getContext (final String path ){
280- final String linSlash = path .replace ("\\ " ,"/" );
281- if (linSlash .equals ("/" )) return "/" ;
282- final String seSlash = (!linSlash .startsWith ("/" ) ? "/" : "" ) + linSlash + (!linSlash .endsWith ("/" ) ? "/" : "" );
283- return seSlash .substring (0 ,seSlash .length ()-1 );
284- }
285-
286281}
0 commit comments