acs java_acsservlet.java 源代码在线查看 - openacs source for CPE wan management 资源下载 虫虫电子下载站...

/* * ACSServlet.java * * Created on Sekmadienis, 2007, Rugs雑o 9, 14.39 */package org.openacs;import java.io.ByteArrayOutputStream;import java.io.FileInputStream;import java.io.IOException;import java.io.InputStream;import java.io.OutputStream;import java.net.Authenticator;import java.net.PasswordAuthentication;import java.util.Calendar;import java.util.Collection;import java.util.logging.*;import java.util.NoSuchElementException;import java.util.Set;import javax.servlet.*;import javax.servlet.http.*;import javax.xml.soap.*;import javax.ejb.CreateException;import javax.ejb.FinderException;import javax.jms.JMSException;import javax.jms.MessageConsumer;import javax.jms.ObjectMessage;import org.openacs.message.*;import org.openacs.utils.*;/** * * @author Administrator * @version */public class ACSServlet extends HttpServlet { private class MyAuthenticator extends Authenticator { @Override protected PasswordAuthentication getPasswordAuthentication() { String ui = this.getRequestingURL().getUserInfo(); System.out.println ("MyAuthenticator: ui="+ui); if (ui == null || ui.equals("")) return super.getPasswordAuthentication(); String up[] = ui.split(":"); char[] pc = new char[up[1].length()]; up[1].getChars(0, up[1].length(), pc, 0); PasswordAuthentication pa = new PasswordAuthentication(up[0], pc); return pa; } } private class xmlFilterInputStream extends InputStream { /** Creates a new instance of xmlFilterInputStream */ public xmlFilterInputStream(InputStream is, int l) { // System.out.println("Stream length is "+l); len = l; istream = is; } public int read() throws IOException { if (lastchar == '>' && lvl == 0) { // System.err.println ("return EOF"); return -1; } int l = lastchar; if (nextchar != -1) { lastchar = nextchar; nextchar = -1; } else { lastchar = istream.read(); } if (l == ' if (lastchar == '/') { lvl--; } else { lvl++; } } // System.err.println ("return char="+(char)lastchar+" lvl="+lvl); //System.err.print ((char)lastchar); len--; return lastchar; } private InputStream istream; private int lvl; private int lastchar; private int len; private int nextchar; public boolean next() throws IOException { while ((nextchar = istream.read()) != -1) { if (!Character.isWhitespace(nextchar)) { break; } } // System.out.println ("Next char is "+nextchar); lvl = 0; lastchar = 0; return (nextchar != -1); } } private boolean authenticate(HostsLocal host, HttpServletRequest request, HttpServletResponse response) throws IOException { /* System.out.println ("host="+host +" request="+request+" response="+response); System.out.println ("user="+host.getUsername()); System.out.println ("pass="+host.getPassword()); System.out.println ("authtype="+host.getAuthtype()); */ return HttpAuthentication.Authenticate(host.getUsername(), host.getPassword(), host.getAuthtype(), request, response); } /** * Processes requests for both HTTP GET and POST methods. * * * * @param request ACSServlet request * @param response ACSServlet response */ protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { Logger logger = Logger.getLogger(getClass().getName()); ServletContext ctx = getServletContext(); boolean autoCreateCPE = Boolean.parseBoolean(ctx.getInitParameter("org.openacs.AutoCreateCPE"));// OutputStream out = response.getOutputStream(); ByteArrayOutputStream out = new ByteArrayOutputStream(); SOAPMessage soapMsg = null;// FileInputStream fi = new FileInputStream("c:\\tmp\\tst.xml");// xmlFilterInputStream f = new xmlFilterInputStream(fi, fi.available()); xmlFilterInputStream f = new xmlFilterInputStream(request.getInputStream(), request.getContentLength()); MessageFactory mf; //SOAPFactory spf; try { mf = MessageFactory.newInstance(); //spf = SOAPFactory.newInstance(); } catch (SOAPException e) { throw new ServletException(); } response.setContentType("text/xml;charset=UTF-8"); //response.setContentType("text/xml"); int countEnvelopes = 0; HttpSession session = request.getSession(); String oui, sn; Inform lastInform = (Inform) session.getAttribute("lastInform"); /* int maxEnvelopes = (lastInform != null) ? lastInform.MaxEnvelopes : 2; if (maxEnvelopes < 2) { System.out.println("MaxEnvelopes are less then 2 (" + maxEnvelopes + "). Setting to 2"); maxEnvelopes = 2; } */ int maxEnvelopes = (lastInform != null) ? lastInform.MaxEnvelopes : MIN_MAX_ENVELOPES; if (maxEnvelopes < MIN_MAX_ENVELOPES) { System.out.println("MaxEnvelopes are less then " + MIN_MAX_ENVELOPES + " (" + maxEnvelopes + "). Setting to " + MIN_MAX_ENVELOPES); maxEnvelopes = 1; } // // QueueSession queuesession = null;// javax.jms.Queue queue = null; // // HardwareModelLocal hw = (HardwareModelLocal) session.getAttribute("hardware"); HostsLocal lasthost = (HostsLocal) session.getAttribute("host"); while (f.next()) { try { //System.out.println("createMessage"); soapMsg = mf.createMessage(null, f); String reqname = Message.getRequestName(soapMsg); System.out.println("Request is " + reqname); Message msg = null; try { msg = (Message) Class.forName("org.openacs.message." + reqname).newInstance(); } catch (IllegalAccessException ex) { ex.printStackTrace(); return; } catch (InstantiationException ex) { ex.printStackTrace(); return; } catch (ClassNotFoundException ex) { ex.printStackTrace(); return; } msg.parse(soapMsg); logger.log(Level.FINEST, msg.toString()); //if (msg.isFault()) { continue; } try { // if (reqname.equals("Inform")) { lastInform = (Inform) msg; session.setAttribute("lastInform", lastInform); InformResponse resp = new InformResponse(lastInform.getId (), MY_MAX_ENVELOPES); resp.writeTo(out); countEnvelopes++; maxEnvelopes = lastInform.MaxEnvelopes; sn = lastInform.sn; oui = lastInform.oui; String url = lastInform.getURL(); //System.out.println("oui="+oui+", sn="+sn+", URL="+url); logger.log(Level.INFO, "oui=" + oui + ", sn=" + sn + ", URL=" + url + ", hw=" + lastInform.getHardwareVersion() + ", sw=" + lastInform.getSoftwareVersion() + ", cfg=" + lastInform.getConfigVersion()+", ProvisioningCode="+lastInform.getProvisiongCode()); HardwareModelLocalHome hwhome = Ejb.lookupHardwareModelBean(); try { hw = hwhome.findByOuiAndClassAndVersion(oui, lastInform.ProductClass, lastInform.getHardwareVersion()); } catch (FinderException e) { try { hw = hwhome.create(lastInform.ProductClass, lastInform.Manufacturer, oui, lastInform.ProductClass, lastInform.getHardwareVersion()); } catch (CreateException ex) { ex.printStackTrace(); throw new RuntimeException(); } } // HardwareModelLocal hwold = null; try { hwold = hwhome.findByOuiAndClass(oui, lastInform.ProductClass); } catch (FinderException ex) { } // session.setAttribute("hardware", hw); HostsLocalHome hsthome = Ejb.lookupHostsBean(); //System.out.println("SERVLET: looked up HostsLocalHome"); HostsLocal host = null; // if (hwold != null) { try { host = hsthome.findByHwidAndSn((Integer) hwold.getId(), sn); host.setHwid((Integer)hw.getId()); } catch (FinderException ex) { } } // try {

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值