📄 webservicedecorator.java
字号:
/*
* Copyright 2003-2005 the original author or authors.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package com.jdon.controller.service;
import javax.servlet.http.HttpServletRequest;
import com.jdon.container.ContainerWrapper;
import com.jdon.container.access.ServiceAccessor;
import com.jdon.container.access.TargetMetaRequest;
import com.jdon.container.finder.ComponentKeys;
import com.jdon.container.finder.ContainerCallback;
import com.jdon.container.visitor.ComponentVisitor;
import com.jdon.container.visitor.data.SessionContext;
import com.jdon.security.web.UserPrincipalSetup;
/**
* before accessing container, we can do something and store
* some state into UserTargetMetaDef object.
*
* @author <a href="mailto:banqJdon<AT>jdon.com">banq</a>
*
*/
public class WebServiceDecorator implements WebServiceAccessor {
private ServiceAccessor serviceAccessor;
private ContainerCallback containerCallback;
/**
* @param serviceAccessor
*/
public WebServiceDecorator(ServiceAccessor serviceAccessor, ContainerCallback containerCallback) {
this.serviceAccessor = serviceAccessor;
this.containerCallback = containerCallback;
}
/*
* 1. create a SessionContext object in httpsession
* 2. save the principle name in the session context.
* the principle name the request.getPrincipleNme
* you can save more attribute in the SessionContext object by replcaing this class in container.xml
*
*/
public Object getService(TargetMetaRequest targetMetaRequest, HttpServletRequest request) {
ContainerWrapper cw = containerCallback.getContainerWrapper();
UserPrincipalSetup userPrincipalSetup = (UserPrincipalSetup)cw.lookup(ComponentKeys.SESSIONCONTEXT_SETUP);
targetMetaRequest.setVisitableName(ComponentKeys.SESSIONCONTEXT_FACTORY);
ComponentVisitor componentVisitor = targetMetaRequest.getComponentVisitor();
SessionContext sessionContext = (SessionContext)componentVisitor.visitSessionContext(targetMetaRequest);
targetMetaRequest.setSessionContext(sessionContext);
userPrincipalSetup.saveSessionContext(sessionContext, request);
return serviceAccessor.getService(targetMetaRequest);
}
/*
* 1. create a SessionContext object in httpsession
* 2. save the principle name in the session context.
* the principle name the request.getPrincipleNme
* you can save more attribute in the SessionContext object by replcaing this class in container.xml
*/
public Object execute(TargetMetaRequest targetMetaRequest, HttpServletRequest request) throws Exception {
ContainerWrapper cw = containerCallback.getContainerWrapper();
UserPrincipalSetup sessionContextSetup = (UserPrincipalSetup)cw.lookup(ComponentKeys.SESSIONCONTEXT_SETUP);
targetMetaRequest.setVisitableName(ComponentKeys.SESSIONCONTEXT_FACTORY);
ComponentVisitor componentVisitor = targetMetaRequest.getComponentVisitor();
SessionContext sessionContext = (SessionContext)componentVisitor.visitSessionContext(targetMetaRequest);
targetMetaRequest.setSessionContext(sessionContext);
sessionContextSetup.saveSessionContext(sessionContext, request);
return serviceAccessor.executeService(targetMetaRequest, cw);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -