/*
 * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
 * ORACLE PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 * 
 * $Id: WSCServer.java 72795 2013-09-04 15:47:07Z supol $
 */

package com.sun.ts.tests.websocket.ee.javax.websocket.containerprovider.vi;

import java.io.IOException;

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

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

@ServerEndpoint("/srv")
public class WSCServer {
	@OnMessage
	public boolean onMessage(String data) {
		WebSocketContainer container = ContainerProvider
				.getWebSocketContainer();
		return container != null;
	}

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