package com.gaowj.service.client.utils;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.rmi.RemoteException;
import java.util.Map;
import java.util.Properties;

import javax.servlet.http.HttpServletRequest;

import org.apache.axis2.AxisFault;
import org.quartz.core.QuartzScheduler;

public class AuthenticateUtil {
	
//	public static String getTokenId(){
//		
//		String tokenId = "-1";
//		String clientUser=getEndpoint("clientUser");
//		String clientPass=getEndpoint("clientPass");
//
//		try {
//			AuthorityServiceStub stub = new AuthorityServiceStub(getEndpoint("Authority"));
//			Authenticate au = new Authenticate();
//			au.setUserName(com.gaowj.business.util.Encipher.EncodePasswd(clientUser));
//			au.setPassword(com.gaowj.business.util.Encipher.EncodePasswd(clientPass));
//			AuthenticateResponse res = stub.authenticate(au);
//			tokenId = res.get_return().getId();
//		} catch (AxisFault e) {
//			tokenId = "-1";
//			//e.printStackTrace();
//		} catch (RemoteException e) {
//			tokenId = "-1";
//			//e.printStackTrace();
//		} catch (AuthorityServiceServiceExceptionException e) {
//			tokenId = "-1";
//			//e.printStackTrace();
//		}
//		
//		return tokenId;
//	}
//	public static String getTokenId(String route){
//		
//		String tokenId = "-1";
//		String clientUser=getEndpoint("clientUser");
//		String clientPass=getEndpoint("clientPass");
//		
//		try {
//			AuthorityServiceStub stub = new AuthorityServiceStub(getEndpoint(route));
//			Authenticate au = new Authenticate();
//			au.setUserName(com.gaowj.business.util.Encipher.EncodePasswd(clientUser));
//			au.setPassword(com.gaowj.business.util.Encipher.EncodePasswd(clientPass));
//			AuthenticateResponse res = stub.authenticate(au);
//			tokenId = res.get_return().getId();
//		} catch (AxisFault e) {
//			tokenId = "-1";
//			e.printStackTrace();
//		} catch (RemoteException e) {
//			tokenId = "-1";
//			e.printStackTrace();
//		} catch (AuthorityServiceServiceExceptionException e) {
//			tokenId = "-1";
//			e.printStackTrace();
//		}
//		
//		return tokenId;
//	}
	
	public static String getEndpoint(String target){
		
		InputStream in = QuartzScheduler.class.getResourceAsStream("/quartz_service.properties");
		Properties config = new Properties();
		String targetEndpoint = "";
		try {
			config.load(in);
			if (config.getProperty(target) != null) {
				targetEndpoint = config.getProperty(target);
			}
		 }
		catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		return  targetEndpoint;
	  }
	
	public static void main(String args[]){   
//		System.out.println(AuthenticateUtil.getEndpoint("Authority"));  
		String tt = "{\"NAME\":\"1\",\"VALUE\":\"保存成功!\"}";
		Map<String,Object> m = jsonFormatMap.getMap(tt);
		System.out.println(Integer.parseInt((String) m.get("NAME"))<0);
	}


}
