Commits

Andy Moncsek committed a2f0dec

update TwitterWebSocket project

Comments (0)

Files changed (9)

Domain/src/main/java/org/jacp/jee/entity/Query.java

 
 package org.jacp.jee.entity;
 
+import java.io.Serializable;
+
 /**
  * Created with IntelliJ IDEA.
  * User: ady
  * Time: 13:57
  * To change this template use File | Settings | File Templates.
  */
-public class Query {
+public class Query implements Serializable{
     private final String query;
 
     public Query(final String query){

JacpFXTwitterWebsocketClient/pom.xml

 
                                 <!-- create executeables use: nativeBundles="all" to create native executeables-->
                                 <fx:deploy width="${applet.width}" height="${applet.height}"
-                                           outdir="${project.build.directory}/deploy" embedJNLP="true"
+                                           outdir="${project.build.directory}/deploy" embedJNLP="flase"
                                            outfile="${application.title}">
 
                                     <fx:application refId="${project.name}"/>

JacpFXTwitterWebsocketClient/src/main/java/org/jacp/twitter/callbacks/TwitterEndpointComponent.java

 import org.jacp.javafx.rcp.component.AStatefulCallbackComponent;
 import org.jacp.jee.entity.Query;
 import org.jacp.jee.entity.TwitterResult;
+import org.jacp.twitter.decoder.TwitterResultDecoder;
+import org.jacp.twitter.encoder.QueryEncoder;
 
 
 import javax.websocket.*;
  *
  * @author <a href="mailto:amo.ahcp@gmail.com"> Andy Moncsek</a>
  */
-@ClientEndpoint
+@ClientEndpoint(decoders = {TwitterResultDecoder.class}, encoders = {QueryEncoder.class})
 @CallbackComponent(id = "id003", name = "twitterEndpointComponent", active = false)
 public class TwitterEndpointComponent extends AStatefulCallbackComponent {
     private Session session;
     public void cleanup() {
         this.log.info("WebSocketEndpoint stop");
         try {
-            if(session!=null)session.close();
+            if(session!=null)
+                session.close();
         } catch (IOException e) {
             e.printStackTrace();
         }
      * WebSocket lifecycle
      */
     public void onTwitterMessage(TwitterResult result) {
-        this.getActionListener("id001", result);
+        this.getActionListener("id001", result).performAction(null);
     }
 
     private void sendQuery(Query query) throws IOException, EncodeException {

JacpFXTwitterWebsocketClient/src/main/java/org/jacp/twitter/components/QueryView.java

 import org.jacp.javafx.rcp.componentLayout.FXComponentLayout;
 import org.jacp.javafx.rcp.util.FXUtil.MessageUtil;
 import org.jacp.jee.entity.Query;
-import org.jacp.twitter.entities.Clear;
+
 
 import java.net.URI;
 import java.net.URISyntaxException;

JacpFXTwitterWebsocketClient/src/main/java/org/jacp/twitter/components/TweetView.java

 import org.jacp.javafx.rcp.util.FXUtil.MessageUtil;
 import org.jacp.jee.entity.Tweet;
 import org.jacp.jee.entity.TwitterResult;
-import org.jacp.twitter.entities.Clear;
+
 
 import java.util.Arrays;
 import java.util.Collections;
         if (action.getLastMessage().equals(MessageUtil.INIT)) {
             this.pane = (AnchorPane) arg0;
         } else if (action.getLastMessage() instanceof TwitterResult) {
+            tweets.clear();
             TwitterResult result = (TwitterResult) action.getLastMessage();
             if (!result.getResults().isEmpty()) {
                 tweets.addAll(result.getResults());
                 Collections.sort(tweets);
             }
-        } else if(action.getLastMessage() instanceof Clear){
-            tweets.clear();
         }
         return this.pane;
     }

JacpFXTwitterWebsocketClient/src/main/java/org/jacp/twitter/decoder/TwitterResultDecoder.java

+/*
+ * Copyright (c) 2013, Andy Moncsek, inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification, are permitted provided
+ * that the following conditions are met:
+ *
+ *    Redistributions of source code must retain the above copyright notice, this list of conditions and the
+ *    following disclaimer.
+ *
+ *    Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
+ *    the following disclaimer in the documentation and/or other materials provided with the distribution.
+ *
+ *    Neither the name of Andy Moncsek, inc. nor the names of its contributors may be used to endorse or
+ *    promote products derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+ * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
+ * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+package org.jacp.twitter.decoder;
+
+import org.apache.commons.lang.SerializationUtils;
+import org.jacp.jee.entity.TwitterResult;
+
+import javax.websocket.DecodeException;
+import javax.websocket.Decoder;
+import javax.websocket.EndpointConfig;
+import java.nio.ByteBuffer;
+
+/**
+ * Created with IntelliJ IDEA.
+ * User: ady
+ * Date: 21.04.13
+ * Time: 18:45
+ * To change this template use File | Settings | File Templates.
+ */
+public class TwitterResultDecoder implements Decoder.Binary<TwitterResult> {
+    @Override
+    public TwitterResult decode(ByteBuffer TwitterResult) throws DecodeException {
+        return (TwitterResult) SerializationUtils.deserialize(TwitterResult.array());
+    }
+
+    @Override
+    public boolean willDecode(ByteBuffer bytes) {
+        Object message = SerializationUtils.deserialize(bytes.array());
+        if (message == null) return false;
+        return message instanceof TwitterResult;
+    }
+
+    @Override
+    public void init(EndpointConfig config) {
+        //To change body of implemented methods use File | Settings | File Templates.
+    }
+
+    @Override
+    public void destroy() {
+        //To change body of implemented methods use File | Settings | File Templates.
+    }
+}

JacpFXTwitterWebsocketClient/src/main/java/org/jacp/twitter/encoder/QueryEncoder.java

+/*
+ * Copyright (c) 2013, Andy Moncsek, inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification, are permitted provided
+ * that the following conditions are met:
+ *
+ *    Redistributions of source code must retain the above copyright notice, this list of conditions and the
+ *    following disclaimer.
+ *
+ *    Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
+ *    the following disclaimer in the documentation and/or other materials provided with the distribution.
+ *
+ *    Neither the name of Andy Moncsek, inc. nor the names of its contributors may be used to endorse or
+ *    promote products derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+ * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
+ * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+package org.jacp.twitter.encoder;
+
+import org.apache.commons.lang.SerializationUtils;
+import org.jacp.jee.entity.Query;
+
+import javax.websocket.EncodeException;
+import javax.websocket.Encoder;
+import javax.websocket.EndpointConfig;
+import java.nio.ByteBuffer;
+
+/**
+ * Created with IntelliJ IDEA.
+ * User: ady
+ * Date: 21.04.13
+ * Time: 18:53
+ * To change this template use File | Settings | File Templates.
+ */
+public class QueryEncoder implements Encoder.Binary<Query> {
+    @Override
+    public ByteBuffer encode(Query object) throws EncodeException {
+        return ByteBuffer.wrap(SerializationUtils.serialize(object));
+    }
+
+    @Override
+    public void init(EndpointConfig config) {
+        //To change body of implemented methods use File | Settings | File Templates.
+    }
+
+    @Override
+    public void destroy() {
+        //To change body of implemented methods use File | Settings | File Templates.
+    }
+}

WebClient-TwitterWebsocket/pom.xml

             <version>${project.version}</version>
             <scope>provided</scope>
         </dependency>
+        <dependency>
+            <groupId>com.google.code.gson</groupId>
+            <artifactId>gson</artifactId>
+            <version>${gson.version}</version>
+        </dependency>
     </dependencies>
 </project>
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
-         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
     <modelVersion>4.0.0</modelVersion>
     <groupId>org.jacp.jee</groupId>
     <artifactId>JEE7-websocket</artifactId>
         <module>JacpFXWebsocketChatClient</module>
 		<module>JacpFXSSETwitterClient</module>
 		<module>JacpFXTwitterWebsocketClient</module>
-    </modules>
+  </modules>
     <properties>
         <javax.persistence.version>2.0.0</javax.persistence.version>
         <jee.version>7.0-b83</jee.version>
             </plugins>
         </pluginManagement>
     </build>
-</project>
-
+</project>