001/* 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017package org.apache.wicket.protocol.ws.javax; 018 019import org.apache.wicket.protocol.http.WebApplication; 020import org.apache.wicket.protocol.http.WicketFilter; 021import org.apache.wicket.protocol.ws.AbstractUpgradeFilter; 022import org.apache.wicket.util.string.Strings; 023 024import java.util.Enumeration; 025 026import javax.servlet.FilterConfig; 027import javax.servlet.ServletContext; 028import javax.servlet.ServletException; 029 030/** 031 * An upgrade filter that setups javax.websocket 032 */ 033public class JavaxWebSocketFilter extends AbstractUpgradeFilter 034{ 035 public JavaxWebSocketFilter() 036 { 037 super(); 038 } 039 040 public JavaxWebSocketFilter(WebApplication application) 041 { 042 super(application); 043 } 044 045 @Override 046 public void init(final boolean isServlet, final FilterConfig filterConfig) throws ServletException 047 { 048 super.init(isServlet, new JavaxWebSocketFilterConfig(filterConfig)); 049 } 050 051 /** 052 * A wrapper of the passed FilterConfig in #init() that adds #WICKET_WEB_SOCKET_PATH to 053 * the list of ignored paths 054 */ 055 private static class JavaxWebSocketFilterConfig implements FilterConfig 056 { 057 private final FilterConfig delegate; 058 059 private JavaxWebSocketFilterConfig(FilterConfig delegate) 060 { 061 this.delegate = delegate; 062 } 063 064 @Override 065 public String getFilterName() 066 { 067 return delegate.getFilterName(); 068 } 069 070 @Override 071 public ServletContext getServletContext() 072 { 073 return delegate.getServletContext(); 074 } 075 076 @Override 077 public String getInitParameter(String s) 078 { 079 String result = delegate.getInitParameter(s); 080 081 if (WicketFilter.IGNORE_PATHS_PARAM.equalsIgnoreCase(s)) 082 { 083 if (Strings.isEmpty(result)) 084 { 085 result = WicketServerEndpointConfig.WICKET_WEB_SOCKET_PATH; 086 } 087 else 088 { 089 result = result + ',' + WicketServerEndpointConfig.WICKET_WEB_SOCKET_PATH; 090 } 091 } 092 093 return result; 094 } 095 096 @Override 097 public Enumeration<String> getInitParameterNames() 098 { 099 return delegate.getInitParameterNames(); 100 } 101 } 102}