Smack XMPP Java:如何访问字节流请求 (OPEN) 的原始 XML 表示?

Smack XMPP Java: How to access the original XML reprsentation of a ByteStreamRequest (OPEN)?

我需要访问字节流初始化的原始 XML 表示,因为我需要与自定义实现通信。 toXML 方法只是重建 XMLStructur。

我已经尝试使用订阅实现来实现自定义调试器,但 StreamElement 也不包含原始发送的 XML 数据。

通过实施订阅调试器解决,该调试器可以将原始 XML 日志转发给侦听器。示例:

public class SubscribeDebugger 扩展了 SmackDebugger {

private static List<IncomingRequestDebugListener> incomingRequestDebugListeners = new ArrayList<>();
private static List<OutgoingRequestDebugListener> outgoingRequestDebugListeners = new ArrayList<>();
private static Boolean enableOutputToConsole;
private static SmackDebugger consoleDebugger;
private ReaderListener readerListener;
private WriterListener writerListener;
private ObservableWriter writer;
private ObservableReader reader;

public SubscribeDebugger(XMPPConnection connection) {
    super(connection);
    if (this.getEnableOutputToConsole()) {
        consoleDebugger = new ConsoleDebugger(connection);
    }
    readerListener = str -> notifyIncomingRequestDebugListeners(str.toString());
    writerListener = str -> notifyOutgoingRequestDebugListeners(str.toString());
}

public Boolean getEnableOutputToConsole() { return enableOutputToConsole; }
public static void setEnableOutputToConsole(Boolean active) {
    enableOutputToConsole = active;
}

/*Static part since a debugger will be initiated by xmpp connection. Smack does not
  provide access on the debugger instances. All instances share the listeners.*/
public static void registerIncomingRequestDebugListener (IncomingRequestDebugListener listener) {
    incomingRequestDebugListeners.add(listener);
}
public static void unregisterIncomingRequestDebugListener(IncomingRequestDebugListener listener) {
    incomingRequestDebugListeners.remove(listener);
}
public static void registerOutgoingRequestDebugListener (OutgoingRequestDebugListener listener) {
    outgoingRequestDebugListeners.add(listener);
}
public static void unregisterOutgoingRequestDebugListener(OutgoingRequestDebugListener listener) {
    outgoingRequestDebugListeners.remove(listener);
}
protected void notifyIncomingRequestDebugListeners (String streamElement) {
    incomingRequestDebugListeners.parallelStream().forEach((listener) -> {
        listener.onRequestReceived(streamElement);
    });
}
protected void notifyOutgoingRequestDebugListeners (String streamElement) {
    outgoingRequestDebugListeners.parallelStream().forEach((listener) -> {
        listener.onRequestSent(streamElement);
    });
}

@Override
public void userHasLogged(EntityFullJid user) {

}

@Override
public Reader newConnectionReader(Reader reader) {


    ObservableReader debugReader = new ObservableReader(reader);
    debugReader.addReaderListener(readerListener);
    reader = debugReader;

    if (enableOutputToConsole && consoleDebugger != null)
        return consoleDebugger.newConnectionReader(reader);
    return reader;
}

@Override
public Writer newConnectionWriter(Writer writer) {
    if(enableOutputToConsole && consoleDebugger != null)
        return consoleDebugger.newConnectionWriter(writer);
    return writer;
}

@Override
public void onIncomingStreamElement(TopLevelStreamElement streamElement) {
    if(enableOutputToConsole && consoleDebugger != null)
        consoleDebugger.onIncomingStreamElement(streamElement);


}

@Override
public void onOutgoingStreamElement(TopLevelStreamElement streamElement) {
    if (enableOutputToConsole && consoleDebugger != null)
        consoleDebugger.onOutgoingStreamElement(streamElement);

}

}