⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 s3ocoremodel.java

📁 单点登陆
💻 JAVA
字号:
package net.s3o.core;

import java.io.IOException;
import java.net.MalformedURLException;
import java.util.Map;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.s3o.common.ClientInfoWrapper;
import net.s3o.common.IPasswordHandler;
import net.s3o.common.PasswordHandlerImpl;
import net.s3o.common.S3OConstant;
import net.s3o.common.S3OUtils;
import net.s3o.core.method.ServerMethodCenter;
import net.s3o.core.method.ServerMethodProxyCenter;
import net.s3o.core.service.ServiceInvoker;
import net.s3o.core.service.ServiceInvokerCenter;
import net.s3o.core.service.ServiceProxyCenter;
import net.s3o.server.cache.ServerCacheManager;

import org.springframework.beans.factory.InitializingBean;
import org.springframework.util.AntPathMatcher;
import org.springframework.util.PathMatcher;

public abstract class S3OCoreModel implements IS3OCoreModel,InitializingBean {
	
	public static String serverURL=null;
	public static String clientURL=null;

	public static String systemKey=null;
	
	protected static String serverMethodRequestPrefix=null;
	
	protected static String serviceRequestPrefix=null;
	
	protected ServiceInvokerCenter serviceInvokerCenter=null;
	
	protected ServiceProxyCenter serviceProxyCenter=null;
	
	protected ServerMethodCenter serverMethodCenter=null;
	
	protected ServerMethodProxyCenter serverMethodProxyCenter=null;
	

	public static IPasswordHandler passwordHandler=new PasswordHandlerImpl();
	
	
	protected PathMatcher pathMatcher = new AntPathMatcher();
	
	protected String passURL=null;
	
	
	abstract public boolean mainFunction(HttpServletRequest request, HttpServletResponse response) throws ServletException;
	
	
	abstract public boolean afterChain(HttpServletRequest request, HttpServletResponse response) throws ServletException;
	
	public boolean isServiceRequest(HttpServletRequest request, HttpServletResponse response) {
//		String servletPath=request.getServletPath();
		String requestURI=request.getRequestURI()+"/";
		String webPath=request.getContextPath();
		return request.getMethod().equals("POST")	&& 
				requestURI.startsWith(webPath+S3OCoreModel.getServiceRequestPrefix()+"/");
	
	}
	
	public boolean isServerMethodRequest(HttpServletRequest request, HttpServletResponse response) {
//		String servletPath=request.getServletPath();
		String requestURI=request.getRequestURI()+"/";
		String webPath=request.getContextPath();

		return requestURI.startsWith(webPath+S3OCoreModel.getServerMethodRequestPrefix()+"/");

	}
	
	public void invokeService(HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException{
		
			String serviceName=serviceInvokerCenter.getServiceName(request);
			ServiceInvoker invoker=serviceInvokerCenter.getSerivecInvoker(serviceName);
			serviceInvokerCenter.invokeService(request,response,invoker);

	}

	
	public boolean invokeServerMethod(HttpServletRequest request, HttpServletResponse response) throws ServletException {
		return serverMethodCenter.invokeServerMethod(request, response);
	}
	

	public Object callRemoteServiceByName(String proxyName, Object arguments) throws IOException, ServletException {
		return serviceProxyCenter.callRemoteServiceByName(proxyName, arguments);
	}

	public Object callRemoteServiceByURL(String serviceURL, Object arguments) throws IOException, ServletException {
		return ServiceProxyCenter.callRemoteServiceByURL(serviceURL, arguments);
	}
	
	
	public boolean callRemoteServerMethodByName(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
		String proxyName=null;
		Map arguments=null;
		return serverMethodProxyCenter.callRemoteServerMethodByName(request, response,proxyName, arguments);
	}

	public boolean callRemoteServerMethodByURL(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
		String serverMethodURL=null;
		return serverMethodProxyCenter.callRemoteServerMethodByURL(request, response,serverMethodURL);
	}
	
    public static void callServerMethod(HttpServletRequest request, HttpServletResponse response,String methodName,String queryString) throws IOException{
		StringBuffer serverMethodURL=new StringBuffer(serverURL).append(getServerMethodRequestPrefix()).append("?");
		serverMethodURL.append(S3OConstant.FIELD_SERVER_METHOD).append("=").append(methodName);
		serverMethodURL.append("&").append(queryString);
		S3OUtils.sendRedirect(request, response,serverMethodURL.toString());
    }
    
	public static Object[] doBroadcast(String serviceName,Object arguments){
		ClientInfoWrapper[] clientInfos=ServerCacheManager.getAllClients();
		Object[] results=new Object[clientInfos.length];
		
		if (clientInfos!=null){
			String url=null;
			String sp=null;
			for (int i=0;i<clientInfos.length;i++){
				try {
					url=clientInfos[i].getClientURL();
					sp=clientInfos[i].getClientServicePrefix();
					results[i]=ServiceProxyCenter.callRemoteServiceByURL(url+sp+"/"+serviceName, arguments);
				} catch (MalformedURLException e) {
					results[i]=null;
				}
			}
		}
		return results;
	}
	
	


	
	
	public ServiceInvokerCenter getServiceInvokerCenter() {
		return serviceInvokerCenter;
	}


	public void setServiceInvokerCenter(ServiceInvokerCenter serviceInvokerCenter) {
		this.serviceInvokerCenter = serviceInvokerCenter;
	}


	public ServiceProxyCenter getServiceProxyCenter() {
		return serviceProxyCenter;
	}

	
	public void setServiceProxyCenter(ServiceProxyCenter serviceProxyCenter) {
		this.serviceProxyCenter = serviceProxyCenter;
	}


	public ServerMethodProxyCenter getServerMethodProxyCenter() {
		return serverMethodProxyCenter;
	}

	public void setServerMethodProxyCenter(
			ServerMethodProxyCenter serverMethodProxyCenter) {
		this.serverMethodProxyCenter = serverMethodProxyCenter;
	}



	public ServerMethodCenter getServerMethodCenter() {
		return serverMethodCenter;
	}


	public void setServerMethodCenter(ServerMethodCenter serverMethodCenter) {
		this.serverMethodCenter = serverMethodCenter;
	}

	
	
	
	
	public static String getServerMethodRequestPrefix() {
		return serverMethodRequestPrefix;
	}

	public void setServerMethodRequestPrefix(String serverMethodRequestPrefix) {
		S3OCoreModel.serverMethodRequestPrefix = serverMethodRequestPrefix;
	}

	public static String getServiceRequestPrefix() {
		return serviceRequestPrefix;
	}

	public void setServiceRequestPrefix(String serviceRequestPrefix) {
		S3OCoreModel.serviceRequestPrefix = serviceRequestPrefix;
	}



	
	public String getSystemKey() {
		return S3OCoreModel.systemKey;
	}


	public void setSystemKey(String systemKey) {
		S3OCoreModel.systemKey=systemKey;
		
	}
	
	public static String getClientURL() {
		return S3OCoreModel.clientURL;
	}


	public void setClientURL(String clientURL) {
		S3OCoreModel.clientURL = clientURL;
	}


	public static String getServerURL() {
		return S3OCoreModel.serverURL;
	}


	public void setServerURL(String serverURL) {
		S3OCoreModel.serverURL = serverURL;
	}


	public String getPassURL() {
		return passURL;
	}


	public void setPassURL(String passURL) {
		this.passURL = passURL;
	}

	public static IPasswordHandler getPasswordHandler() {
		return passwordHandler;
	}

	public void setPasswordHandler(IPasswordHandler passwordHandler) {
		S3OCoreModel.passwordHandler = passwordHandler;
	}



}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -