powered by Jive Software

Hi all ! org.xmlpull.v1.XmlparserException

I am writeing forum plugin of Jive Messenger , I am start socket to listen port(5533)

This is parse Message packet Error :

Socket connect Socket[addr=/10.1.16.32, port=1951, localport=5533]

org.xmlpull.v1.XmlPullParserException: start tag not allowed in epilog but got m

<position: IGNORABLE_WHITESPACE seen …\r\n<m…@2:3>

at org.xmlpull.mxp1.MXParser.parseEpilogMXParser.java:1588

at org.xmlpull.mxp1.MXParser.nextImplMXParser.java:1393

at org.xmlpull.mxp1.MXParser.nextTokenMXParser.java:1100

at org.dom4j.io.XPPPacketReader.parseDocumentXPPPacketReader.java:268

at org.jivesoftware.messenger.plugin.ForumSocketReader.readStream

public void run() {

try {

reader = new XPPPacketReader();

reader.setXPPFactory(factory);

try {

reader.getXPPParser().setInput(new InputStreamReader(socket.getInputStream(),CHARSET));

} catch (UnsupportedEncodingException e) {

e.printStackTrace();

} catch (IOException e) {

e.printStackTrace();

}

try {

readStream();

} catch (Exception e) {

e.printStackTrace();

}

}catch (XmlPullParserException e) {

e.printStackTrace();

}finally{

//shutdown();

}

private void readStream() throws Exception {

open = true;

while (open) {

Element doc = reader.parseDocument().getRootElement(); // ERROR

First Send Of Client is OK ,but continuity send is Error ! Why ?

Thanks !

Hey zhuam,

I see that the client is sending \r\n between the XML packets. I guess that those characters are making the parser fail. Try modifying the client so that those characters are not sent.

Regards,

– Gato

Hey Gota,

I am already change source on XML packets, but not solve problem ,

This is Exception :


org.xmlpull.v1.XmlPullParserException : start tag not allowed in epilog but got m

<position: END_TAG seen …<m… @1:96>

at org.xmlpull.mxp1.MXParser.parseEpilogMXParser.java:1588

at org.xmlpull.mxp1.MXParser.nextImplMXParser.java:1393

at org.xmlpull.mxp1.MXParser.nextTokenMXParser.java:1100

at org.dom4j.io.XPPPacketReader.parseDocumentXPPPacketReader.java:268

at org.jivesoftware.messenger.plugin.ForumSocketReader.readStream

at org.jivesoftware.messenger.plugin.ForumSocketReader.run<ForumSocketReader.java: 116>

at java.lang.Thread.runThread.java:595

This is source of ForumSocketReader.java


public class ForumSocketReader implements Runnable {

private static String CHARSET = “UTF-8”;

private static XmlPullParserFactory factory = null;

private MessageRouter messageRouter;

private PresenceRouter presenceRouter;

private XMPPServer localServer;

private Socket socket;

private Writer writer;

protected boolean open;

XPPPacketReader reader = null;

static {

try {

factory = XmlPullParserFactory.newInstance();

}

catch (XmlPullParserException e) {

Log.error(“Error creating a parser factory”, e);

}

}

public ForumSocketReader(XMPPServer xmppServer,Socket socket){

localServer = xmppServer;

messageRouter = localServer.getMessageRouter();

presenceRouter = localServer.getPresenceRouter();

this.socket = socket;

try {

writer = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream(), CHARSET));

} catch (UnsupportedEncodingException e) {

e.printStackTrace();

} catch (IOException e) {

e.printStackTrace();

}

}

public void run() {

try {

reader = new XPPPacketReader();

reader.setXPPFactory(factory);

try {

reader.getXPPParser().setInput(new InputStreamReader(socket.getInputStream(),CHARSET));

} catch (UnsupportedEncodingException e) {

e.printStackTrace();

} catch (IOException e) {

e.printStackTrace();

}

try {

readStream();

} catch (Exception e) {

e.printStackTrace();

}

}catch (XmlPullParserException e) {

e.printStackTrace();

}finally{

//shutdown();

}

}

private void readStream() throws Exception {

open = true;

while (open) {

Element doc = reader.parseDocument().getRootElement();

if (doc == null) {

// Stop reading the stream since the client has sent an end of

// stream element and probably closed the connection.

return;

}

String tag = doc.getName();

if (“message”.equals(tag)) {

Message packet = null;

packet = new Message(doc);

messageRouter.route(packet);

}

else{

//Unknow Packet

open = false;

}

}

}

}

protected void shutdown() {

messageRouter = null;

presenceRouter = null;

}

}

Message was edited by:

zhuam

This is test source :


import java.io.BufferedWriter;

import java.io.IOException;

import java.io.OutputStreamWriter;

import java.net.Socket;

public class testForum {

public static void main(String[] args) {

String host = “10.1.16.32”;

int port = 5533;

Socket soc=null;

String strout=null;

try

{

soc=new Socket(host,port);

System.out.println(“Connecting to the Server”);

BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(soc.getOutputStream(), “UTF-8”));

for(int i=1 ; i";

writer.write(strout);

writer.flush();

}

}

catch(Exception e)

{

System.out.println(“error:”+e);

}

finally

{

try {

soc.close();

} catch (IOException e) {

e.printStackTrace();

}

System.exit(0);

}

}

}

try using a valid xml document as input,

wrap the

for(int i=1 ; i");

writer.flush();

and modify the parser on the server side so it skips the first tag, eg

private void readStream() throws Exception {

//wait for the first tag using the underlying XmlPullParser…

XmlPullParser xpp = reader.getXPPParser();

for (int eventType = xpp.getEventType(); eventType != XmlPullParser.START_TAG;) {

eventType = xpp.next();

}

open = true;

while (open) {

Element doc = reader.parseDocument().getRootElement();

if (doc == null) {

// Stop reading the stream since the client has sent an end of

// stream element and probably closed the connection.

open = false;

}

}

}

see also

http://www.jivesoftware.org/fisheye/viewrep/cvs-org/whack/source/java/org/jiveso ftware/whack/ExternalComponent.java?r=1.7

line 160 to 193

hope this helps,

Bram

thanks for your bram !

I am already try using a valid xml document , add a Root Element , but is not a solve concatenation send message problem , I believe this problem should be also exist of Jive Messenger ,

I am current a solved method :

public String readStream(InputStream InStream) {

reader = new XPPPacketReader();

reader.setXPPFactory(factory);

try {

reader.getXPPParser().setInput(new InputStreamReader(InStream,CHARSET));

} catch (UnsupportedEncodingException e1) {

e1.printStackTrace();

} catch (XmlPullParserException e1) {

e1.printStackTrace();

}

Element doc = null;

try {

doc = reader.parseDocument().getRootElement();

} catch (DocumentException e1) {

e1.printStackTrace();

} catch (IOException e1) {

e1.printStackTrace();

} catch (XmlPullParserException e1) {

e1.printStackTrace();

}

if (doc == null) {

return “”;

}

ok, you’'re half way there

the trick is to “skip” the first element (the document root) and after the first element use the reader.parseDocument() method. then that method returns a document for each “sub element” of the root, so with a xml file like this :

end tag).

try it and when you put in a trace in thw while loop you should be able to echo the child elements of the root after they are send by the client.

bram

Message was edited by:

bram

hmm somehow the enters and spaces got messed up

Message was edited by:

ah, you cant use < a />

bram

thanks !