0

im following this documentation to achieve gcm upstream message.

so far,i've created a servlet,and from that servlet im calling the SmackCcsClient.

    ConnectionConfiguration config =
            new ConnectionConfiguration(GCM_SERVER, GCM_PORT);
    config.setSecurityMode(SecurityMode.enabled);
    config.setReconnectionAllowed(true);
    config.setRosterLoadedAtLogin(false);
    config.setSendPresence(false);
    config.setSocketFactory(SSLSocketFactory.getDefault());

    connection = new XMPPTCPConnection(config);
    connection.connect();

    connection.addConnectionListener(new LoggingConnectionListener());

    // Handle incoming packets
    connection.addPacketListener(new PacketListener() {

        @Override
        public void processPacket(Packet packet) {
            logger.log(Level.INFO, "Received: " + packet.toXML());
            Message incomingMessage = (Message) packet;
            GcmPacketExtension gcmPacket =
                    (GcmPacketExtension) incomingMessage.
                    getExtension(GCM_NAMESPACE);
            String json = gcmPacket.getJson();
            try {
                @SuppressWarnings("unchecked")
                Map<String, Object> jsonObject =
                        (Map<String, Object>) JSONValue.
                        parseWithException(json);

                // present for "ack"/"nack", null otherwise
                Object messageType = jsonObject.get("message_type");

                if (messageType == null) {
                    // Normal upstream data message
                    handleUpstreamMessage(jsonObject);

                    // Send ACK to CCS
                    String messageId = (String) jsonObject.get("message_id");
                    String from = (String) jsonObject.get("from");
                    String ack = createJsonAck(from, messageId);
                    send(ack);
                } else if ("ack".equals(messageType.toString())) {
                      // Process Ack
                      handleAckReceipt(jsonObject);
                } else if ("nack".equals(messageType.toString())) {
                      // Process Nack
                      handleNackReceipt(jsonObject);
                } else if ("control".equals(messageType.toString())) {
                      // Process control message
                      handleControlMessage(jsonObject);
                } else {
                      logger.log(Level.WARNING,
                              "Unrecognized message type (%s)",
                              messageType.toString());
                }
            } catch (ParseException e) {
                logger.log(Level.SEVERE, "Error parsing JSON " + json, e);
            } catch (Exception e) {
                logger.log(Level.SEVERE, "Failed to process packet", e);
            }
        }
    }, new PacketTypeFilter(Message.class));

    // Log all outgoing packets
    connection.addPacketInterceptor(new PacketInterceptor() {
        @Override
            public void interceptPacket(Packet packet) {
                logger.log(Level.INFO, "Sent: {0}", packet.toXML());
            }
        }, new PacketTypeFilter(Message.class));

    connection.login(senderId + "@gcm.googleapis.com", apiKey);

its compiling and i dont get any errors as i have included the smack 4.0.7 library.but while executing,im always getting the following error: java.lang.ClassNotFoundException: org.jivesoftware.smack.XMPPConnection

the jar has been added in the build path.

Shofiqul Alam
  • 585
  • 1
  • 7
  • 29

1 Answers1

2

The smack.jar contains the class. download and add it to your classpath.

Jens
  • 67,715
  • 15
  • 98
  • 113
  • as i said,the jar has been added in the build path already,and its not giving error while compiling. its throwing the exception in runtime. – Shofiqul Alam Mar 10 '15 at 14:31
  • Have you add it to your classpath? At runtime the buildpath is not available! – Jens Mar 10 '15 at 14:33
  • ok,in java resources folder,there is a libraries folder and i have added the smack.jar in that folder. how do i add it to classpath also? – Shofiqul Alam Mar 10 '15 at 14:39
  • How do you build your application? Where do you run it (Eclipse, Tomcat,...)? – Jens Mar 10 '15 at 14:40
  • tomcat and eclipse. im running the tomcat server from eclipse. – Shofiqul Alam Mar 10 '15 at 14:44
  • try to add it in the launcher in "classpath" tab. – Jens Mar 10 '15 at 14:46
  • where it is?i dont find any classpath tab. – Shofiqul Alam Mar 10 '15 at 14:50
  • ok after adding the jars in classpath,i get java.lang.UnsupportedClassVersionError: org/jivesoftware/smack/tcp/XMPPTCPConnection : Unsupported major.minor version 51.0 – Shofiqul Alam Mar 10 '15 at 14:53
  • see [here](http://stackoverflow.com/questions/10382929/unsupported-major-minor-version-51-0) – Jens Mar 10 '15 at 14:54
  • after upgrading jre to 8,now im getting this error. java.lang.IncompatibleClassChangeError: Expected static method org.jivesoftware.smack.provider.ProviderManager.addExtensionProvider(Ljava/lang/String;Ljava/lang/String;Ljava/lang/Object;)V com.shofiq.libs.SmackCcsClient.(SmackCcsClient.java:53) gosh,why this library is this much complicated! – Shofiqul Alam Mar 11 '15 at 08:45