问题描述
这个就是我现在遇到的问题,请各位帮忙找下错误在哪?怎么解决?在tomcat6.0环境下,有乱码情况,浏览器报错500如上图。
packagecom.landray.sso.client.filter;importcom.landray.sso.client.EKPSSOChain;importcom.landray.sso.client.EKPSSOContext;importcom.landray.sso.client.util.Logger;importcom.landray.sso.client.util.StringUtil;importjava.io.IOException;importjava.util.HashMap;importjava.util.Map;importjava.util.Properties;importjavax.servlet.ServletException;importjavax.servlet.http.HttpServletRequest;importjavax.servlet.http.HttpServletResponse;importjavax.servlet.http.HttpSession;importorg.jasig.cas.client.authentication.AttributePrincipal;importorg.jasig.cas.client.util.CommonUtils;importorg.jasig.cas.client.util.XmlUtils;importorg.jasig.cas.client.validation.Assertion;importorg.jasig.cas.client.validation.Cas20ServiceTicketValidator;importorg.jasig.cas.client.validation.TicketValidationException;importorg.jasig.cas.client.validation.TicketValidator;publicclassCASURLFilterextendsAbstractFilter{privateMapsessionMap;privateStringcasServerUrlPrefix;privateStringticketParameterName;publicvoidinit(Propertiesprop)throwsServletException{this.sessionMap=newHashMap();this.casServerUrlPrefix=getConfigProperty(prop,"CASURLFilter.cas.server");this.ticketParameterName=getConfigProperty(prop,"CASURLFilter.cas.ticket");}publicvoiddestroy(){this.sessionMap=null;this.casServerUrlPrefix=null;this.ticketParameterName=null;}publicvoiddoFilter(EKPSSOContextcontext,EKPSSOChainchain)throwsIOException,ServletException{if("POST".equals(context.getRequest().getMethod()))doLogout(context,chain);elsedoLogin(context,chain);}privatevoiddoLogout(EKPSSOContextcontext,EKPSSOChainchain)throwsIOException,ServletException{StringlogoutRequest=CommonUtils.safeGetParameter(context.getRequest(),"logoutRequest");if(CommonUtils.isNotBlank(logoutRequest)){StringsessionIdentifier=XmlUtils.getTextForElement(logoutRequest,"SessionIndex");if(CommonUtils.isNotBlank(sessionIdentifier)){HttpSessionsession=(HttpSession)this.sessionMap.remove(sessionIdentifier);if(session!=null)try{session.invalidate();}catch(IllegalStateExceptionlocalIllegalStateException){}}}chain.doNextFilter();}privatevoiddoLogin(EKPSSOContextcontext,EKPSSOChainchain)throwsIOException,ServletException{HttpServletRequestrequest=context.getRequest();HttpServletResponseresponse=context.getResponse();Stringticket=request.getParameter(this.ticketParameterName);if((StringUtil.isNull(ticket))||(this.sessionMap.containsKey(ticket))){chain.doNextFilter();return;}Stringuri=request.getRequestURI();StringlocalServerName=request.getRequestURL().toString();if(StringUtil.isNotNull(uri)){localServerName=localServerName.substring(0,localServerName.length()-uri.length());}Logger.debug("锟斤拷URL锟叫伙拷取锟斤拷锟斤拷"+this.ticketParameterName+"锟斤拷锟斤拷为锟斤拷"+ticket);StringserviceURL=constructServiceUrl(request,response,null,localServerName,this.ticketParameterName,true);try{TicketValidatorvalidator=newCas20ServiceTicketValidator(this.casServerUrlPrefix);System.out.println("CASURLFilter..1..ticket..."+ticket);System.out.println("CASURLFilter..2..serviceURL..."+serviceURL);Assertionassertion=validator.validate(ticket,serviceURL);Stringusername=assertion.getPrincipal().getName();Logger.debug("锟斤拷锟斤拷锟斤拷证票锟捷o拷锟矫碉拷锟矫伙拷锟斤拷"+username);if(StringUtil.isNotNull(username))context.setCurrentUsername(username);elseticket=null;}catch(TicketValidationExceptione){response.setStatus(403);thrownewServletException(e);}chain.doNextFilter();if((chain.isFinish())&&(ticket!=null))this.sessionMap.put(ticket,request.getSession());}publicstaticStringconstructServiceUrl(HttpServletRequestrequest,HttpServletResponseresponse,Stringservice,StringserverName,StringartifactParameterName,booleanencode){if(isNotBlank(service)){returnencode?response.encodeURL(service):service;}StringBufferbuffer=newStringBuffer();synchronized(buffer){if((!serverName.startsWith("https://"))&&(!serverName.startsWith("http://"))){buffer.append(request.isSecure()?"https://":"http://");}buffer.append(serverName);buffer.append(request.getRequestURI());if(isNotBlank(request.getQueryString())){intlocation=request.getQueryString().indexOf(artifactParameterName+"=");if(location==0){StringreturnValue=encode?response.encodeURL(buffer.toString()):buffer.toString();System.out.println("serviceUrlgenerated:"+returnValue);returnreturnValue;}buffer.append("?");if(location==-1){buffer.append(request.getQueryString());}elseif(location>0){intactualLocation=request.getQueryString().indexOf("&"+artifactParameterName+"=");if(actualLocation==-1)buffer.append(request.getQueryString());elseif(actualLocation>0){buffer.append(request.getQueryString().substring(0,actualLocation));}}}}StringreturnValue=encode?response.encodeURL(buffer.toString()):buffer.toString();System.out.println("serviceUrlgenerated:"+returnValue);returnreturnValue;}publicstaticbooleanisEmpty(Stringstring){return(string==null)||(string.length()==0);}publicstaticbooleanisNotEmpty(Stringstring){return!isEmpty(string);}publicstaticbooleanisBlank(Stringstring){return(isEmpty(string))||(string.trim().length()==0);}publicstaticbooleanisNotBlank(Stringstring){return!isBlank(string);}}
<?xmlversion="1.0"encoding="UTF-8"?><web-appversion="2.5"xmlns="http://java.sun.com/xml/ns/javaee"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://java.sun.com/xml/ns/javaeehttp://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"><display-name></display-name><filter><filter-name>EKPSSOClient</filter-name><filter-class>com.landray.sso.client.EKPSSOClient</filter-class><init-param><description>对应的配置文件位置</description><param-name>filterConfigFile</param-name><param-value>/sso-config.properties</param-value></init-param></filter><filter-mapping><filter-name>EKPSSOClient</filter-name><url-pattern>/*</url-pattern></filter-mapping><filter><filter-name>EKPSSOClientAuthenticationFilter</filter-name><filter-class>com.landray.sso.client.EKPSSOClient</filter-class><init-param><param-name>filterclien</param-name><param-value>/EKPSSOClientAuthenticationFilter</param-value></init-param></filter><filter-mapping><filter-name>EKPSSOClientAuthenticationFilter</filter-name><url-pattern>/*</url-pattern></filter-mapping><servlet><servlet-name>webserver</servlet-name><servlet-class>Webserver</servlet-class></servlet><servlet-mapping><servlet-name>webserver</servlet-name><url-pattern>/webserver</url-pattern></servlet-mapping><welcome-file-list><welcome-file>index.jsp</welcome-file></welcome-file-list></web-app>
解决方案
本帖最后由 u013283773 于 2013-12-26 11:44:46 编辑