powered by Jive Software

Openfire Chat API


#1

I am trying to build a new web based client for Openfire to replace the outdated and abandoned Flash-based Sparkweb. The project is called Pade (A Yoruba word for Meeting) and my first step was to decide on my web client API.

Representational state transfer (REST) has now become the standard for abstracting request/response type web services into an API. When it is combined with Server Sent Events (otherwise known as Event Source), the result is a fresh new way of providing two-way real-time communication between web clients and a server using synchronous requests/responses (IQ) with REST and asynchronous evening (Message, Presence) with SSE. The really cool feature of SSE is the automatic re-connection by the web browser.

The Rest API plugin by Redor is brilliant . It allows you to administer Openfire via a RESTful API. Most of the common functions we do from the Openfire admin console web application can now be automated and integrated into server-side Java plugins or client-side web applications with ease. After spending hours inside the code and extending it for use at work to manage all the telephony entities we use with our Openlink XEP from the various commercial plugins we develop, it became clear that REST+SSE is the way forward for web-based real time messaging. Don’t take my work for it. Read what the folks at erlang-solutions.com have to say.

As my first step towards implementing Pade, I have built a Chat API plugin by extending the REST API plugin with SSE and Jetty web authentication taken from the Openfire meetings plugin. The plugin now runs on the HTTP-BIND (7070/7443) port instead of the admin (9090/9091) port. It authenticates you as an Openfire user once and reuses the authentication for REST, SSE and XMPP bosh/websockets. It supports everything you can do with the REST API plus Bookmarks and SIP Accounts as an admin user. It then enables you as a normal user to handle presence, chat, groupchat, contacts and users with just a handful of REST requests and SSE events.

Documentation can be found on GitHub Wiki pages


#2

Added SwaggerUI to Chat API. Allows easy quickly find an API endpoint and try it out on your Openfire server.


#3

This really looks nice! Sorry it might be dumb question but I could find multiple jar files in your github repository. Which one should I use to add into Openfire plugin to get this UI and other features?


#4

Where is the Chat API plugin? It’s not listed in the plugin directory. What am I missing?


#5

It is in a state of flux.

The old version built with ANT is deprecated and can be found here in the igniterealtime repo at

The new version built with Maven is still in development and can be found in my personal repo at

I intend to move in back into its own repo on igniterealtime at some point when I am free to work on it.


#6

Can you please let me where will I get this new version of ChatAPI plugin. I need it urgently. I am using openfire 4.2.3 and found one older version of chat API.jar. Using that I am getting response code 500 error while posting message to a chat room.

Request ur urgent help . Thanks


#7

Try


#8

Thanks Dele. But I am getting this error: while trying to use this. Can you please help me on this:

2018.06.09 23:20:57 org.jivesoftware.openfire.plugin.rest.exceptions.RESTExceptionMapper - IllegalArgumentException: Exception with ressource Exception
2018.06.09 23:21:30 org.jivesoftware.openfire.plugin.rest.exceptions.RESTExceptionMapper - IllegalArgumentException: Exception with ressource Exception
2018.06.09 23:31:00 org.jivesoftware.openfire.plugin.rest.exceptions.RESTExceptionMapper - IllegalArgumentException: Exception with ressource Exception
2018.06.09 23:33:45 org.jivesoftware.openfire.plugin.rest.RESTServicePlugin - refreshClientCerts
java.lang.NullPointerException
at org.jivesoftware.openfire.plugin.rest.RESTServicePlugin$3.call(RESTServicePlugin.java:1047)
at org.jivesoftware.openfire.plugin.rest.RESTServicePlugin$3.call(RESTServicePlugin.java:1036)
at java.util.concurrent.FutureTask.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)


#9

Also I am not able to download the certificate ,getting 406 error


#10

Client certificates is not working properly yet with official openfire server. I have not finished testing it and it may require more changes to openfire server code before it works properly.


#11

Hi Everyone,

I want to send message into group.

For that feature i took code from https://github.com/deleolajide/ofmeet-openfire-plugin and build chatapi.jar.

Upload chatapi.jar into plugins.

Now i call api with below URL:-
http://server:9090/plugins/restapi/v1/chat/messages/87d8c986-609a-4358-a01c-753a94f3800e?servicename=test using RestClient but api respond me 404 (Not Found) error.

I am not able to figure out what i am missing in request.

Please help me.


#12

chatapi uses http-bind port 7070/7443 and not admin port 9090/9091


#13

Ok.

I changed my port from 9090 to 7070 now it works.

Thanks @Dele_Olajide


#14

@Dele_Olajide

Is there any way to send custom message like i want to send some extra field while sending message using http://ps-win-lp-166.thepsi.com:7070/rest/api/restapi/v1/chat/streamid/rooms/room1 api.

I need to send some extra parameter with message using chat api.

Please help me this.


#15

At the moment, no. However it is good idea and I will add that feature :slight_smile:


#16

@Dele_Olajide

I am building ofchat.jar from https://github.com/deleolajide/ofmeet-openfire-plugin Github.

Can you please add provision to add custom tag/element in message into your git directory.

Thanks in advance.


#17

The ofchat project has moved to https://github.com/igniterealtime/openfire-chat


#18

Thanks @Dele_Olajide

I sent message successfully using ofchat api but when i restart openfire server then i try to join same room which gives 500 error on same chat room which i sent earlier.

following steps i perform:-

  1. create chat room as room1.
  2. login to get streamid. (200 OK)
  3. join room1. (200 OK)
  4. send message to room1. (200 OK)

This send message successfully to room1.

now i restart my openfire server.
do same steps.

  1. login to get steamid (200 OK).
  2. join room1 (500 INTERNAL SERVER ERROR).

API
curl -X PUT --header ‘Authorization: 89wjjp0HBCDUAN9z’ ‘http://ps-win-lp-166.thepsi.com:7070/rest/api/restapi/v1/chat/ofchat-557815489/rooms/e2be381a-4f27-407a-9257-84f1c3bf0ac3?service=xxx

Response
Aug 23, 2018 3:10:10 PM com.sun.jersey.spi.container.ContainerResponse logException
SEVERE: Mapped exception to response: 500 (Internal Server Error)
javax.ws.rs.WebApplicationException: com.sun.jersey.api.MessageException: A message body writer for Java class org.jivesoftware.openfire.plugin.rest.exceptions.ErrorResponse, and Java type class org.jivesoftware.openfire.plugin.rest.exceptions.ErrorResponse, and MIME media type / was not found.

at com.sun.jersey.spi.container.ContainerResponse.write(ContainerResponse.java:284)
at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1510)
at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1419)
at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1409)
at com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:409)
at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:558)
at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:733)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:812)
at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:587)
at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:221)
at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1127)
at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:515)
at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:185)
at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1061)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141)
at org.eclipse.jetty.server.handler.HandlerCollection.handle(HandlerCollection.java:110)
at org.eclipse.jetty.server.handler.HandlerList.handle(HandlerList.java:52)
at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:97)
at org.eclipse.jetty.server.Server.handle(Server.java:499)
at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:311)
at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:257)
at org.eclipse.jetty.io.AbstractConnection$2.run(AbstractConnection.java:544)
at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:635)
at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:555)
at java.lang.Thread.run(Unknown Source)

Caused by: com.sun.jersey.api.MessageException: A message body writer for Java class org.jivesoftware.openfire.plugin.rest.exceptions.ErrorResponse, and Java type class org.jivesoftware.openfire.plugin.rest.exceptions.ErrorResponse, and MIME media type / was not found.

@Dele_Olajide can you please help me on this issue.


#19

Hi @Dele_Olajide

I took checkout from https://github.com/igniterealtime/openfire-chat and build project using mvn clean package. it build ofchat.jar into target folder. i upload ofchat.jar into plugins.

Now now swagger is not working it show The webpage at https://xxx.com:7443/swagger might be temporarily down or it may have moved permanently to a new web address

Please help me out.


#20

It is uses XMPPServer.getInstance().getServerInfo().getHostname()

make sure hostname is configured and pointing at your xmpp server.

<body>
<iframe frameborder='0' style='border:0px; border-width:0px; margin-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; width:100%;height:100%;' src='<%=  "https://" + JiveGlobals.getProperty("network.interface", XMPPServer.getInstance().getServerInfo().getHostname()) + ":" + JiveGlobals.getProperty("httpbind.port.secure", "7443") + "/swagger" %>'></iframe>
</body>