Author: kkolinko Date: Thu Feb 16 10:58:21 2012 New Revision: 1244927 URL: http://svn.apache.org/viewvc?rev=1244927&view=rev Log: Set svn:eol-style=native on 5 files, as detected by validate-eoln target run on Gump
Modified: tomcat/trunk/modules/jdbc-pool/src/test/java/org/apache/tomcat/jdbc/bugs/Bug51582.java (contents, props changed) tomcat/trunk/modules/jdbc-pool/src/test/java/org/apache/tomcat/jdbc/pool/interceptor/InduceSlowQuery.java (contents, props changed) tomcat/trunk/test/org/apache/catalina/websocket/TestWebSocket.java (contents, props changed) tomcat/trunk/webapps/examples/WEB-INF/classes/websocket/EchoMessage.java (contents, props changed) tomcat/trunk/webapps/examples/WEB-INF/classes/websocket/EchoStream.java (contents, props changed) Modified: tomcat/trunk/modules/jdbc-pool/src/test/java/org/apache/tomcat/jdbc/bugs/Bug51582.java URL: http://svn.apache.org/viewvc/tomcat/trunk/modules/jdbc-pool/src/test/java/org/apache/tomcat/jdbc/bugs/Bug51582.java?rev=1244927&r1=1244926&r2=1244927&view=diff ============================================================================== --- tomcat/trunk/modules/jdbc-pool/src/test/java/org/apache/tomcat/jdbc/bugs/Bug51582.java (original) +++ tomcat/trunk/modules/jdbc-pool/src/test/java/org/apache/tomcat/jdbc/bugs/Bug51582.java Thu Feb 16 10:58:21 2012 @@ -1,136 +1,136 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.tomcat.jdbc.bugs; - -import java.sql.CallableStatement; -import java.sql.Connection; -import java.sql.SQLException; -import java.sql.Statement; -import java.util.ArrayList; -import java.util.List; - -import org.apache.tomcat.jdbc.pool.ConnectionPool; -import org.apache.tomcat.jdbc.pool.PoolConfiguration; -import org.apache.tomcat.jdbc.test.DefaultProperties; - - -public class Bug51582 -{ - - /** - * @param args - * @throws SQLException - */ - public static void main(String[] args) throws SQLException - { - org.apache.tomcat.jdbc.pool.DataSource datasource = null; - PoolConfiguration p = new DefaultProperties(); - - p.setJmxEnabled(true); - p.setTestOnBorrow(false); - p.setTestOnReturn(false); - p.setValidationInterval(1000); - p.setTimeBetweenEvictionRunsMillis(2000); - - p.setMaxWait(2000); - p.setMinEvictableIdleTimeMillis(1000); - - datasource = new org.apache.tomcat.jdbc.pool.DataSource(); - datasource.setPoolProperties(p); - datasource.setJdbcInterceptors("org.apache.tomcat.jdbc.pool.interceptor.SlowQueryReportJmx(threshold=200)"); - ConnectionPool pool = datasource.createPool(); - - - Connection con = pool.getConnection(); - Statement st = con.createStatement(); - try { - st.execute("DROP ALIAS SLEEP"); - }catch (Exception ignore) {} - st.execute("CREATE ALIAS SLEEP AS $$\nboolean sleep() {\n try {\n Thread.sleep(10000);\n return true; } catch (Exception x) {\n return false;\n }\n}\n$$;"); - st.close(); - con.close(); - int iter = 0; - while ((iter++) < 10) - { - final Connection connection = pool.getConnection(); - final CallableStatement s = connection.prepareCall("{CALL SLEEP()}"); - - List<Thread> threadList = new ArrayList<Thread>(); - - for (int l = 0; l < 3; l++) - { - final int i = l; - - Thread thread = new Thread() - { - @Override - public void run() - { - try - { - if (i == 0) - { - Thread.sleep(1000); - s.cancel(); - } - else if (i == 1) - { - //or use some other statement which will block for a longer time - long start = System.currentTimeMillis(); - System.out.println("["+getName()+"] Calling SP SLEEP"); - s.execute(); - System.out.println("["+getName()+"] Executed SP SLEEP ["+(System.currentTimeMillis()-start)+"]"); - } - else - { - Thread.sleep(1000); - connection.close(); - } - } - catch (InterruptedException e) - { - - } - catch (SQLException e) - { - e.printStackTrace(); - } - - }; - - }; - threadList.add(thread); - thread.start(); - } - for (Thread t : threadList) - { - try - { - t.join(); - } - catch (InterruptedException e) - { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } - - } - - - } -} +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.tomcat.jdbc.bugs; + +import java.sql.CallableStatement; +import java.sql.Connection; +import java.sql.SQLException; +import java.sql.Statement; +import java.util.ArrayList; +import java.util.List; + +import org.apache.tomcat.jdbc.pool.ConnectionPool; +import org.apache.tomcat.jdbc.pool.PoolConfiguration; +import org.apache.tomcat.jdbc.test.DefaultProperties; + + +public class Bug51582 +{ + + /** + * @param args + * @throws SQLException + */ + public static void main(String[] args) throws SQLException + { + org.apache.tomcat.jdbc.pool.DataSource datasource = null; + PoolConfiguration p = new DefaultProperties(); + + p.setJmxEnabled(true); + p.setTestOnBorrow(false); + p.setTestOnReturn(false); + p.setValidationInterval(1000); + p.setTimeBetweenEvictionRunsMillis(2000); + + p.setMaxWait(2000); + p.setMinEvictableIdleTimeMillis(1000); + + datasource = new org.apache.tomcat.jdbc.pool.DataSource(); + datasource.setPoolProperties(p); + datasource.setJdbcInterceptors("org.apache.tomcat.jdbc.pool.interceptor.SlowQueryReportJmx(threshold=200)"); + ConnectionPool pool = datasource.createPool(); + + + Connection con = pool.getConnection(); + Statement st = con.createStatement(); + try { + st.execute("DROP ALIAS SLEEP"); + }catch (Exception ignore) {} + st.execute("CREATE ALIAS SLEEP AS $$\nboolean sleep() {\n try {\n Thread.sleep(10000);\n return true; } catch (Exception x) {\n return false;\n }\n}\n$$;"); + st.close(); + con.close(); + int iter = 0; + while ((iter++) < 10) + { + final Connection connection = pool.getConnection(); + final CallableStatement s = connection.prepareCall("{CALL SLEEP()}"); + + List<Thread> threadList = new ArrayList<Thread>(); + + for (int l = 0; l < 3; l++) + { + final int i = l; + + Thread thread = new Thread() + { + @Override + public void run() + { + try + { + if (i == 0) + { + Thread.sleep(1000); + s.cancel(); + } + else if (i == 1) + { + //or use some other statement which will block for a longer time + long start = System.currentTimeMillis(); + System.out.println("["+getName()+"] Calling SP SLEEP"); + s.execute(); + System.out.println("["+getName()+"] Executed SP SLEEP ["+(System.currentTimeMillis()-start)+"]"); + } + else + { + Thread.sleep(1000); + connection.close(); + } + } + catch (InterruptedException e) + { + + } + catch (SQLException e) + { + e.printStackTrace(); + } + + }; + + }; + threadList.add(thread); + thread.start(); + } + for (Thread t : threadList) + { + try + { + t.join(); + } + catch (InterruptedException e) + { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + } + + + } +} Propchange: tomcat/trunk/modules/jdbc-pool/src/test/java/org/apache/tomcat/jdbc/bugs/Bug51582.java ------------------------------------------------------------------------------ svn:eol-style = native Modified: tomcat/trunk/modules/jdbc-pool/src/test/java/org/apache/tomcat/jdbc/pool/interceptor/InduceSlowQuery.java URL: http://svn.apache.org/viewvc/tomcat/trunk/modules/jdbc-pool/src/test/java/org/apache/tomcat/jdbc/pool/interceptor/InduceSlowQuery.java?rev=1244927&r1=1244926&r2=1244927&view=diff ============================================================================== --- tomcat/trunk/modules/jdbc-pool/src/test/java/org/apache/tomcat/jdbc/pool/interceptor/InduceSlowQuery.java (original) +++ tomcat/trunk/modules/jdbc-pool/src/test/java/org/apache/tomcat/jdbc/pool/interceptor/InduceSlowQuery.java Thu Feb 16 10:58:21 2012 @@ -1,76 +1,76 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.tomcat.jdbc.pool.interceptor; - -import java.lang.reflect.Method; -import java.security.SecureRandom; - -/** - * @author fhanik - * - */ -public class InduceSlowQuery extends AbstractQueryReport { - public static SecureRandom random = new SecureRandom(); - - public InduceSlowQuery() { - // TODO Auto-generated constructor stub - } - - public void doWait() { - try { - int b = random.nextInt(10); - if (b == 0) { - Thread.sleep(random.nextInt(2000)); - } - } catch (InterruptedException x) { - - } - - } - - @Override - public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { - // TODO Auto-generated method stub - Object result = super.invoke(proxy, method, args); - return result; - } - - @Override - protected void prepareCall(String query, long time) { - } - - @Override - protected void prepareStatement(String sql, long time) { - } - - @Override - public void closeInvoked() { - } - - @Override - protected String reportQuery(String query, Object[] args, String name, long start, long delta) { - doWait(); - return super.reportQuery(query, args, name, start, delta); - } - - @Override - protected String reportSlowQuery(String query, Object[] args, String name, long start, long delta) { - doWait(); - return super.reportSlowQuery(query, args, name, start, delta); - } -} +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.tomcat.jdbc.pool.interceptor; + +import java.lang.reflect.Method; +import java.security.SecureRandom; + +/** + * @author fhanik + * + */ +public class InduceSlowQuery extends AbstractQueryReport { + public static SecureRandom random = new SecureRandom(); + + public InduceSlowQuery() { + // TODO Auto-generated constructor stub + } + + public void doWait() { + try { + int b = random.nextInt(10); + if (b == 0) { + Thread.sleep(random.nextInt(2000)); + } + } catch (InterruptedException x) { + + } + + } + + @Override + public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { + // TODO Auto-generated method stub + Object result = super.invoke(proxy, method, args); + return result; + } + + @Override + protected void prepareCall(String query, long time) { + } + + @Override + protected void prepareStatement(String sql, long time) { + } + + @Override + public void closeInvoked() { + } + + @Override + protected String reportQuery(String query, Object[] args, String name, long start, long delta) { + doWait(); + return super.reportQuery(query, args, name, start, delta); + } + + @Override + protected String reportSlowQuery(String query, Object[] args, String name, long start, long delta) { + doWait(); + return super.reportSlowQuery(query, args, name, start, delta); + } +} Propchange: tomcat/trunk/modules/jdbc-pool/src/test/java/org/apache/tomcat/jdbc/pool/interceptor/InduceSlowQuery.java ------------------------------------------------------------------------------ svn:eol-style = native Modified: tomcat/trunk/test/org/apache/catalina/websocket/TestWebSocket.java URL: http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/catalina/websocket/TestWebSocket.java?rev=1244927&r1=1244926&r2=1244927&view=diff ============================================================================== --- tomcat/trunk/test/org/apache/catalina/websocket/TestWebSocket.java (original) +++ tomcat/trunk/test/org/apache/catalina/websocket/TestWebSocket.java Thu Feb 16 10:58:21 2012 @@ -1,83 +1,83 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.catalina.websocket; - -import java.io.InputStream; -import java.io.Reader; -import java.nio.ByteBuffer; -import java.nio.CharBuffer; - -import org.junit.Test; - -import org.apache.catalina.startup.TomcatBaseTest; - -public class TestWebSocket extends TomcatBaseTest { - - @Test - public void testSimple() { - // TODO: Write a test - } - - private static final class StreamingWebSocketServlet - extends WebSocketServlet { - - private static final long serialVersionUID = 1L; - - @Override - protected StreamInbound createWebSocketInbound() { - return new SimpleStreamInbound(); - } - } - - private static final class SimpleStreamInbound extends StreamInbound { - - @Override - protected void onBinaryData(InputStream is) { - // TODO Auto-generated method stub - } - - @Override - protected void onTextData(Reader r) { - // TODO Auto-generated method stub - } - } - - - private static final class MessageWebSocketServlet - extends WebSocketServlet { - - private static final long serialVersionUID = 1L; - - @Override - protected StreamInbound createWebSocketInbound() { - return new SimpleMessageInbound(); - } - } - - private static final class SimpleMessageInbound extends MessageInbound { - - @Override - protected void onBinaryMessage(ByteBuffer message) { - // TODO Auto-generated method stub - } - - @Override - protected void onTextMessage(CharBuffer message) { - // TODO Auto-generated method stub - } - } -} +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.catalina.websocket; + +import java.io.InputStream; +import java.io.Reader; +import java.nio.ByteBuffer; +import java.nio.CharBuffer; + +import org.junit.Test; + +import org.apache.catalina.startup.TomcatBaseTest; + +public class TestWebSocket extends TomcatBaseTest { + + @Test + public void testSimple() { + // TODO: Write a test + } + + private static final class StreamingWebSocketServlet + extends WebSocketServlet { + + private static final long serialVersionUID = 1L; + + @Override + protected StreamInbound createWebSocketInbound() { + return new SimpleStreamInbound(); + } + } + + private static final class SimpleStreamInbound extends StreamInbound { + + @Override + protected void onBinaryData(InputStream is) { + // TODO Auto-generated method stub + } + + @Override + protected void onTextData(Reader r) { + // TODO Auto-generated method stub + } + } + + + private static final class MessageWebSocketServlet + extends WebSocketServlet { + + private static final long serialVersionUID = 1L; + + @Override + protected StreamInbound createWebSocketInbound() { + return new SimpleMessageInbound(); + } + } + + private static final class SimpleMessageInbound extends MessageInbound { + + @Override + protected void onBinaryMessage(ByteBuffer message) { + // TODO Auto-generated method stub + } + + @Override + protected void onTextMessage(CharBuffer message) { + // TODO Auto-generated method stub + } + } +} Propchange: tomcat/trunk/test/org/apache/catalina/websocket/TestWebSocket.java ------------------------------------------------------------------------------ svn:eol-style = native Modified: tomcat/trunk/webapps/examples/WEB-INF/classes/websocket/EchoMessage.java URL: http://svn.apache.org/viewvc/tomcat/trunk/webapps/examples/WEB-INF/classes/websocket/EchoMessage.java?rev=1244927&r1=1244926&r2=1244927&view=diff ============================================================================== --- tomcat/trunk/webapps/examples/WEB-INF/classes/websocket/EchoMessage.java (original) +++ tomcat/trunk/webapps/examples/WEB-INF/classes/websocket/EchoMessage.java Thu Feb 16 10:58:21 2012 @@ -1,50 +1,50 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package websocket; - -import java.io.IOException; -import java.nio.ByteBuffer; -import java.nio.CharBuffer; - -import org.apache.catalina.websocket.MessageInbound; -import org.apache.catalina.websocket.StreamInbound; -import org.apache.catalina.websocket.WebSocketServlet; - - -public class EchoMessage extends WebSocketServlet { - - private static final long serialVersionUID = 1L; - - @Override - protected StreamInbound createWebSocketInbound() { - return new EchoMessageInbound(); - } - - private static final class EchoMessageInbound extends MessageInbound { - - @Override - protected void onBinaryMessage(ByteBuffer message) throws IOException { - System.out.write(message.array(), 0, message.limit()); - System.out.print('\n'); - } - - @Override - protected void onTextMessage(CharBuffer message) throws IOException { - System.out.println(message); - } - } -} +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package websocket; + +import java.io.IOException; +import java.nio.ByteBuffer; +import java.nio.CharBuffer; + +import org.apache.catalina.websocket.MessageInbound; +import org.apache.catalina.websocket.StreamInbound; +import org.apache.catalina.websocket.WebSocketServlet; + + +public class EchoMessage extends WebSocketServlet { + + private static final long serialVersionUID = 1L; + + @Override + protected StreamInbound createWebSocketInbound() { + return new EchoMessageInbound(); + } + + private static final class EchoMessageInbound extends MessageInbound { + + @Override + protected void onBinaryMessage(ByteBuffer message) throws IOException { + System.out.write(message.array(), 0, message.limit()); + System.out.print('\n'); + } + + @Override + protected void onTextMessage(CharBuffer message) throws IOException { + System.out.println(message); + } + } +} Propchange: tomcat/trunk/webapps/examples/WEB-INF/classes/websocket/EchoMessage.java ------------------------------------------------------------------------------ svn:eol-style = native Modified: tomcat/trunk/webapps/examples/WEB-INF/classes/websocket/EchoStream.java URL: http://svn.apache.org/viewvc/tomcat/trunk/webapps/examples/WEB-INF/classes/websocket/EchoStream.java?rev=1244927&r1=1244926&r2=1244927&view=diff ============================================================================== --- tomcat/trunk/webapps/examples/WEB-INF/classes/websocket/EchoStream.java (original) +++ tomcat/trunk/webapps/examples/WEB-INF/classes/websocket/EchoStream.java Thu Feb 16 10:58:21 2012 @@ -1,67 +1,67 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package websocket; - -import java.io.IOException; -import java.io.InputStream; -import java.io.Reader; - -import org.apache.catalina.websocket.StreamInbound; -import org.apache.catalina.websocket.WebSocketServlet; -import org.apache.catalina.websocket.WsOutbound; - - -public class EchoStream extends WebSocketServlet { - - private static final long serialVersionUID = 1L; - - @Override - protected StreamInbound createWebSocketInbound() { - return new EchoStreamInbound(); - } - - private static final class EchoStreamInbound extends StreamInbound { - - @Override - protected void onBinaryData(InputStream is) throws IOException { - // Simply echo the data to back to the client. - WsOutbound outbound = getStreamOutbound(); - - int i = is.read(); - while (i != -1) { - outbound.writeBinaryData(i); - i = is.read(); - } - - outbound.flush(); - } - - @Override - protected void onTextData(Reader r) throws IOException { - // Simply echo the data to back to the client. - WsOutbound outbound = getStreamOutbound(); - - int c = r.read(); - while (c != -1) { - outbound.writeTextData((char) c); - c = r.read(); - } - - outbound.flush(); - } - } -} +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package websocket; + +import java.io.IOException; +import java.io.InputStream; +import java.io.Reader; + +import org.apache.catalina.websocket.StreamInbound; +import org.apache.catalina.websocket.WebSocketServlet; +import org.apache.catalina.websocket.WsOutbound; + + +public class EchoStream extends WebSocketServlet { + + private static final long serialVersionUID = 1L; + + @Override + protected StreamInbound createWebSocketInbound() { + return new EchoStreamInbound(); + } + + private static final class EchoStreamInbound extends StreamInbound { + + @Override + protected void onBinaryData(InputStream is) throws IOException { + // Simply echo the data to back to the client. + WsOutbound outbound = getStreamOutbound(); + + int i = is.read(); + while (i != -1) { + outbound.writeBinaryData(i); + i = is.read(); + } + + outbound.flush(); + } + + @Override + protected void onTextData(Reader r) throws IOException { + // Simply echo the data to back to the client. + WsOutbound outbound = getStreamOutbound(); + + int c = r.read(); + while (c != -1) { + outbound.writeTextData((char) c); + c = r.read(); + } + + outbound.flush(); + } + } +} Propchange: tomcat/trunk/webapps/examples/WEB-INF/classes/websocket/EchoStream.java ------------------------------------------------------------------------------ svn:eol-style = native --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org