OpenNTF/SocialSDK

CommunityService.createData throws [Fatal Error] :1:1: Premature end of file

Closed this issue · 1 comments

Hey Paul,

I get the error:

[Fatal Error] :1:1: Premature end of file.

com.ibm.sbt.services.client.ClientServicesException: 
    at com.ibm.sbt.services.client.Response.parseContent(Response.java:164)
    at com.ibm.sbt.services.client.Response.<init>(Response.java:64)
    at com.ibm.sbt.services.client.ClientService.processResponse(ClientService.java:1326)
    at com.ibm.sbt.services.client.ClientService._xhr(ClientService.java:1235)
    at com.ibm.sbt.services.client.ClientService.execRequest(ClientService.java:1200)
    at com.ibm.sbt.services.client.ClientService.xhr(ClientService.java:1157)





Caused by: java.io.IOException
    at com.ibm.sbt.services.client.ClientService$HandlerXml.parseContent(ClientService.java:906)
    at com.ibm.sbt.services.client.Response.parseContent(Response.java:161)
    ... 42 more
Caused by: com.ibm.commons.xml.XMLException: Error parsing XML stream
    at com.ibm.commons.xml.drivers.XercesSunDriver.parse(XercesSunDriver.java:341)
    at com.ibm.commons.xml.DOMUtil.createDocument(DOMUtil.java:195)
    at com.ibm.commons.xml.DOMUtil.createDocument(DOMUtil.java:219)
    at com.ibm.sbt.services.client.ClientService$HandlerXml.parseContent(ClientService.java:904)
    ... 43 more
Caused by: org.xml.sax.SAXParseException; lineNumber: 1; columnNumber: 1; Premature end of file.
    at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(DOMParser.java:257)
    at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:339)
    at javax.xml.parsers.DocumentBuilder.parse(DocumentBuilder.java:121)
    at com.ibm.commons.xml.drivers.XercesSunDriver.parse(XercesSunDriver.java:332)
    ... 46 more

when running my Code.
Although the Bookmark I want to create in a Community will be created, I get the above mentioned error. The XML seems to be OK for me, having considered the fact that the Bookmark will be created successfully.

I am running the following Code:

public static boolean createCommunityBookMark(String communityUuid, String bookMarkTitle, String bookMarkURL,
      String bookMarkDescription, List<String> bookMarkTags)
          throws ClientServicesException, MalformedURLException, URISyntaxException {

    String serviceURL = Variables.baseURL + "/communities/service/atom/community/bookmarks?communityUuid=" + communityUuid;

    String content =
      "<entry xmlns=\"http://www.w3.org/2005/Atom\" xmlns:app=\"http://www.w3.org/2007/app\" xmlns:snx=\"http://www.ibm.com/xmlns/prod/sn\">"
        + "<category term=\"bookmark\" scheme=\"http://www.ibm.com/xmlns/prod/sn/type\">" + "</category>"
        + "<content type=\"html\">$DESCRIPTION</content>" + "<title type=\"text\">$TITLE</title>"
        + "<category term=\"$TAGTITLE\"/>";

    if (!bookMarkTags.isEmpty()) {
      for (String tag : bookMarkTags) {
        content += "<category term=\"$TAG\"/>".replace( "$TAG", tag );
      }
    }

    content += "<link href=\"$URL\">" + "</link>" + "</entry>";

    content = content.replace( "$TITLE", bookMarkTitle );
    content = content.replace( "$DESCRIPTION", bookMarkDescription );
    content = content.replace( "$TAGONE", bookMarkTitle );
    content = content.replace( "$TAGTWO", bookMarkTitle.substring( 0, bookMarkTitle.length() - 1 ).toLowerCase() );
    content = content.replace( "$URL", new URL( bookMarkURL ).toExternalForm() );
    content = content.replace( "$TAGTITLE", bookMarkTitle );

//Variables.aCommunityService is an instantiated CommunityService working properly because
//for instance creating a Community works perfectly.

    return Variables.aCommunityService.createData( serviceURL, null, content ).getResponse().getStatusLine()
      .getStatusCode() == 201;
  }

Calling:

 public static void test() throws ClientServicesException, MalformedURLException, URISyntaxException {
    List<String> tagz = new ArrayList<String>();
    tagz.add( "Hello" );
    BookmarksHandler.createCommunityBookMark( "2b0c1393-b692-42f6-9d34-8e89a90be962", "TESTTITLE", "http://www.google.de/",
      "TESTDESCRIPTION", tagz );
  }

Would be nice if you could take a look at.

Best regards,

Siri

Look at your XML stream you are getting back. It's most likely not XML. refer to https://github.com/OpenNTF/SocialSDK/wiki/Troubleshooting-Issues-with-the-SocialSDK