svn commit: r1537 - subproject/bayeux/src/main/java/org/jboss/netty/example/bayeux.
"이희승 (Trustin Lee)"
trustin at gmail.com
Wed Jul 8 10:35:33 EDT 2009
Danny,
Could you write the summary of what you've done for each commit when you
commit? The Log field is empty.
On 07/08/2009 11:31 PM, netty-commits at lists.jboss.org wrote:
> Author: guiwuu
> Date: 2009-07-08 10:31:48 -0400 (Wed, 08 Jul 2009)
> New Revision: 1537
>
> Modified:
> subproject/bayeux/src/main/java/org/jboss/netty/example/bayeux/BayeuxHandler.java
> Log:
<<<HERE>>>
> Modified: subproject/bayeux/src/main/java/org/jboss/netty/example/bayeux/BayeuxHandler.java
> ===================================================================
> --- subproject/bayeux/src/main/java/org/jboss/netty/example/bayeux/BayeuxHandler.java 2009-07-08 13:36:54 UTC (rev 1536)
> +++ subproject/bayeux/src/main/java/org/jboss/netty/example/bayeux/BayeuxHandler.java 2009-07-08 14:31:48 UTC (rev 1537)
> @@ -25,10 +25,13 @@
> import java.io.BufferedReader;
> import java.io.File;
> import java.io.FileReader;
> +import java.util.Arrays;
> import java.util.List;
> import java.util.Map;
> import java.util.Map.Entry;
> +import java.util.Random;
> import java.util.Set;
> +import java.util.UUID;
> import org.jboss.netty.buffer.ChannelBuffer;
> import org.jboss.netty.buffer.ChannelBuffers;
> import org.jboss.netty.channel.ChannelFuture;
> @@ -39,7 +42,11 @@
> import org.jboss.netty.channel.MessageEvent;
> import org.jboss.netty.channel.SimpleChannelUpstreamHandler;
> import org.jboss.netty.handler.codec.bayeux.BayeuxMessage;
> +import org.jboss.netty.handler.codec.bayeux.ConnectRequest;
> +import org.jboss.netty.handler.codec.bayeux.ConnectResponse;
> import org.jboss.netty.handler.codec.bayeux.HandshakeRequest;
> +import org.jboss.netty.handler.codec.bayeux.HandshakeResponse;
> +import org.jboss.netty.handler.codec.bayeux.JSONParser;
> import org.jboss.netty.handler.codec.http.Cookie;
> import org.jboss.netty.handler.codec.http.CookieDecoder;
> import org.jboss.netty.handler.codec.http.CookieEncoder;
> @@ -67,27 +74,66 @@
> private static final InternalLogger logger =
> InternalLoggerFactory.getInstance(BayeuxHandler.class.getName());
> private String root;
> - private String cometUri;
>
> public BayeuxHandler() {
> }
>
> - public BayeuxHandler(String root, String cometUri) {
> + public BayeuxHandler(String root) {
> this.root = root;
> - this.cometUri = cometUri;
> }
>
> @Override
> public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception {
> - if(e.getMessage() instanceof BayeuxMessage){
> - BayeuxMessage bayeux=(BayeuxMessage)e.getMessage();
> - if(bayeux instanceof HandshakeRequest){
> - HandshakeRequest handshakeRequest=(HandshakeRequest)bayeux;
> - logger.info(handshakeRequest.toJSON());
> + if (e.getMessage() instanceof BayeuxMessage) {
> + BayeuxMessage bayeux = (BayeuxMessage) e.getMessage();
> + BayeuxMessage response = null;
> + if (bayeux instanceof HandshakeRequest) {
> + HandshakeRequest handshakeRequest = (HandshakeRequest) bayeux;
> + logger.info("Hankshake Request: "+handshakeRequest.toJSON());
> + String[] supportedConnectionTypes = handshakeRequest.getSupportedConnectionTypes();
> + List list = Arrays.asList(supportedConnectionTypes);
> +
> + String version = handshakeRequest.getVersion();
> + String minimumVersion = handshakeRequest.getMinimumVersion();
> + boolean successful = true;
> + String error = null;
> + String responseVersion = shakeVersion(version, minimumVersion);
> + if (!list.contains("long-polling")) {
> + successful = false;
> + error = "401:" + JSONParser.toJSON(supportedConnectionTypes) + ":Unsupported Connection Types";
> + } else if (responseVersion == null || responseVersion.length() == 0) {
> + successful = false;
> + error = "402:version:Unsupported Version";
> + }
> + HandshakeResponse handshakeResponse = new HandshakeResponse(handshakeRequest);
> + handshakeResponse.setSuccessful(successful);
> + if (successful) {
> + handshakeResponse.setVersion(responseVersion);
> + String[] responseSupportedConnectionTypes = {"long-polling"};
> + handshakeResponse.setSupportedConnectionTypes(responseSupportedConnectionTypes);
> + byte[] bf=new byte[16];
> + new Random().nextBytes(bf);
> + handshakeResponse.setClientId(new String(bf));
> +
> + } else {
> + handshakeResponse.setError(error);
> + }
> + logger.info("Hankshake Response: "+handshakeResponse.toJSON());
> + response = handshakeResponse;
> + // Write the response.
> +
> +
> + } else if (bayeux instanceof ConnectRequest) {
> + ConnectRequest connectRequest = (ConnectRequest) bayeux;
> + logger.info("Connect Request: "+connectRequest.toJSON());
> + ConnectResponse connectResponse = new ConnectResponse(connectRequest);
> + logger.info("Connect Response: "+connectResponse.toJSON());
> + response = connectResponse;
> }
> + ChannelFuture future = e.getChannel().write(response);
>
> - }else if (!readingChunks&& e.getMessage() instanceof HttpRequest) {
> - HttpRequest request = this.request = (HttpRequest) e.getMessage();
> + } else if (!readingChunks && e.getMessage() instanceof HttpRequest) {
> + request = (HttpRequest) e.getMessage();
>
> File file = new File(root + File.separator + request.getUri());
> if (file.exists() && file.isFile()) {
> @@ -206,4 +252,12 @@
> e.getCause().printStackTrace();
> e.getChannel().close();
> }
> +
> + private String shakeVersion(String version, String minimumVersion) {
> + String internalVersion = "1.0beta";
> + String internalMinimumVersion = internalVersion;
> + String result = null;
> + result = internalVersion;
> + return "1.0";
> + }
> }
>
> _______________________________________________
> netty-commits mailing list
> netty-commits at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/netty-commits
More information about the netty-dev
mailing list