📄 multiplexerpackethandler.java
字号:
else { Element extraError = DocumentHelper.createElement(QName.get( "unknown-stanza", "http://jabber.org/protocol/connectionmanager#errors")); sendErrorPacket(route, PacketError.Condition.bad_request, extraError); } } catch (UnsupportedEncodingException e) { Log.error("Error processing wrapped packet: " + wrappedElement.asXML(), e); sendErrorPacket(route, PacketError.Condition.internal_server_error, null); } } private void processIQ(ClientSession session, IQ packet) { packet.setFrom(session.getAddress()); try { // Invoke the interceptors before we process the read packet InterceptorManager.getInstance().invokeInterceptors(packet, session, true, false); router.route(packet); // Invoke the interceptors after we have processed the read packet InterceptorManager.getInstance().invokeInterceptors(packet, session, true, true); session.incrementClientPacketCount(); } catch (PacketRejectedException e) { // An interceptor rejected this packet so answer a not_allowed error IQ reply = new IQ(); reply.setChildElement(packet.getChildElement().createCopy()); reply.setID(packet.getID()); reply.setTo(session.getAddress()); reply.setFrom(packet.getTo()); reply.setError(PacketError.Condition.not_allowed); session.process(reply); // Check if a message notifying the rejection should be sent if (e.getRejectionMessage() != null && e.getRejectionMessage().trim().length() > 0) { // A message for the rejection will be sent to the sender of the rejected packet Message notification = new Message(); notification.setTo(session.getAddress()); notification.setFrom(packet.getTo()); notification.setBody(e.getRejectionMessage()); session.process(notification); } } } private void processPresence(ClientSession session, Presence packet) { packet.setFrom(session.getAddress()); try { // Invoke the interceptors before we process the read packet InterceptorManager.getInstance().invokeInterceptors(packet, session, true, false); router.route(packet); // Invoke the interceptors after we have processed the read packet InterceptorManager.getInstance().invokeInterceptors(packet, session, true, true); session.incrementClientPacketCount(); } catch (PacketRejectedException e) { // An interceptor rejected this packet so answer a not_allowed error Presence reply = new Presence(); reply.setID(packet.getID()); reply.setTo(session.getAddress()); reply.setFrom(packet.getTo()); reply.setError(PacketError.Condition.not_allowed); session.process(reply); // Check if a message notifying the rejection should be sent if (e.getRejectionMessage() != null && e.getRejectionMessage().trim().length() > 0) { // A message for the rejection will be sent to the sender of the rejected packet Message notification = new Message(); notification.setTo(session.getAddress()); notification.setFrom(packet.getTo()); notification.setBody(e.getRejectionMessage()); session.process(notification); } } } private void processMessage(ClientSession session, Message packet) { packet.setFrom(session.getAddress()); try { // Invoke the interceptors before we process the read packet InterceptorManager.getInstance().invokeInterceptors(packet, session, true, false); router.route(packet); // Invoke the interceptors after we have processed the read packet InterceptorManager.getInstance().invokeInterceptors(packet, session, true, true); session.incrementClientPacketCount(); } catch (PacketRejectedException e) { // An interceptor rejected this packet if (e.getRejectionMessage() != null && e.getRejectionMessage().trim().length() > 0) { // A message for the rejection will be sent to the sender of the rejected packet Message reply = new Message(); reply.setID(packet.getID()); reply.setTo(session.getAddress()); reply.setFrom(packet.getTo()); reply.setType(packet.getType()); reply.setThread(packet.getThread()); reply.setBody(e.getRejectionMessage()); session.process(reply); } } } private IQ getIQ(Element doc) { Element query = doc.element("query"); if (query != null && "jabber:iq:roster".equals(query.getNamespaceURI())) { return new Roster(doc); } else { return new IQ(doc); } } /** * Sends an IQ error with the specified condition to the sender of the original * IQ packet. * * @param packet the packet to be bounced. * @param extraError application specific error or null if none. */ private void sendErrorPacket(IQ packet, PacketError.Condition error, Element extraError) { IQ reply = IQ.createResultIQ(packet); reply.setChildElement(packet.getChildElement().createCopy()); reply.setError(error); if (extraError != null) { // Add specific application error if available reply.getError().getElement().add(extraError); } deliver(reply); } /** * Sends an IQ error with the specified condition to the sender of the original * IQ packet. * * @param packet the packet to be bounced. * @param extraError application specific error or null if none. */ private void sendErrorPacket(Route packet, PacketError.Condition error, Element extraError) { Route reply = new Route(packet.getStreamID()); reply.setID(packet.getID()); reply.setFrom(packet.getTo()); reply.setTo(packet.getFrom()); reply.setError(error); if (extraError != null) { // Add specific application error if available reply.getError().getElement().add(extraError); } deliver(reply); } /** * Sends an IQ result packet confirming that the operation was successful. * * @param packet the original IQ packet. */ private void sendResultPacket(IQ packet) { IQ reply = IQ.createResultIQ(packet); reply.setChildElement(packet.getChildElement().createCopy()); deliver(reply); } private void deliver(Packet reply) { // Get any session of the connection manager to deliver the packet ConnectionMultiplexerSession session = multiplexerManager.getMultiplexerSession(connectionManagerDomain); if (session != null) { session.deliver(reply); } else { Log.warn("No multiplexer session found. Packet not delivered: " + reply.toXML()); } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -