Package org.jivesoftware.smack.packet

Examples of org.jivesoftware.smack.packet.Registration


     * Gets the account registration info from the server.
     *
     * @throws XMPPException if an error occurs.
     */
    private synchronized void getRegistrationInfo() throws XMPPException {
        Registration reg = new Registration();
        reg.setTo(connection.getServiceName());
        PacketFilter filter = new AndFilter(new PacketIDFilter(reg.getPacketID()),
                new PacketTypeFilter(IQ.class));
        PacketCollector collector = connection.createPacketCollector(filter);
        connection.sendPacket(reg);
        IQ result = (IQ)collector.nextResult(SmackConfiguration.getPacketReplyTimeout());
        // Stop queuing results
View Full Code Here


     *
     * http://xmpp.org/extensions/xep-0077.html
     */
    public static synchronized Registration getRegistrationInfo(
        String toRegister, Connection connection) throws XMPPException {
        Registration reg = new Registration();
        reg.setTo(connection.getServiceName());
        reg.setFrom(toRegister);
        PacketFilter filter = new AndFilter(new PacketIDFilter(
            reg.getPacketID()), new PacketTypeFilter(IQ.class));
        PacketCollector collector = connection.createPacketCollector(filter);
        connection.sendPacket(reg);
        IQ result = (IQ) collector.nextResult(SmackConfiguration
            .getPacketReplyTimeout());

View Full Code Here

     */
    public static String isAccountCreationPossible(Connection connection,
        String username) {
        String errorMessage = null;

        Registration registration = null;
        try {
            registration = XMPPUtil.getRegistrationInfo(username, connection);
        } catch (XMPPException e) {
            log.error("Server " + connection.getHost()
                + " does not support XEP-0077"
                + " (In-Band Registration) properly:", e);
        }
        if (registration != null && registration.getError() != null) {
            if (registration.getAttributes().containsKey("registered")) {
                errorMessage = "Account " + username
                    + " already exists on the server.";
            } else if (!registration.getAttributes().containsKey("username")) {
                if (registration.getInstructions() != null) {
                    errorMessage = "Registration via Saros not possible.\n\n"
                        + "Please follow these instructions:\n"
                        + registration.getInstructions();
                } else {
                    errorMessage = "Registration via Saros not possible.\n\n"
                        + "Please see the server's web site for\n"
                        + "informations for how to create an account.";
                }
            } else {
                errorMessage = "No in-band registration. Please create account on provider's website.";
                log.warn("Unknow registration error: "
                    + registration.getError().getMessage());
            }
        }

        return errorMessage;
    }
View Full Code Here

            monitor.worked(1);

            connection.connect();
            monitor.worked(1);

            Registration registration = null;
            try {
                registration = XMPPUtil.getRegistrationInfo(username,
                    connection);
            } catch (XMPPException e) {
                LOG.error("Server " + server + " does not support XEP-0077"
                    + " (In-Band Registration) properly:", e);
            }
            if (registration != null) {
                if (registration.getAttributes().containsKey("registered")) {
                    throw new XMPPException("Account " + username
                        + " already exists on server");
                }
                if (!registration.getAttributes().containsKey("username")) {
                    String instructions = registration.getInstructions();
                    if (instructions != null) {
                        throw new XMPPException(
                            "Registration via Saros not possible. Please follow these instructions:\n"
                                + instructions);
                    } else {
View Full Code Here

            throws XMPPException
    {
        if (!supportsAccountCreation()) {
            throw new XMPPException("Server does not support account creation.");
        }
        Registration reg = new Registration();
        reg.setType(IQ.Type.SET);
        reg.setTo(connection.getServiceName());
        attributes.put("username",username);
        attributes.put("password",password);
        reg.setAttributes(attributes);
        PacketFilter filter = new AndFilter(new PacketIDFilter(reg.getPacketID()),
                new PacketTypeFilter(IQ.class));
        PacketCollector collector = connection.createPacketCollector(filter);
        connection.sendPacket(reg);
        IQ result = (IQ)collector.nextResult(SmackConfiguration.getPacketReplyTimeout());
        // Stop queuing results
View Full Code Here

     *
     * @throws IllegalStateException if not currently logged-in to the server.
     * @throws XMPPException if an error occurs when changing the password.
     */
    public void changePassword(String newPassword) throws XMPPException {
        Registration reg = new Registration();
        reg.setType(IQ.Type.SET);
        reg.setTo(connection.getServiceName());
        Map<String, String> map = new HashMap<String, String>();
        map.put("username",StringUtils.parseName(connection.getUser()));
        map.put("password",newPassword);
        reg.setAttributes(map);
        PacketFilter filter = new AndFilter(new PacketIDFilter(reg.getPacketID()),
                new PacketTypeFilter(IQ.class));
        PacketCollector collector = connection.createPacketCollector(filter);
        connection.sendPacket(reg);
        IQ result = (IQ)collector.nextResult(SmackConfiguration.getPacketReplyTimeout());
        // Stop queuing results
View Full Code Here

     */
    public void deleteAccount() throws XMPPException {
        if (!connection.isAuthenticated()) {
            throw new IllegalStateException("Must be logged in to delete a account.");
        }
        Registration reg = new Registration();
        reg.setType(IQ.Type.SET);
        reg.setTo(connection.getServiceName());
        Map<String, String> attributes = new HashMap<String, String>();
        // To delete an account, we add a single attribute, "remove", that is blank.
        attributes.put("remove", "");
        reg.setAttributes(attributes);
        PacketFilter filter = new AndFilter(new PacketIDFilter(reg.getPacketID()),
                new PacketTypeFilter(IQ.class));
        PacketCollector collector = connection.createPacketCollector(filter);
        connection.sendPacket(reg);
        IQ result = (IQ)collector.nextResult(SmackConfiguration.getPacketReplyTimeout());
        // Stop queuing results
View Full Code Here

     * Gets the account registration info from the server.
     *
     * @throws XMPPException if an error occurs.
     */
    private synchronized void getRegistrationInfo() throws XMPPException {
        Registration reg = new Registration();
        reg.setTo(connection.getServiceName());
        PacketFilter filter = new AndFilter(new PacketIDFilter(reg.getPacketID()),
                new PacketTypeFilter(IQ.class));
        PacketCollector collector = connection.createPacketCollector(filter);
        connection.sendPacket(reg);
        IQ result = (IQ)collector.nextResult(SmackConfiguration.getPacketReplyTimeout());
        // Stop queuing results
View Full Code Here

            throws XMPPException
    {
        if (!supportsAccountCreation()) {
            throw new XMPPException("Server does not support account creation.");
        }
        Registration reg = new Registration();
        reg.setType(IQ.Type.SET);
        reg.setTo(connection.getServiceName());
        attributes.put("username",username);
        attributes.put("password",password);
        reg.setAttributes(attributes);
        PacketFilter filter = new AndFilter(new PacketIDFilter(reg.getPacketID()),
                new PacketTypeFilter(IQ.class));
        PacketCollector collector = connection.createPacketCollector(filter);
        connection.sendPacket(reg);
        IQ result = (IQ)collector.nextResult(SmackConfiguration.getPacketReplyTimeout());
        // Stop queuing results
View Full Code Here

     *
     * @throws IllegalStateException if not currently logged-in to the server.
     * @throws XMPPException if an error occurs when changing the password.
     */
    public void changePassword(String newPassword) throws XMPPException {
        Registration reg = new Registration();
        reg.setType(IQ.Type.SET);
        reg.setTo(connection.getServiceName());
        Map<String, String> map = new HashMap<String, String>();
        map.put("username",StringUtils.parseName(connection.getUser()));
        map.put("password",newPassword);
        reg.setAttributes(map);
        PacketFilter filter = new AndFilter(new PacketIDFilter(reg.getPacketID()),
                new PacketTypeFilter(IQ.class));
        PacketCollector collector = connection.createPacketCollector(filter);
        connection.sendPacket(reg);
        IQ result = (IQ)collector.nextResult(SmackConfiguration.getPacketReplyTimeout());
        // Stop queuing results
View Full Code Here

TOP

Related Classes of org.jivesoftware.smack.packet.Registration

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.