@WebService(
endpointInterface = "com.nssc.website.out.ws.IResourceManager"
,serviceName = "WsResourceManager"
)
public class ResourceManager implements IResourceManager {
private final static Logger LOG = LoggerFactory.getLogger(SystemContext.class);
@Resource
private WebServiceContext wsContext;
@Override
public void operateResource(String validate, ResOptTask task) throws WebsiteWsException {
try {
if(!Security.getMD5(task.getPath()).equals(validate)) {
throw new RuntimeException();
}
} catch(Exception e) {
String ip = getIpOfRequest();
LOG.error("Illegal access !!![ip = " + ip + "]");
throw new WebsiteWsException("Illegal access !!![ip = " + ip + "]");
}
SystemContext.getTaskRunner().addTask(task);
}
/**
* 获取请求端ip
* @return
*/
private String getIpOfRequest() {
try {
MessageContext mc = wsContext.getMessageContext();
HttpServletRequest request = (HttpServletRequest)(mc.get(MessageContext.SERVLET_REQUEST));
return request.getRemoteAddr();
} catch (Exception e) {
LOG.error("Fail to fetch client Address.", e);
return "";
}
}