private StompFrame constructMessage(StringBuffer incomingMessage) {
		String fullMessage= incomingMessage.toString();
		System.out.println("Server received: ");
		System.out.println(fullMessage.toString());
		int indexOfNewline= fullMessage.indexOf("" + StompFrame.endlineChar);
		if (indexOfNewline == 0){
			fullMessage= fullMessage.substring(StompFrame.lenghtOfEndlineChar);
			indexOfNewline= fullMessage.indexOf("" + StompFrame.endlineChar);
		}
		String header= fullMessage.substring(0, indexOfNewline);
		if (header.equals("CONNECT")){
			return ConnectFrame.factory(fullMessage.substring(indexOfNewline + StompFrame.lenghtOfEndlineChar));
		}
		if (header.equals("SEND")){
			return SendFrame.factory(fullMessage.substring(indexOfNewline + StompFrame.lenghtOfEndlineChar));
		}
		if (header.equals("SUBSCRIBE")){
			return SubscribeFrame.factory(fullMessage.substring(indexOfNewline + StompFrame.lenghtOfEndlineChar));
		}
		if (header.equals("UNSUBSCRIBE")){
			return UnsubscribeFrame.factory(fullMessage.substring(indexOfNewline + StompFrame.lenghtOfEndlineChar));
		}
		if (header.equals("DISCONNECT")){
			return DisconnectFrame.factory(fullMessage.substring(indexOfNewline + StompFrame.lenghtOfEndlineChar));
		}
		return ErrorFrame.factory(fullMessage.toString(), "malformed STOMP message");
	}