Gateway registration help?

Hi,

I want to write a simple jsp page through which i can add new registration at “Gateway Registration” in my openfire server. My openfire server is running at 213.152.241.XXX and i have a registered user guest and domain name is iwape2004.

The page will have 5 text boxex and there i will put my openfire user name, gmail id , password, nick name and then i will press a button and this will add a new gateway registration agains user guest.

Can anybody please help me with a example / sample?

Regards,

Samba

I think you want to extend Openfire for your use case, so please move your thread to the “Openfire Dev” track.

I am now now able to do Openfire Gateway registration using smack and below is the code.

<%@ page import=“com.requestec.mds.parsers." %>
<%@ page import="com.requestec.mds.managers.
” %>
<%@ page import=“com.requestec.smg.servlets." %>
<%@ page import="java.util.
” %>
<%@ page import=“java.net." %>
<%@ page import="java.io.
” %>
<%@ page import=“java.io." %>
<%@ page import=“org.jivesoftware.smack.XMPPConnection” %>
<%@ page import="org.jivesoftware.smack.packet.
” %>
<%@ page import=“org.jivesoftware.smack.filter.PacketIDFilter” %>
<%@ page import=“org.jivesoftware.smack.*” %>

<%!
public static void register(XMPPConnection conn, String gateway, String username, String password, String nickname) throws XMPPException
{ if(username == null || username.length() == 0 ||
password == null || password.length() == 0 ||
nickname == null || nickname.length() == 0 ||
gateway == null || gateway.length() == 0)
throw new XMPPException(“Incorrect paramaters”);

 Registration registration = new Registration();
 registration.setType(IQ.Type.SET);
 registration.setTo(gateway);
 registration.addExtension(new GatewayRegisterExtension());

 Map attributes = new HashMap();
 if (username != null) attributes.put("username", username);
 if (password != null) attributes.put("password", password);
 if (nickname != null) attributes.put("nick", nickname);
 registration.setAttributes(attributes);             

 PacketCollector collector = conn.createPacketCollector(new PacketIDFilter(registration.getPacketID()));
 conn.sendPacket(registration);

 IQ response = (IQ) collector.nextResult(SmackConfiguration.getPacketReplyTimeout());
 collector.cancel();
 if(response == null) throw new XMPPException("Server timed out");
 if(response.getType() == IQ.Type.ERROR)
     {
     System.out.println(response.getXmlns());
     System.out.println(response.getChildElementXML());
     throw new XMPPException("Error registering user", response.getError());
     }

 System.out.println(response.getChildElementXML());         

 if(!conn.getRoster().contains(gateway))
      conn.getRoster().createEntry(gateway, gateway, null);

 Presence subscribe = new Presence(Presence.Type.subscribe);
 subscribe.setTo(gateway);
 conn.sendPacket(subscribe);                                                             

}

static class GatewayRegisterExtension implements PacketExtension
{
public String getElementName()
{
return “x”;
}

 public String getNamespace()
 {
      return "jabber:iq:gateway:register";
 }

 public String toXML()
 {
      StringBuilder builder = new StringBuilder();
      builder.append("<").append(getElementName()).append(" xmlns=\"").append(getNamespace()).append("\"/>");
      return builder.toString();
 }

}
%>

<%

try{
String xmppUserName = request.getParameter(“xmppUserName”);
String xmppUserPassword = request.getParameter(“xmppUserPassword”);

    String gatewayCombo    = request.getParameter("gatewayCombo");
    String userName           = request.getParameter("userName");
    String userPassword     = request.getParameter("userPassword");
    String nickName           = request.getParameter("nickName");
   
   
    XMPPConnection connection = new XMPPConnection("XXX.YYY.XXX.YYY");
    connection.connect();
    connection.login(xmppUserName, xmppUserPassword);

    register(connection,gatewayCombo,userName,userPassword,nickName);

    connection.disconnect();

}
catch(Exception e)
{
out.println(e);
}
%>

Please replace the server IP and pass the following information to this page from your client properly.

Yes now i can use smack to do gateway registration to Openfire.

Able to add different transports.

Sorry, I tought you want a Openfire plugin which allows trough the build-in jetty application server the gateway registration. But with Smack and an external application server you should be independent of the choice of the XMPP server.

**HI **

Am using the same logic ,but where i got struct with these exception

help is appreciated.

idhasoftemailtest@gmail.comidhasoftemailtest@gmail.comidhas0ftemailtest

Error registering user: remote-server-not-found(404)

at registration.RegistrationManager.register(RegistrationManager.java:49)

at servlets.servlet.doPost(servlet.java:191)

at servlets.servlet.doGet(servlet.java:75)

at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)

at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)

at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFil terChain.java:290)

at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain .java:206)

at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java: 233)

at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java: 191)

at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)

at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)

at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:10 9)

at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)

at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:859)

at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11P rotocol.java:588)

at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)

at java.lang.Thread.run(Unknown Source)

isAuthenticated()—false

stream:error (conflict)

at org.jivesoftware.smack.PacketReader.parsePackets(PacketReader.java:260)

at org.jivesoftware.smack.PacketReader.access$1(PacketReader.java:220)

at org.jivesoftware.smack.PacketReader$1.run(PacketReader.java:70)

Hello

I need to do gateway registration to Openfire+smack.

i am getting

Error registering user: remote-server-not-found(404)

**can you plz post the code **

MyCODE

package registration;

import java.util.HashMap;

import java.util.Map;

import org.jivesoftware.smack.PacketCollector;

import org.jivesoftware.smack.SmackConfiguration;

import org.jivesoftware.smack.XMPPConnection;

import org.jivesoftware.smack.XMPPException;

import org.jivesoftware.smack.filter.PacketIDFilter;

import org.jivesoftware.smack.packet.IQ;

import org.jivesoftware.smack.packet.PacketExtension;

import org.jivesoftware.smack.packet.Presence;

import org.jivesoftware.smack.packet.Registration;

public class RegistrationManager {

public static void register(XMPPConnection conn, String gateway, String username, String password, String nickname) throws XMPPException

{

if(username == null || username.length() == 0 ||

password == null || password.length() == 0 ||

nickname == null || nickname.length() == 0 ||

gateway == null || gateway.length() == 0)

throw new XMPPException(“Incorrect paramaters”);

Registration registration = new Registration();

registration.setType(IQ.Type.SET);

registration.setTo(gateway);

registration.addExtension(new GatewayRegisterExtension());

Map attributes = new HashMap();

if (username != null) attributes.put(“username”, username);

if (password != null) attributes.put(“password”, password);

if (username != null) attributes.put(“email”, username);

// if (nickname != null) attributes.put(“nick”, nickname);

registration.setAttributes(attributes);

PacketCollector collector = conn.createPacketCollector(new PacketIDFilter(registration.getPacketID()));

conn.sendPacket(registration);

IQ response = (IQ) collector.nextResult(SmackConfiguration.getPacketReplyTimeout());

collector.cancel();

if(response == null){

System.out.println(response.getXmlns());

System.out.println(response.getChildElementXML());

throw new XMPPException(“Server timed out”);}

if(response.getType() == IQ.Type.ERROR)

{

System.out.println(response.getXmlns());

System.out.println(response.getChildElementXML());

throw new XMPPException(“Error registering user”, response.getError());

}

if(!conn.getRoster().contains(gateway))

conn.getRoster().createEntry(gateway, gateway, null);

Presence subscribe = new Presence(Presence.Type.subscribe);

subscribe.setTo(gateway);

subscribe.setFrom(conn.getUser());

conn.sendPacket(subscribe);

}

}


package registration;

import org.jivesoftware.smack.packet.PacketExtension;

class GatewayRegisterExtension implements PacketExtension

{

public String getElementName()

{

return “x”;

}

public String getNamespace()

{

return “jabber:iq:register”;

}

public String toXML()

{

StringBuilder builder = new StringBuilder();

builder.append("<").append(getElementName()).append(" xmlns="").append(getNamespace()).append(""/>");

System.out.println(“builder”+builder);

return builder.toString();

}

}

XML request

idhasoftemailtest@gmail.comidhasoftemailtest@gmail.comidhas0ftemailtest

XML response