/*
 * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
 * ORACLE PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 * 
 * $Id: EchoServerEndpoint.java 74503 2015-05-21 15:13:10Z jsupol $
 */

package com.sun.ts.tests.websocket.negdep;

import java.io.IOException;

import javax.websocket.OnError;
import javax.websocket.OnMessage;
import javax.websocket.Session;
import javax.websocket.server.ServerEndpoint;

import com.sun.ts.tests.websocket.common.util.IOUtil;

@ServerEndpoint("/echo")
public class EchoServerEndpoint {

	@OnMessage
	public String echo(String echo) {
		return echo;
	}
	
	@OnMessage
	public String echo(byte[] bytes){
		return new String(bytes);
	}

	@OnError
	public void onError(Session session, Throwable thr) throws IOException {
		thr.printStackTrace(); // Write to error log, too
		String message = IOUtil.printStackTrace(thr);
		session.getBasicRemote().sendText(message);
	}

}
